From c9d4714e983f541a5afb6b42364476acc27ec7b5 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Fri, 4 Jul 2014 21:03:11 +0100 Subject: [PATCH 1/3] Extend makeTranscludeWidget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for specifying the filename, and the fallback content within the transclude widget that is used if the transclusion target isn’t found --- core/modules/wiki.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 73b0c9ab6..f4d405bf4 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -856,19 +856,30 @@ exports.makeWidget = function(parser,options) { /* Make a widget tree for transclusion title: target tiddler title -options: as for wiki.makeWidget() (including parseAsInline) +options: as for wiki.makeWidget() plus: +options.field: optional field to transclude (defaults to "text") +options.children: optional array of children for the transclude widget */ exports.makeTranscludeWidget = function(title,options) { options = options || {}; var parseTree = {tree: [{ - type: "transclude", - attributes: { - tiddler: { - name: "tiddler", - type: "string", - value: title}}, - isBlock: !options.parseAsInline} + type: "element", + tag: "div", + children: [{ + type: "transclude", + attributes: { + tiddler: { + name: "tiddler", + type: "string", + value: title}}, + isBlock: !options.parseAsInline}]} ]}; + if(options.field) { + parseTree.tree[0].children[0].attributes.field = {type: "string", value: options.field}; + } + if(options.children) { + parseTree.tree[0].children[0].children = options.children; + } return $tw.wiki.makeWidget(parseTree,options); }; From 465f4ac46903070759a572d183c498c5579cb922 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Fri, 4 Jul 2014 21:07:35 +0100 Subject: [PATCH 2/3] Fix problem with refreshing modal dialogues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously any refreshing of the content of a modal would cause a crash. The problem is the way that we steal the root widget for the render trees used in the modal. The root widget is tied to the container DOM node for the main content area, which isn’t actually a parent of the modal DOM nodes, hence the confusion for the refresh mechanism. --- core/modules/utils/dom/modal.js | 58 +++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/core/modules/utils/dom/modal.js b/core/modules/utils/dom/modal.js index 2ba4680ed..b0efaaa77 100644 --- a/core/modules/utils/dom/modal.js +++ b/core/modules/utils/dom/modal.js @@ -67,20 +67,27 @@ Modal.prototype.display = function(title,options) { modalFooter.appendChild(modalFooterButtons); modalWrapper.appendChild(modalFooter); // Render the title of the message - var titleText; - if(tiddler && tiddler.fields && tiddler.fields.subtitle) { - titleText = tiddler.fields.subtitle; - } else { - titleText = title; - } - var headerParser = this.wiki.parseText("text/vnd.tiddlywiki",titleText,{parseAsInline: true}), - headerWidgetNode = this.wiki.makeWidget(headerParser,{parentWidget: $tw.rootWidget, document: document}); + var headerWidgetNode = this.wiki.makeTranscludeWidget(title,{ + field: "subtitle", + children: [{ + type: "text", + attributes: { + text: { + type: "string", + value: title + }}}], + parentWidget: $tw.rootWidget, + document: document + }); headerWidgetNode.render(headerTitle,null); this.wiki.addEventListener("change",function(changes) { headerWidgetNode.refresh(changes,modalHeader,null); }); // Render the body of the message - var bodyWidgetNode = this.wiki.makeTranscludeWidget(title,{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); @@ -100,14 +107,31 @@ Modal.prototype.display = function(title,options) { modalFooterHelp.appendChild(link); modalFooterHelp.style.float = "left"; } - var footerText; - if(tiddler && tiddler.fields && tiddler.fields.footer) { - footerText = tiddler.fields.footer; - } else { - footerText = '<$button message="tw-close-tiddler" class="btn btn-primary">Close'; - } - var footerParser = this.wiki.parseText("text/vnd.tiddlywiki",footerText,{parseAsInline: true}), - footerWidgetNode = this.wiki.makeWidget(footerParser,{parentWidget: $tw.rootWidget, document: document}); + var footerWidgetNode = this.wiki.makeTranscludeWidget(title,{ + field: "footer", + children: [{ + type: "button", + attributes: { + message: { + type: "string", + value: "tw-close-tiddler" + }, + "class": { + type: "string", + value: "btn btn-primary" + } + }, + children: [{ + type: "text", + attributes: { + text: { + type: "string", + value: "Close" + }}} + ]}], + parentWidget: $tw.rootWidget, + document: document + }); footerWidgetNode.render(modalFooterButtons,null); this.wiki.addEventListener("change",function(changes) { footerWidgetNode.refresh(changes,modalFooterButtons,null); From 3351ae7e29cbf3bed6fc1925ef33664bcc59fef5 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sun, 6 Jul 2014 10:11:21 +0100 Subject: [PATCH 3/3] Fix issue with localStorage error on Firefox Firefox raises an error if window.localStorage is accessed when cookies are disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=771890 --- core/modules/utils/dom/dom.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/modules/utils/dom/dom.js b/core/modules/utils/dom/dom.js index 3d611f768..e896049ed 100644 --- a/core/modules/utils/dom/dom.js +++ b/core/modules/utils/dom/dom.js @@ -96,8 +96,11 @@ exports.getBoundingPageRect = function(element) { Saves a named password in the browser */ exports.savePassword = function(name,password) { - if(window.localStorage) { - localStorage.setItem("tw5-password-" + name,password); + try { + if(window.localStorage) { + localStorage.setItem("tw5-password-" + name,password); + } + } catch(e) { } }; @@ -105,7 +108,11 @@ exports.savePassword = function(name,password) { Retrieve a named password from the browser */ exports.getPassword = function(name) { - return window.localStorage ? localStorage.getItem("tw5-password-" + name) : ""; + try { + return window.localStorage ? localStorage.getItem("tw5-password-" + name) : ""; + } catch(e) { + return ""; + } }; /*