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() {
|
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;
|
2023-07-22 14:47:39 +00:00
|
|
|
// 2023-07-21 Edge returns UA below. So we use "isChromeLike"
|
|
|
|
//'mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/114.0.0.0 safari/537.36 edg/114.0.1823.82'
|
|
|
|
$tw.browser.isChromeLike = navigator.userAgent.toLowerCase().indexOf("chrome") > -1;
|
|
|
|
$tw.browser.hasTouch = !!window.matchMedia && window.matchMedia("(pointer: coarse)").matches;
|
|
|
|
$tw.browser.isMobileChrome = $tw.browser.isChromeLike && $tw.browser.hasTouch;
|
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);
|
2018-11-25 10:51:42 +00:00
|
|
|
$tw.platform.isLinux = /Linux/i.test(navigator.platform);
|
2016-04-22 07:36:29 +00:00
|
|
|
} 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");
|
2019-03-07 18:43:23 +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
|
|
|
|
$tw.rootWidget = new widget.widget({
|
|
|
|
type: "widget",
|
|
|
|
children: []
|
|
|
|
},{
|
|
|
|
wiki: $tw.wiki,
|
|
|
|
document: $tw.browser ? document : $tw.fakeDocument
|
|
|
|
});
|
|
|
|
// Execute any startup actions
|
2020-11-26 12:41:24 +00:00
|
|
|
$tw.rootWidget.invokeActionsByTag("$:/tags/StartupAction");
|
2019-03-07 18:43:23 +00:00
|
|
|
if($tw.browser) {
|
2021-01-15 16:55:52 +00:00
|
|
|
$tw.rootWidget.invokeActionsByTag("$:/tags/StartupAction/Browser");
|
2019-03-07 18:43:23 +00:00
|
|
|
}
|
|
|
|
if($tw.node) {
|
2021-01-15 16:55:52 +00:00
|
|
|
$tw.rootWidget.invokeActionsByTag("$:/tags/StartupAction/Node");
|
2019-03-07 18:43:23 +00:00
|
|
|
}
|
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: [
|
2019-03-07 18:46:24 +00:00
|
|
|
"$:/languages/en-GB"
|
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"
|
|
|
|
}]);
|
|
|
|
}
|
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) {
|
2022-11-20 17:26:14 +00:00
|
|
|
$tw.syncer = new $tw.Syncer({
|
|
|
|
wiki: $tw.wiki,
|
|
|
|
syncadaptor: $tw.syncadaptor,
|
|
|
|
logging: $tw.wiki.getTiddlerText('$:/config/SyncLogging', "yes") === "yes"
|
|
|
|
});
|
2020-03-30 14:24:05 +00:00
|
|
|
}
|
2014-08-20 09:02:44 +00:00
|
|
|
// Setup the saver handler
|
2019-02-08 15:38:23 +00:00
|
|
|
$tw.saverHandler = new $tw.SaverHandler({
|
|
|
|
wiki: $tw.wiki,
|
|
|
|
dirtyTracking: !$tw.syncadaptor,
|
|
|
|
preloadDirty: $tw.boot.preloadDirty || []
|
|
|
|
});
|
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
|
|
|
|
|
|
|
})();
|