From 2c2d03f7a76f81b68a9bce2e84f7fb05e1197a9b Mon Sep 17 00:00:00 2001 From: Jermolene Date: Thu, 7 Mar 2019 18:43:23 +0000 Subject: [PATCH] Refactor startup action execution so that they can switch language/theme --- core/modules/startup/startup.js | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/core/modules/startup/startup.js b/core/modules/startup/startup.js index 442ba67ad..8c2153ea1 100755 --- a/core/modules/startup/startup.js +++ b/core/modules/startup/startup.js @@ -55,6 +55,27 @@ exports.startup = function() { $tw.version = $tw.utils.extractVersionInfo(); // Set up the performance framework $tw.perf = new $tw.Performance($tw.wiki.getTiddlerText(PERFORMANCE_INSTRUMENTATION_CONFIG_TITLE,"no") === "yes"); + // 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 + 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); + }); + }; + executeStartupTiddlers("$:/tags/StartupAction"); + if($tw.browser) { + executeStartupTiddlers("$:/tags/StartupAction/Browser"); + } + if($tw.node) { + executeStartupTiddlers("$:/tags/StartupAction/Node"); + } // Kick off the language manager and switcher $tw.language = new $tw.Language(); $tw.languageSwitcher = new $tw.PluginSwitcher({ @@ -95,27 +116,6 @@ exports.startup = function() { handlerMethod: "handleKeydownEvent" }]); } - // 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 - 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); - }); - }; - executeStartupTiddlers("$:/tags/StartupAction"); - if($tw.browser) { - executeStartupTiddlers("$:/tags/StartupAction/Browser"); - } - if($tw.node) { - executeStartupTiddlers("$:/tags/StartupAction/Node"); - } // Clear outstanding tiddler store change events to avoid an unnecessary refresh cycle at startup $tw.wiki.clearTiddlerEventQueue(); // Find a working syncadaptor