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,
|
2012-04-05 11:21:49 +00:00
|
|
|
HttpSync = require("./HttpSync.js").HttpSync,
|
2011-12-13 12:30:09 +00:00
|
|
|
Tiddler = require("./Tiddler.js").Tiddler,
|
|
|
|
tiddlerInput = require("./TiddlerInput.js"),
|
|
|
|
tiddlerOutput = require("./TiddlerOutput.js"),
|
2012-02-16 20:38:10 +00:00
|
|
|
Renderer = require("./Renderer.js").Renderer,
|
2012-01-05 11:08:05 +00:00
|
|
|
WikiTextParser = require("./WikiTextParser.js").WikiTextParser,
|
2012-03-03 18:07:09 +00:00
|
|
|
PlainTextParser = require("./PlainTextParser.js").PlainTextParser,
|
2012-01-04 18:31:19 +00:00
|
|
|
JavaScriptParser = require("./JavaScriptParser.js").JavaScriptParser,
|
2012-03-02 11:31:39 +00:00
|
|
|
JSONParser = require("./JSONParser.js").JSONParser,
|
2012-02-02 18:00:42 +00:00
|
|
|
ImageParser = require("./ImageParser.js").ImageParser;
|
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-27 16:35:55 +00:00
|
|
|
// Register the parsers
|
|
|
|
this.store.registerParser("text/x-tiddlywiki",new WikiTextParser({store: this.store}));
|
2012-03-03 18:07:09 +00:00
|
|
|
this.store.registerParser("text/plain",new PlainTextParser({store: this.store}));
|
2012-03-03 12:29:13 +00:00
|
|
|
this.store.registerParser(["image/svg+xml",".svg","image/jpg",".jpg","image/jpeg",".jpeg","image/png",".png","image/gif",".gif"],new ImageParser({store: this.store}));
|
|
|
|
this.store.registerParser(["application/javascript",".js"],new JavaScriptParser({store: this.store}));
|
|
|
|
this.store.registerParser(["application/json",".json"],new JSONParser({store: this.store}));
|
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) {
|
2012-03-01 23:24:25 +00:00
|
|
|
// First, the JavaScript system tiddlers
|
2012-03-14 18:57:53 +00:00
|
|
|
var moduleArea = document.getElementById("jsModules");
|
|
|
|
this.store.shadows.addTiddlers(this.store.deserializeTiddlers("(DOM)",moduleArea));
|
2012-03-01 23:24:25 +00:00
|
|
|
// Then, the ordinary tiddlers baked into the storeArea
|
|
|
|
var storeArea = document.getElementById("storeArea");
|
2012-03-14 18:57:53 +00:00
|
|
|
this.store.addTiddlers(this.store.deserializeTiddlers("(DOM)",storeArea));
|
|
|
|
// Finally, the shadow tiddlers
|
|
|
|
var shadowArea = document.getElementById("shadowArea");
|
|
|
|
this.store.shadows.addTiddlers(this.store.deserializeTiddlers("(DOM)",shadowArea));
|
2012-01-03 11:57:30 +00:00
|
|
|
}
|
2012-04-05 11:21:49 +00:00
|
|
|
// Reset pending events on the store so that we don't get events for the initial load
|
|
|
|
this.store.clearEvents();
|
2012-01-07 17:33:42 +00:00
|
|
|
// Bit of a hack to set up the macros
|
2012-03-07 17:44:12 +00:00
|
|
|
this.store.installMacro(require("./macros/chooser.js").macro);
|
2012-03-29 16:02:05 +00:00
|
|
|
this.store.installMacro(require("./macros/command.js").macro);
|
2012-01-07 17:33:42 +00:00
|
|
|
this.store.installMacro(require("./macros/echo.js").macro);
|
2012-03-29 14:32:36 +00:00
|
|
|
this.store.installMacro(require("./macros/edit.js").macro);
|
2012-01-15 14:37:49 +00:00
|
|
|
this.store.installMacro(require("./macros/image.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-23 18:31:17 +00:00
|
|
|
this.store.installMacro(require("./macros/slider.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);
|
2012-02-01 12:36:40 +00:00
|
|
|
this.store.installMacro(require("./macros/video.js").macro);
|
2012-01-07 17:33:42 +00:00
|
|
|
this.store.installMacro(require("./macros/view.js").macro);
|
2012-03-16 15:11:37 +00:00
|
|
|
this.store.installMacro(require("./macros/zoomer.js").macro);
|
2012-04-03 16:07:38 +00:00
|
|
|
// Install the default link massager
|
|
|
|
this.store.linkMassager = function(linkInfo) {
|
|
|
|
if(!linkInfo.isExternal) {
|
2012-04-07 10:32:41 +00:00
|
|
|
linkInfo.to = encodeURIComponent(linkInfo.to);
|
2012-04-03 16:07:38 +00:00
|
|
|
}
|
|
|
|
};
|
2012-04-05 11:21:49 +00:00
|
|
|
// Set up for the browser
|
2012-01-03 11:57:30 +00:00
|
|
|
if(this.isBrowser) {
|
2012-04-05 11:21:49 +00:00
|
|
|
// Set up HttpSync
|
|
|
|
this.httpSync = new HttpSync(this.store);
|
2012-01-13 16:50:11 +00:00
|
|
|
// Open the PageTemplate
|
2012-02-20 20:52:54 +00:00
|
|
|
var renderer = this.store.renderMacro("tiddler",{target: "PageTemplate"});
|
2012-02-16 20:38:10 +00:00
|
|
|
renderer.renderInDom(document.body);
|
2012-02-17 12:34:28 +00:00
|
|
|
// Register an event handler to handle refreshing the DOM
|
|
|
|
this.store.addEventListener("",function(changes) {
|
|
|
|
renderer.refreshInDom(changes);
|
|
|
|
});
|
|
|
|
// Set the page title and refresh it when needed
|
2012-02-20 20:52:54 +00:00
|
|
|
var titleRenderer = this.store.renderMacro("tiddler",{target: "WindowTitle"});
|
2012-02-17 12:34:28 +00:00
|
|
|
document.title = titleRenderer.render("text/plain");
|
|
|
|
this.store.addEventListener("",function(changes) {
|
|
|
|
titleRenderer.refresh(changes);
|
|
|
|
document.title = titleRenderer.render("text/plain");
|
|
|
|
});
|
2012-03-13 15:12:23 +00:00
|
|
|
// Listen for navigate events that weren't caught
|
|
|
|
document.addEventListener("tw-navigate",function (event) {
|
|
|
|
renderer.broadcastEvent(event);
|
|
|
|
},false);
|
2012-04-05 11:21:49 +00:00
|
|
|
// Set up a timer to change the value of a tiddler
|
|
|
|
var me = this,
|
|
|
|
s = setInterval || window.setInterval;
|
|
|
|
s(function() {
|
|
|
|
me.store.addTiddler(new Tiddler({
|
|
|
|
title: "ClockTiddler",
|
|
|
|
text: "The time was recently " + (new Date()).toString()
|
|
|
|
}));
|
|
|
|
},3000);
|
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
|
|
|
})();
|