From a637f7fb60a77b290faa42d8e534424aa149e3c3 Mon Sep 17 00:00:00 2001 From: saqimtiaz Date: Mon, 16 Nov 2020 17:27:46 +0100 Subject: [PATCH] Modals: add navigator to handle tm-navigate (#5027) * Wrap modal in a navigator widget to allow tm-navigate to work * Move all story list handling to Modal * Make sure any values for story list or history list sent as variables have precedence * Code clean up --- core/modules/utils/dom/modal.js | 40 +++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/core/modules/utils/dom/modal.js b/core/modules/utils/dom/modal.js index df6ef5432..561dbf298 100644 --- a/core/modules/utils/dom/modal.js +++ b/core/modules/utils/dom/modal.js @@ -13,6 +13,7 @@ Modal message mechanism "use strict"; var widget = require("$:/core/modules/widgets/widget.js"); +var navigator = require("$:/core/modules/widgets/navigator.js"); var Modal = function(wiki) { this.wiki = wiki; @@ -41,7 +42,12 @@ Modal.prototype.display = function(title,options) { return; } // Create the variables - var variables = $tw.utils.extend({currentTiddler: title},options.variables); + var variables = $tw.utils.extend({ + currentTiddler: title, + "tv-story-list": (options.event && options.event.widget ? options.event.widget.getVariable("tv-story-list") : ""), + "tv-history-list": (options.event && options.event.widget ? options.event.widget.getVariable("tv-history-list") : "") + },options.variables); + // Create the wrapper divs var wrapper = this.srcDocument.createElement("div"), modalBackdrop = this.srcDocument.createElement("div"), @@ -75,6 +81,31 @@ Modal.prototype.display = function(title,options) { modalFooter.appendChild(modalFooterHelp); modalFooter.appendChild(modalFooterButtons); modalWrapper.appendChild(modalFooter); + var navigatorTree = { + "type": "navigator", + "attributes": { + "story": { + "name": "story", + "type": "string", + "value": variables["tv-story-list"] + }, + "history": { + "name": "history", + "type": "string", + "value": variables["tv-history-list"] + } + }, + "tag": "$navigator", + "isBlock": true, + "children": [] + }; + var navigatorWidgetNode = new navigator.navigator(navigatorTree, { + wiki: this.wiki, + document : this.srcDocument, + parentWidget: $tw.rootWidget + }); + navigatorWidgetNode.render(modalBody,null); + // Render the title of the message var headerWidgetNode = this.wiki.makeTranscludeWidget(title,{ field: "subtitle", @@ -86,7 +117,7 @@ Modal.prototype.display = function(title,options) { type: "string", value: title }}}], - parentWidget: $tw.rootWidget, + parentWidget: navigatorWidgetNode, document: this.srcDocument, variables: variables, importPageMacros: true @@ -94,11 +125,12 @@ Modal.prototype.display = function(title,options) { headerWidgetNode.render(headerTitle,null); // Render the body of the message var bodyWidgetNode = this.wiki.makeTranscludeWidget(title,{ - parentWidget: $tw.rootWidget, + parentWidget: navigatorWidgetNode, document: this.srcDocument, variables: variables, importPageMacros: true }); + bodyWidgetNode.render(modalBody,null); // Setup the link if present if(options.downloadLink) { @@ -135,7 +167,7 @@ Modal.prototype.display = function(title,options) { value: $tw.language.getString("Buttons/Close/Caption") }}} ]}], - parentWidget: $tw.rootWidget, + parentWidget: navigatorWidgetNode, document: this.srcDocument, variables: variables, importPageMacros: true