1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-28 11:00:27 +00:00

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
This commit is contained in:
saqimtiaz 2020-11-16 17:27:46 +01:00 committed by GitHub
parent ca4cdc81dd
commit a637f7fb60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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