1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-04 23:39:57 +00:00
This commit is contained in:
mrichter 2020-11-16 17:51:46 +01:00
commit 31de02f8d8
2 changed files with 48 additions and 4 deletions

View File

@ -13,6 +13,7 @@ Modal message mechanism
"use strict"; "use strict";
var widget = require("$:/core/modules/widgets/widget.js"); var widget = require("$:/core/modules/widgets/widget.js");
var navigator = require("$:/core/modules/widgets/navigator.js");
var Modal = function(wiki) { var Modal = function(wiki) {
this.wiki = wiki; this.wiki = wiki;
@ -41,7 +42,12 @@ Modal.prototype.display = function(title,options) {
return; return;
} }
// Create the variables // 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 // Create the wrapper divs
var wrapper = this.srcDocument.createElement("div"), var wrapper = this.srcDocument.createElement("div"),
modalBackdrop = this.srcDocument.createElement("div"), modalBackdrop = this.srcDocument.createElement("div"),
@ -75,6 +81,31 @@ Modal.prototype.display = function(title,options) {
modalFooter.appendChild(modalFooterHelp); modalFooter.appendChild(modalFooterHelp);
modalFooter.appendChild(modalFooterButtons); modalFooter.appendChild(modalFooterButtons);
modalWrapper.appendChild(modalFooter); 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 // Render the title of the message
var headerWidgetNode = this.wiki.makeTranscludeWidget(title,{ var headerWidgetNode = this.wiki.makeTranscludeWidget(title,{
field: "subtitle", field: "subtitle",
@ -86,7 +117,7 @@ Modal.prototype.display = function(title,options) {
type: "string", type: "string",
value: title value: title
}}}], }}}],
parentWidget: $tw.rootWidget, parentWidget: navigatorWidgetNode,
document: this.srcDocument, document: this.srcDocument,
variables: variables, variables: variables,
importPageMacros: true importPageMacros: true
@ -94,11 +125,12 @@ Modal.prototype.display = function(title,options) {
headerWidgetNode.render(headerTitle,null); headerWidgetNode.render(headerTitle,null);
// Render the body of the message // Render the body of the message
var bodyWidgetNode = this.wiki.makeTranscludeWidget(title,{ var bodyWidgetNode = this.wiki.makeTranscludeWidget(title,{
parentWidget: $tw.rootWidget, parentWidget: navigatorWidgetNode,
document: this.srcDocument, document: this.srcDocument,
variables: variables, variables: variables,
importPageMacros: true importPageMacros: true
}); });
bodyWidgetNode.render(modalBody,null); bodyWidgetNode.render(modalBody,null);
// Setup the link if present // Setup the link if present
if(options.downloadLink) { if(options.downloadLink) {
@ -135,7 +167,7 @@ Modal.prototype.display = function(title,options) {
value: $tw.language.getString("Buttons/Close/Caption") value: $tw.language.getString("Buttons/Close/Caption")
}}} }}}
]}], ]}],
parentWidget: $tw.rootWidget, parentWidget: navigatorWidgetNode,
document: this.srcDocument, document: this.srcDocument,
variables: variables, variables: variables,
importPageMacros: true importPageMacros: true

View File

@ -56,3 +56,15 @@ In order to remove `$:/baz` in any case, existing or not, simply use the `+` pre
* <$link to="is Operator">`foo bar $:/baz +[!is[system]]`</$link> * <$link to="is Operator">`foo bar $:/baz +[!is[system]]`</$link>
* <$link to="prefix Operator">`foo bar $:/baz +[!prefix[$:/]]`</$link> * <$link to="prefix Operator">`foo bar $:/baz +[!prefix[$:/]]`</$link>
There is also a difference between the `:intersection` and `+` prefixes due to varying inputs.
The `+` prefix should be thought of as an "AND" in formal logic, e.g. "give me all titles that satisfy condition A ''and'' condition B". But it's not suitable for all cases; if condition B uses a filter operator that replaces its input, then it will be difficult to use the `+` prefix. For example, if you wanted to find out what tags two tiddlers have in common, you might try to write a filter expression like:
* <$link to="tags Operator">`[[field Operator]tags[]] +[[compare Operator]tags[]]`</$link>
But that won't work, because the second filter run will end up throwing away its input and replacing it with an input consisting of the single title `[[compare Operator]]`. So the result you'd get from that filter expression would be just the tags of the `compare Operator` tiddler.
For cases like this, the `:intersection` prefix is what you need. It takes the filter output so far, //sets it aside// in temporary storage, and starts the next filter run with all tiddler titles as input. Then once the latest filter run has completed, it takes the latest output, compares it to the set-aside output, and produces a new output that contains only titles that appeared in both the set-aside output and the latest output. So to get only the tags that the `field Operator` and `compare Operator` tiddlers have in common, you would write a filter expresison like this:
* <$link to="tags Operator">`[[field Operator]tags[]] :intersection[[compare Operator]tags[]]`</$link>