2011-12-13 12:30:09 +00:00
|
|
|
/*\
|
2012-01-03 11:38:15 +00:00
|
|
|
title: js/App.js
|
2011-12-13 12:30:09 +00:00
|
|
|
|
|
|
|
This is the main() function in the browser
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
2011-12-14 14:11:11 +00:00
|
|
|
/*jslint node: true, browser: true */
|
2011-12-13 12:30:09 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var WikiStore = require("./WikiStore.js").WikiStore,
|
|
|
|
Tiddler = require("./Tiddler.js").Tiddler,
|
|
|
|
tiddlerInput = require("./TiddlerInput.js"),
|
|
|
|
tiddlerOutput = require("./TiddlerOutput.js"),
|
2012-01-05 11:08:05 +00:00
|
|
|
WikiTextParser = require("./WikiTextParser.js").WikiTextParser,
|
2012-01-04 18:31:19 +00:00
|
|
|
JavaScriptParser = require("./JavaScriptParser.js").JavaScriptParser,
|
2012-01-12 19:17:32 +00:00
|
|
|
SVGParser = require("./SVGParser.js").SVGParser,
|
2012-01-12 21:48:24 +00:00
|
|
|
BitmapParser = require("./BitmapParser.js").BitmapParser,
|
2011-12-13 16:20:56 +00:00
|
|
|
Navigators = require("./Navigators.js").Navigators,
|
|
|
|
StoryNavigator = require("./StoryNavigator.js").StoryNavigator;
|
2011-12-13 12:30:09 +00:00
|
|
|
|
2012-01-03 11:57:30 +00:00
|
|
|
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();
|
2012-01-12 19:17:32 +00:00
|
|
|
// Register the wikitext parser and the SVG parser
|
2012-01-05 11:08:05 +00:00
|
|
|
this.store.registerParser("text/x-tiddlywiki",new WikiTextParser({
|
2012-01-03 11:57:30 +00:00
|
|
|
store: this.store
|
|
|
|
}));
|
2012-01-12 19:17:32 +00:00
|
|
|
this.store.registerParser("image/svg+xml",new SVGParser());
|
2012-01-12 21:48:24 +00:00
|
|
|
var bitmapParser = new BitmapParser();
|
|
|
|
this.store.registerParser("image/jpg",bitmapParser);
|
|
|
|
this.store.registerParser("image/jpeg",bitmapParser);
|
|
|
|
this.store.registerParser("image/png",bitmapParser);
|
2012-01-13 15:37:58 +00:00
|
|
|
this.store.registerParser("image/gif",bitmapParser);
|
2012-01-03 11:57:30 +00:00
|
|
|
// Register the standard tiddler serializers and deserializers
|
|
|
|
tiddlerInput.register(this.store);
|
|
|
|
tiddlerOutput.register(this.store);
|
|
|
|
// Add the shadow tiddlers that are built into TiddlyWiki
|
|
|
|
var shadowShadowStore = new WikiStore({
|
|
|
|
shadowStore: null
|
|
|
|
}),
|
|
|
|
shadowShadows = [
|
|
|
|
{title: "StyleSheet", text: ""},
|
|
|
|
{title: "MarkupPreHead", text: ""},
|
|
|
|
{title: "MarkupPostHead", text: ""},
|
|
|
|
{title: "MarkupPreBody", text: ""},
|
|
|
|
{title: "MarkupPostBody", text: ""},
|
2012-01-03 12:23:02 +00:00
|
|
|
{title: "TabTimeline", text: "<<timeline>>"},
|
|
|
|
{title: "TabAll", text: "<<list all>>"},
|
|
|
|
{title: "TabTags", text: "<<allTags excludeLists>>"},
|
|
|
|
{title: "TabMoreMissing", text: "<<list missing>>"},
|
|
|
|
{title: "TabMoreOrphans", text: "<<list orphans>>"},
|
|
|
|
{title: "TabMoreShadowed", text: "<<list shadowed>>"},
|
|
|
|
{title: "AdvancedOptions", text: "<<options>>"},
|
|
|
|
{title: "PluginManager", text: "<<plugins>>"},
|
|
|
|
{title: "SystemSettings", text: ""},
|
|
|
|
{title: "ToolbarCommands", text: "|~ViewToolbar|closeTiddler closeOthers +editTiddler > fields syncing permalink references jump|\n|~EditToolbar|+saveTiddler -cancelTiddler deleteTiddler|"},
|
2012-01-03 11:57:30 +00:00
|
|
|
{title: "WindowTitle", text: "<<tiddler SiteTitle>> - <<tiddler SiteSubtitle>>"},
|
|
|
|
{title: "DefaultTiddlers", text: "[[GettingStarted]]"},
|
|
|
|
{title: "MainMenu", text: "[[GettingStarted]]"},
|
|
|
|
{title: "SiteTitle", text: "My TiddlyWiki"},
|
|
|
|
{title: "SiteSubtitle", text: "a reusable non-linear personal web notebook"},
|
2012-01-03 12:23:02 +00:00
|
|
|
{title: "SiteUrl", text: ""},
|
|
|
|
{title: "SideBarOptions", text: '<<search>><<closeAll>><<permaview>><<newTiddler>><<newJournal "DD MMM YYYY" "journal">><<saveChanges>><<slider chkSliderOptionsPanel OptionsPanel "options \u00bb" "Change TiddlyWiki advanced options">>'},
|
|
|
|
{title: "SideBarTabs", text: '<<tabs txtMainTab "Timeline" "Timeline" TabTimeline "All" "All tiddlers" TabAll "Tags" "All tags" TabTags "More" "More lists" TabMore>>'},
|
|
|
|
{title: "TabMore", text: '<<tabs txtMoreTab "Missing" "Missing tiddlers" TabMoreMissing "Orphans" "Orphaned tiddlers" TabMoreOrphans "Shadowed" "Shadowed tiddlers" TabMoreShadowed>>'}
|
2012-01-03 11:57:30 +00:00
|
|
|
];
|
|
|
|
this.store.shadows.shadows = shadowShadowStore;
|
|
|
|
for(t=0; t<shadowShadows.length; t++) {
|
|
|
|
shadowShadowStore.addTiddler(new Tiddler(shadowShadows[t]));
|
|
|
|
}
|
|
|
|
// If in the browser, load the tiddlers built into the TiddlyWiki document
|
|
|
|
if(this.isBrowser) {
|
|
|
|
var storeArea = document.getElementById("storeArea"),
|
|
|
|
tiddlers = this.store.deserializeTiddlers("(DOM)",storeArea);
|
|
|
|
for(t=0; t<tiddlers.length; t++) {
|
|
|
|
this.store.addTiddler(new Tiddler(tiddlers[t]));
|
|
|
|
}
|
|
|
|
}
|
2012-01-04 18:31:19 +00:00
|
|
|
// Set up the JavaScript parser
|
2012-01-03 11:57:30 +00:00
|
|
|
if(this.isBrowser) {
|
2012-01-04 18:31:19 +00:00
|
|
|
this.store.jsParser = new JavaScriptParser(this.store.getTiddlerText("javascript.pegjs"));
|
2012-01-03 11:57:30 +00:00
|
|
|
} else {
|
2012-01-04 18:31:19 +00:00
|
|
|
this.store.jsParser = new JavaScriptParser(require("fs").readFileSync("parsers/javascript.pegjs","utf8"));
|
2012-01-03 11:57:30 +00:00
|
|
|
}
|
2012-01-07 17:33:42 +00:00
|
|
|
// Bit of a hack to set up the macros
|
|
|
|
this.store.installMacro(require("./macros/echo.js").macro);
|
2012-01-15 14:37:49 +00:00
|
|
|
this.store.installMacro(require("./macros/image.js").macro);
|
2012-01-07 17:33:42 +00:00
|
|
|
this.store.installMacro(require("./macros/info.js").macro);
|
2012-01-15 13:29:16 +00:00
|
|
|
this.store.installMacro(require("./macros/link.js").macro);
|
2012-01-07 17:33:42 +00:00
|
|
|
this.store.installMacro(require("./macros/list.js").macro);
|
2012-01-13 16:50:11 +00:00
|
|
|
this.store.installMacro(require("./macros/story.js").macro);
|
2012-01-07 17:33:42 +00:00
|
|
|
this.store.installMacro(require("./macros/tiddler.js").macro);
|
|
|
|
this.store.installMacro(require("./macros/version.js").macro);
|
|
|
|
this.store.installMacro(require("./macros/view.js").macro);
|
2012-01-03 11:57:30 +00:00
|
|
|
// Set up navigation if we're in the browser
|
|
|
|
if(this.isBrowser) {
|
|
|
|
// Install the standard navigators
|
|
|
|
var navigators = new Navigators({
|
|
|
|
document: document,
|
|
|
|
store: this.store
|
|
|
|
});
|
|
|
|
navigators.registerNavigator("StoryNavigator",new StoryNavigator(navigators));
|
|
|
|
// Use the story navigator for all links
|
|
|
|
navigators.install("a","StoryNavigator");
|
2012-01-13 16:50:11 +00:00
|
|
|
// Open the PageTemplate
|
2012-01-13 18:51:39 +00:00
|
|
|
var div = document.createElement("div");
|
|
|
|
div.innerHTML = this.store.renderTiddler("text/html","PageTemplate");
|
|
|
|
document.body.appendChild(div);
|
2012-01-14 15:49:12 +00:00
|
|
|
var me = this;
|
|
|
|
window.setInterval(function() {
|
|
|
|
me.store.addTiddler(new Tiddler({
|
|
|
|
title: "TiddlyWiki5",
|
|
|
|
text: "This is a newly created tiddler!"
|
|
|
|
}));
|
|
|
|
},3000);
|
|
|
|
this.store.addEventListener("",function() {
|
|
|
|
me.store.refreshDomNode(div,me.store.getTiddler("PageTemplate"));
|
|
|
|
});
|
2012-01-03 11:57:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.App = App;
|
2012-01-03 11:08:00 +00:00
|
|
|
|
2011-12-13 16:20:56 +00:00
|
|
|
})();
|