1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-09-10 06:46:06 +00:00

Changed App.js to be a proper object class

This commit is contained in:
Jeremy Ruston
2012-01-03 11:57:30 +00:00
parent 883956e855
commit 75e6bdef2b
2 changed files with 66 additions and 61 deletions

125
js/App.js
View File

@@ -18,66 +18,71 @@ var WikiStore = require("./WikiStore.js").WikiStore,
Navigators = require("./Navigators.js").Navigators, Navigators = require("./Navigators.js").Navigators,
StoryNavigator = require("./StoryNavigator.js").StoryNavigator; StoryNavigator = require("./StoryNavigator.js").StoryNavigator;
var store = new WikiStore(), var App = function() {
t; var t;
// Check if we're running on the server or the client
// Register the wikitext processor this.isBrowser = typeof window !== "undefined";
store.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({ // Create the main store
store: store this.store = new WikiStore();
})); // Register the wikitext processor
this.store.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({
// Register the standard tiddler serializers and deserializers store: this.store
tiddlerInput.register(store); }));
tiddlerOutput.register(store); // Register the standard tiddler serializers and deserializers
tiddlerInput.register(this.store);
// Add the shadow tiddlers that are built into TiddlyWiki tiddlerOutput.register(this.store);
var shadowShadowStore = new WikiStore({ // Add the shadow tiddlers that are built into TiddlyWiki
shadowStore: null var shadowShadowStore = new WikiStore({
}), shadowStore: null
shadowShadows = [ }),
{title: "StyleSheet", text: ""}, shadowShadows = [
{title: "MarkupPreHead", text: ""}, {title: "StyleSheet", text: ""},
{title: "MarkupPostHead", text: ""}, {title: "MarkupPreHead", text: ""},
{title: "MarkupPreBody", text: ""}, {title: "MarkupPostHead", text: ""},
{title: "MarkupPostBody", text: ""}, {title: "MarkupPreBody", text: ""},
{title: "WindowTitle", text: "<<tiddler SiteTitle>> - <<tiddler SiteSubtitle>>"}, {title: "MarkupPostBody", text: ""},
{title: "DefaultTiddlers", text: "[[GettingStarted]]"}, {title: "WindowTitle", text: "<<tiddler SiteTitle>> - <<tiddler SiteSubtitle>>"},
{title: "MainMenu", text: "[[GettingStarted]]"}, {title: "DefaultTiddlers", text: "[[GettingStarted]]"},
{title: "SiteTitle", text: "My TiddlyWiki"}, {title: "MainMenu", text: "[[GettingStarted]]"},
{title: "SiteSubtitle", text: "a reusable non-linear personal web notebook"}, {title: "SiteTitle", text: "My TiddlyWiki"},
{title: "SiteUrl", text: ""} {title: "SiteSubtitle", text: "a reusable non-linear personal web notebook"},
]; {title: "SiteUrl", text: ""}
store.shadows.shadows = shadowShadowStore; ];
for(t=0; t<shadowShadows.length; t++) { this.store.shadows.shadows = shadowShadowStore;
shadowShadowStore.addTiddler(new Tiddler(shadowShadows[t])); for(t=0; t<shadowShadows.length; t++) {
} shadowShadowStore.addTiddler(new Tiddler(shadowShadows[t]));
}
// Load the tiddlers built into the TiddlyWiki document // If in the browser, load the tiddlers built into the TiddlyWiki document
var storeArea = document.getElementById("storeArea"), if(this.isBrowser) {
tiddlers = store.deserializeTiddlers("(DOM)",storeArea); var storeArea = document.getElementById("storeArea"),
for(t=0; t<tiddlers.length; t++) { tiddlers = this.store.deserializeTiddlers("(DOM)",storeArea);
store.addTiddler(new Tiddler(tiddlers[t])); for(t=0; t<tiddlers.length; t++) {
} this.store.addTiddler(new Tiddler(tiddlers[t]));
}
// Set up the sandbox for evaluated macro parameters }
store.sandbox = new Sandbox(store.getTiddlerText("javascript.pegjs")); // Set up the sandbox for JavaScript parsing
if(this.isBrowser) {
// Install the standard navigators this.store.sandbox = new Sandbox(this.store.getTiddlerText("javascript.pegjs"));
var navigators = new Navigators({ } else {
document: document, this.store.sandbox = new Sandbox(require("fs").readFileSync("parsers/javascript.pegjs","utf8"));
store: store }
}); // Hack to install standard macros
this.store.installMacros();
navigators.registerNavigator("StoryNavigator",new StoryNavigator(navigators)); // Set up navigation if we're in the browser
// Use the story navigator for all links if(this.isBrowser) {
navigators.install("a","StoryNavigator"); // Install the standard navigators
var navigators = new Navigators({
store.installMacros(); document: document,
store: this.store
//console.log(JSON.stringify(store.sandbox.parse("store.classesForLink(\"HelloThere\");"))); });
navigators.registerNavigator("StoryNavigator",new StoryNavigator(navigators));
// Navigate to HelloThere // Use the story navigator for all links
navigators.navigateTo("HelloThere","StoryNavigator"); navigators.install("a","StoryNavigator");
// Navigate to HelloThere
navigators.navigateTo("HelloThere","StoryNavigator");
}
};
exports.App = App;
})(); })();

View File

@@ -62,7 +62,7 @@ function executeModule(modName,modRoot) {
$(function() { $(function() {
// Execute the main module // Execute the main module
executeModule("js/App.js"); var app = new (executeModule("js/App.js").App)();
}) })
})(); })();