mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-11-04 09:33:00 +00:00 
			
		
		
		
	Changed App.js to be a proper object class
This commit is contained in:
		
							
								
								
									
										55
									
								
								js/App.js
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								js/App.js
									
									
									
									
									
								
							@@ -18,18 +18,19 @@ var WikiStore = require("./WikiStore.js").WikiStore,
 | 
			
		||||
	Navigators = require("./Navigators.js").Navigators,
 | 
			
		||||
	StoryNavigator = require("./StoryNavigator.js").StoryNavigator;
 | 
			
		||||
 | 
			
		||||
var store = new WikiStore(),
 | 
			
		||||
	t;
 | 
			
		||||
 | 
			
		||||
var App = function() {
 | 
			
		||||
	var t;
 | 
			
		||||
	// Check if we're running on the server or the client
 | 
			
		||||
	this.isBrowser = typeof window !== "undefined";
 | 
			
		||||
	// Create the main store
 | 
			
		||||
	this.store = new WikiStore();	
 | 
			
		||||
	// Register the wikitext processor
 | 
			
		||||
store.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({
 | 
			
		||||
	store: store
 | 
			
		||||
	this.store.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({
 | 
			
		||||
		store: this.store
 | 
			
		||||
	}));
 | 
			
		||||
 | 
			
		||||
	// Register the standard tiddler serializers and deserializers
 | 
			
		||||
tiddlerInput.register(store);
 | 
			
		||||
tiddlerOutput.register(store);
 | 
			
		||||
 | 
			
		||||
	tiddlerInput.register(this.store);
 | 
			
		||||
	tiddlerOutput.register(this.store);
 | 
			
		||||
	// Add the shadow tiddlers that are built into TiddlyWiki
 | 
			
		||||
	var shadowShadowStore = new WikiStore({
 | 
			
		||||
			shadowStore: null
 | 
			
		||||
@@ -47,37 +48,41 @@ var shadowShadowStore = new WikiStore({
 | 
			
		||||
			{title: "SiteSubtitle", text: "a reusable non-linear personal web notebook"},
 | 
			
		||||
			{title: "SiteUrl", text: ""}
 | 
			
		||||
		];
 | 
			
		||||
store.shadows.shadows = shadowShadowStore;
 | 
			
		||||
	this.store.shadows.shadows = shadowShadowStore;
 | 
			
		||||
	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
 | 
			
		||||
	if(this.isBrowser) {
 | 
			
		||||
		var storeArea = document.getElementById("storeArea"),
 | 
			
		||||
	tiddlers = store.deserializeTiddlers("(DOM)",storeArea);
 | 
			
		||||
			tiddlers = this.store.deserializeTiddlers("(DOM)",storeArea);
 | 
			
		||||
		for(t=0; t<tiddlers.length; t++) {
 | 
			
		||||
	store.addTiddler(new Tiddler(tiddlers[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) {
 | 
			
		||||
		this.store.sandbox = new Sandbox(this.store.getTiddlerText("javascript.pegjs"));
 | 
			
		||||
	} else {
 | 
			
		||||
		this.store.sandbox = new Sandbox(require("fs").readFileSync("parsers/javascript.pegjs","utf8"));
 | 
			
		||||
	}
 | 
			
		||||
	// Hack to install standard macros
 | 
			
		||||
	this.store.installMacros();
 | 
			
		||||
	// Set up navigation if we're in the browser
 | 
			
		||||
	if(this.isBrowser) {
 | 
			
		||||
		// Install the standard navigators
 | 
			
		||||
		var navigators = new Navigators({
 | 
			
		||||
				document: document,
 | 
			
		||||
		store: store
 | 
			
		||||
				store: this.store
 | 
			
		||||
			});
 | 
			
		||||
 | 
			
		||||
		navigators.registerNavigator("StoryNavigator",new StoryNavigator(navigators));
 | 
			
		||||
		// Use the story navigator for all links
 | 
			
		||||
		navigators.install("a","StoryNavigator");
 | 
			
		||||
 | 
			
		||||
store.installMacros();
 | 
			
		||||
 | 
			
		||||
//console.log(JSON.stringify(store.sandbox.parse("store.classesForLink(\"HelloThere\");")));
 | 
			
		||||
 | 
			
		||||
		// Navigate to HelloThere
 | 
			
		||||
		navigators.navigateTo("HelloThere","StoryNavigator");
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.App = App;
 | 
			
		||||
 | 
			
		||||
})();
 | 
			
		||||
 
 | 
			
		||||
@@ -62,7 +62,7 @@ function executeModule(modName,modRoot) {
 | 
			
		||||
 | 
			
		||||
$(function() {
 | 
			
		||||
	// Execute the main module
 | 
			
		||||
	executeModule("js/App.js");
 | 
			
		||||
	var app = new (executeModule("js/App.js").App)();
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
})();
 | 
			
		||||
		Reference in New Issue
	
	Block a user