2012-04-30 11:23:03 +00:00
|
|
|
/*\
|
2012-05-03 20:47:16 +00:00
|
|
|
title: $:/core/modules/startup.js
|
2012-04-30 11:23:03 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: startup
|
|
|
|
|
2014-07-20 17:06:33 +00:00
|
|
|
Miscellaneous startup logic for both the client and server.
|
2012-04-30 11:23:03 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
2012-05-04 17:49:04 +00:00
|
|
|
/*global $tw: false */
|
2012-04-30 11:23:03 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-05-03 15:32:18 +00:00
|
|
|
// Export name and synchronous status
|
|
|
|
exports.name = "startup";
|
2014-05-03 16:10:55 +00:00
|
|
|
exports.after = ["load-modules"];
|
2014-05-03 15:32:18 +00:00
|
|
|
exports.synchronous = true;
|
|
|
|
|
2014-04-01 07:33:36 +00:00
|
|
|
// Set to `true` to enable performance instrumentation
|
2015-10-14 09:59:46 +00:00
|
|
|
var PERFORMANCE_INSTRUMENTATION_CONFIG_TITLE = "$:/config/Performance/Instrumentation";
|
2014-04-01 07:33:36 +00:00
|
|
|
|
2014-08-13 19:20:58 +00:00
|
|
|
var widget = require("$:/core/modules/widgets/widget.js");
|
|
|
|
|
2012-04-30 11:23:03 +00:00
|
|
|
exports.startup = function() {
|
2014-05-03 20:23:51 +00:00
|
|
|
var modules,n,m,f;
|
2016-04-22 07:36:29 +00:00
|
|
|
// Minimal browser detection
|
2012-10-25 21:20:27 +00:00
|
|
|
if($tw.browser) {
|
2014-05-03 16:10:55 +00:00
|
|
|
$tw.browser.isIE = (/msie|trident/i.test(navigator.userAgent));
|
2016-04-30 13:36:53 +00:00
|
|
|
$tw.browser.isFirefox = !!document.mozFullScreenEnabled;
|
2012-10-25 21:20:27 +00:00
|
|
|
}
|
2016-04-22 07:36:29 +00:00
|
|
|
// Platform detection
|
|
|
|
$tw.platform = {};
|
|
|
|
if($tw.browser) {
|
|
|
|
$tw.platform.isMac = /Mac/.test(navigator.platform);
|
|
|
|
$tw.platform.isWindows = /win/i.test(navigator.platform);
|
|
|
|
$tw.platform.isLinux = /Linux/i.test(navigator.appVersion);
|
|
|
|
} else {
|
|
|
|
switch(require("os").platform()) {
|
|
|
|
case "darwin":
|
|
|
|
$tw.platform.isMac = true;
|
|
|
|
break;
|
|
|
|
case "win32":
|
|
|
|
$tw.platform.isWindows = true;
|
|
|
|
break;
|
|
|
|
case "freebsd":
|
|
|
|
$tw.platform.isLinux = true;
|
|
|
|
break;
|
|
|
|
case "linux":
|
|
|
|
$tw.platform.isLinux = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Initialise version
|
2012-07-15 16:37:03 +00:00
|
|
|
$tw.version = $tw.utils.extractVersionInfo();
|
2014-04-01 07:33:36 +00:00
|
|
|
// Set up the performance framework
|
2015-10-14 09:59:46 +00:00
|
|
|
$tw.perf = new $tw.Performance($tw.wiki.getTiddlerText(PERFORMANCE_INSTRUMENTATION_CONFIG_TITLE,"no") === "yes");
|
2014-03-20 20:55:59 +00:00
|
|
|
// Kick off the language manager and switcher
|
|
|
|
$tw.language = new $tw.Language();
|
|
|
|
$tw.languageSwitcher = new $tw.PluginSwitcher({
|
2014-02-09 19:18:46 +00:00
|
|
|
wiki: $tw.wiki,
|
|
|
|
pluginType: "language",
|
|
|
|
controllerTitle: "$:/language",
|
|
|
|
defaultPlugins: [
|
|
|
|
"$:/languages/en-US"
|
2016-08-15 18:47:26 +00:00
|
|
|
],
|
|
|
|
onSwitch: function(plugins) {
|
|
|
|
if($tw.browser) {
|
|
|
|
var pluginTiddler = $tw.wiki.getTiddler(plugins[0]);
|
|
|
|
if(pluginTiddler) {
|
|
|
|
document.documentElement.setAttribute("dir",pluginTiddler.getFieldString("text-direction") || "auto");
|
|
|
|
} else {
|
|
|
|
document.documentElement.removeAttribute("dir");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-09 19:18:46 +00:00
|
|
|
});
|
2013-04-30 22:04:15 +00:00
|
|
|
// Kick off the theme manager
|
2014-02-08 09:29:37 +00:00
|
|
|
$tw.themeManager = new $tw.PluginSwitcher({
|
|
|
|
wiki: $tw.wiki,
|
|
|
|
pluginType: "theme",
|
|
|
|
controllerTitle: "$:/theme",
|
|
|
|
defaultPlugins: [
|
|
|
|
"$:/themes/tiddlywiki/snowwhite",
|
|
|
|
"$:/themes/tiddlywiki/vanilla"
|
|
|
|
]
|
|
|
|
});
|
2016-04-22 07:36:29 +00:00
|
|
|
// Kick off the keyboard manager
|
|
|
|
$tw.keyboardManager = new $tw.KeyboardManager();
|
2018-11-06 13:34:51 +00:00
|
|
|
// Listen for shortcuts
|
|
|
|
if($tw.browser) {
|
|
|
|
$tw.utils.addEventListeners(document,[{
|
|
|
|
name: "keydown",
|
|
|
|
handlerObject: $tw.keyboardManager,
|
|
|
|
handlerMethod: "handleKeydownEvent"
|
|
|
|
}]);
|
|
|
|
}
|
2014-08-13 19:06:44 +00:00
|
|
|
// Create a root widget for attaching event handlers. By using it as the parentWidget for another widget tree, one can reuse the event handlers
|
2018-03-23 09:35:39 +00:00
|
|
|
$tw.rootWidget = new widget.widget({
|
|
|
|
type: "widget",
|
|
|
|
children: []
|
|
|
|
},{
|
|
|
|
wiki: $tw.wiki,
|
|
|
|
document: $tw.browser ? document : $tw.fakeDocument
|
|
|
|
});
|
|
|
|
// Execute any startup actions
|
|
|
|
var executeStartupTiddlers = function(tag) {
|
|
|
|
$tw.utils.each($tw.wiki.filterTiddlers("[all[shadows+tiddlers]tag[" + tag + "]!has[draft.of]]"),function(title) {
|
|
|
|
$tw.rootWidget.invokeActionString($tw.wiki.getTiddlerText(title),$tw.rootWidget);
|
2014-08-13 19:20:58 +00:00
|
|
|
});
|
2018-03-23 09:35:39 +00:00
|
|
|
};
|
|
|
|
executeStartupTiddlers("$:/tags/StartupAction");
|
|
|
|
if($tw.browser) {
|
|
|
|
executeStartupTiddlers("$:/tags/StartupAction/Browser");
|
|
|
|
}
|
|
|
|
if($tw.node) {
|
|
|
|
executeStartupTiddlers("$:/tags/StartupAction/Node");
|
2014-08-13 19:20:58 +00:00
|
|
|
}
|
2018-03-23 09:35:39 +00:00
|
|
|
// Clear outstanding tiddler store change events to avoid an unnecessary refresh cycle at startup
|
|
|
|
$tw.wiki.clearTiddlerEventQueue();
|
2014-08-14 10:12:25 +00:00
|
|
|
// Find a working syncadaptor
|
|
|
|
$tw.syncadaptor = undefined;
|
|
|
|
$tw.modules.forEachModuleOfType("syncadaptor",function(title,module) {
|
|
|
|
if(!$tw.syncadaptor && module.adaptorClass) {
|
|
|
|
$tw.syncadaptor = new module.adaptorClass({wiki: $tw.wiki});
|
|
|
|
}
|
|
|
|
});
|
2014-08-20 09:02:44 +00:00
|
|
|
// Set up the syncer object if we've got a syncadaptor
|
2014-08-14 10:12:25 +00:00
|
|
|
if($tw.syncadaptor) {
|
|
|
|
$tw.syncer = new $tw.Syncer({wiki: $tw.wiki, syncadaptor: $tw.syncadaptor});
|
2014-08-20 09:02:44 +00:00
|
|
|
}
|
|
|
|
// Setup the saver handler
|
|
|
|
$tw.saverHandler = new $tw.SaverHandler({wiki: $tw.wiki, dirtyTracking: !$tw.syncadaptor});
|
2012-05-05 10:21:59 +00:00
|
|
|
// Host-specific startup
|
2012-05-19 10:29:51 +00:00
|
|
|
if($tw.browser) {
|
2012-07-15 16:37:03 +00:00
|
|
|
// Install the popup manager
|
2014-11-22 10:19:03 +00:00
|
|
|
$tw.popup = new $tw.utils.Popup();
|
2013-10-21 19:14:01 +00:00
|
|
|
// Install the animator
|
|
|
|
$tw.anim = new $tw.utils.Animator();
|
2012-05-05 10:21:59 +00:00
|
|
|
}
|
2012-05-04 17:49:04 +00:00
|
|
|
};
|
2012-04-30 11:23:03 +00:00
|
|
|
|
|
|
|
})();
|