/*\ title: $:/core/modules/macros/list.js type: application/javascript module-type: macro List macro \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; exports.info = { name: "list", dependentAll: true, // Tiddlers containing <> macro are dependent on every tiddler params: { type: {byPos: 0, type: "text"}, filter: {byName: true, type: "filter"}, history: {byName: true, type: "tiddler"}, template: {byName: true, type: "tiddler"}, templateText: {byName: true, type: "text"}, editTemplate: {byName: true, type: "tiddler"}, editTemplateText: {byName: true, type: "text"}, emptyMessage: {byName: true, type: "text"}, listviewTiddler: {byName: true, type: "tiddler"}, listview: {byName: true, type: "text"}, itemClass: {byName: true, type: "text"}, map: {byName: true, type: "tiddler"} } }; /* These types are shorthands for particular filters */ var typeMappings = { all: "[!is[shadow]sort[title]]", recent: "[!is[shadow]sort[modified]]", missing: "[is[missing]sort[title]]", orphans: "[is[orphan]sort[title]]", shadowed: "[is[shadow]sort[title]]" }; exports.executeMacro = function() { // Get the list of tiddlers object this.getTiddlerList(); // Create the list frame element var attributes = {"class": ["tw-list-frame"]}; if(this.classes) { $tw.utils.pushTop(attributes["class"],this.classes); } this.listFrame = $tw.Tree.Element(this.isBlock ? "div" : "span",attributes,[]); // Create the list if(this.list.length === 0) { // Check for an empty list this.listFrame.children = [this.getEmptyMessage()]; } else { // Create the list for(var t=0; t=0; t--) { this.removeListElement(t); } // Insert the empty message this.listFrame.children = [this.getEmptyMessage()]; this.listFrame.children[0].renderInDom(this.listFrame.domNode,this.listFrame.domNode.childNodes[0]); return; } } else { // If it is not empty now, but was empty previously, then remove the empty message if(prevListLength === 0) { this.removeListElement(0); } } // Step through the list and adjust our child list elements appropriately for(t=0; t t) { for(var n=index-1; n>=t; n--) { this.removeListElement(n); } } // Refresh the node we're reusing this.listFrame.children[t].refreshInDom(changes); } } // Remove any left over elements if(this.listFrame.children.length > this.list.length) { for(t=this.listFrame.children.length-1; t>=this.list.length; t--) { this.removeListElement(t); } } }; /* Handle any changes to the history list */ exports.handleHistoryChanges = function() { // Get the history data var newHistory = this.wiki.getTiddlerData(this.params.history,[]); // Ignore any entries of the history that match the previous history var entry = 0; while(entry < newHistory.length && entry < this.history.length && newHistory[entry].title === this.history[entry].title) { entry++; } // Navigate forwards to each of the new tiddlers while(entry < newHistory.length) { if(this.listview && this.listview.navigateTo) { this.listview.navigateTo(newHistory[entry]); } entry++; } // Update the history this.history = newHistory; }; })();