From 7c8c5cf7458f6b736693183b7d0f919e351c996e Mon Sep 17 00:00:00 2001 From: Jermolene Date: Tue, 6 May 2014 10:14:22 +0100 Subject: [PATCH] Fix problem with parsing main UI boot tiddlers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We were parsing the boot tiddlers, making them into a widget and then refreshing the widget tree. The problem is that subsequent chances to the boot tiddlers themselves wouldn’t be picked up as part of the refresh. Now we indirectly parse those UI boot tiddlers through a transclusion, which does get refreshed in the desired way. --- core/modules/startup/render.js | 9 +++------ core/modules/utils/dom/modal.js | 3 +-- core/modules/utils/dom/notifier.js | 3 +-- core/modules/wiki.js | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/core/modules/startup/render.js b/core/modules/startup/render.js index 42ad55b7b..f677788d0 100644 --- a/core/modules/startup/render.js +++ b/core/modules/startup/render.js @@ -28,8 +28,7 @@ var DRAFT_TIDDLER_TIMEOUT = 400; exports.startup = function() { // Set up the title - var titleParser = $tw.wiki.parseTiddler(PAGE_TITLE_TITLE); - $tw.titleWidgetNode = $tw.wiki.makeWidget(titleParser,{document: $tw.fakeDocument}); + $tw.titleWidgetNode = $tw.wiki.makeTranscludeWidget(PAGE_TITLE_TITLE,{document: $tw.fakeDocument, parseAsInline: true}); $tw.titleContainer = $tw.fakeDocument.createElement("div"); $tw.titleWidgetNode.render($tw.titleContainer,null); document.title = $tw.titleContainer.textContent; @@ -39,8 +38,7 @@ exports.startup = function() { } }); // Set up the styles - var styleParser = $tw.wiki.parseTiddler(PAGE_STYLESHEET_TITLE); - $tw.styleWidgetNode = $tw.wiki.makeWidget(styleParser,{document: $tw.fakeDocument}); + $tw.styleWidgetNode = $tw.wiki.makeTranscludeWidget(PAGE_STYLESHEET_TITLE,{document: $tw.fakeDocument}); $tw.styleContainer = $tw.fakeDocument.createElement("style"); $tw.styleWidgetNode.render($tw.styleContainer,null); $tw.styleElement = document.createElement("style"); @@ -52,9 +50,8 @@ exports.startup = function() { } })); // Display the $:/core/ui/PageMacros tiddler to kick off the display - var parser = $tw.wiki.parseTiddler(PAGE_TEMPLATE_TITLE); $tw.perf.report("mainRender",function() { - $tw.pageWidgetNode = $tw.wiki.makeWidget(parser,{document: document, parentWidget: $tw.rootWidget}); + $tw.pageWidgetNode = $tw.wiki.makeTranscludeWidget(PAGE_TEMPLATE_TITLE,{document: document, parentWidget: $tw.rootWidget}); $tw.pageContainer = document.createElement("div"); $tw.utils.addClass($tw.pageContainer,"tw-page-container-wrapper"); document.body.insertBefore($tw.pageContainer,document.body.firstChild); diff --git a/core/modules/utils/dom/modal.js b/core/modules/utils/dom/modal.js index f2e2c1d45..2ba4680ed 100644 --- a/core/modules/utils/dom/modal.js +++ b/core/modules/utils/dom/modal.js @@ -80,8 +80,7 @@ Modal.prototype.display = function(title,options) { headerWidgetNode.refresh(changes,modalHeader,null); }); // Render the body of the message - var bodyParser = this.wiki.parseTiddler(title), - bodyWidgetNode = this.wiki.makeWidget(bodyParser,{parentWidget: $tw.rootWidget, document: document}); + var bodyWidgetNode = this.wiki.makeTranscludeWidget(title,{parentWidget: $tw.rootWidget, document: document}); bodyWidgetNode.render(modalBody,null); this.wiki.addEventListener("change",function(changes) { bodyWidgetNode.refresh(changes,modalBody,null); diff --git a/core/modules/utils/dom/notifier.js b/core/modules/utils/dom/notifier.js index 9e712039f..c2f25c2a9 100644 --- a/core/modules/utils/dom/notifier.js +++ b/core/modules/utils/dom/notifier.js @@ -37,8 +37,7 @@ Notifier.prototype.display = function(title,options) { // Add classes $tw.utils.addClass(notification,"tw-notification"); // Render the body of the notification - var parser = this.wiki.parseTiddler(title), - widgetNode = this.wiki.makeWidget(parser,{parentWidget: $tw.rootWidget, document: document}); + var widgetNode = this.wiki.makeTranscludeWidget(title,{parentWidget: $tw.rootWidget, document: document}); widgetNode.render(notification,null); this.wiki.addEventListener("change",function(changes) { widgetNode.refresh(changes,notification,null); diff --git a/core/modules/wiki.js b/core/modules/wiki.js index e1031e6a2..af398aec9 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -858,6 +858,25 @@ exports.makeWidget = function(parser,options) { }); }; +/* +Make a widget tree for transclusion +title: target tiddler title +options: as for wiki.makeWidget() (including parseAsInline) +*/ +exports.makeTranscludeWidget = function(title,options) { + options = options || {}; + var parseTree = {tree: [{ + type: "transclude", + attributes: { + tiddler: { + name: "tiddler", + type: "string", + value: title}}, + isBlock: !options.parseAsInline} + ]}; + return $tw.wiki.makeWidget(parseTree,options); +}; + /* Parse text in a specified format and render it into another format outputType: content type for the output