/*\ title: $:/core/modules/macros/navigator.js type: application/javascript module-type: macro Traps navigation events to update a story tiddler and history tiddler. Can also optionally capture navigation target in a specified text reference. \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; exports.info = { name: "navigator", params: { story: {byName: "default", type: "text"}, // Actually a tiddler, but we don't want it to be a dependency history: {byName: "default", type: "text"}, // Actually a tiddler, but we don't want it to be a dependency set: {byName: true, type: "tiddler"} } }; exports.getStory = function() { this.story = this.wiki.getTiddlerData(this.params.story,{tiddlers: []}); }; exports.saveStory = function() { if(this.hasParameter("story")) { this.wiki.setTiddlerData(this.params.story,this.story); } }; exports.getHistory = function() { this.history = this.wiki.getTiddlerData(this.params.history,{stack: []}); }; exports.saveHistory = function() { if(this.hasParameter("history")) { this.wiki.setTiddlerData(this.params.history,this.history); } }; exports.handleEvent = function(event) { if(this.eventMap[event.type]) { this.eventMap[event.type].call(this,event); } }; exports.eventMap = {}; // Navigate to a specified tiddler exports.eventMap["tw-navigate"] = function(event) { // Update the story tiddler if specified if(this.hasParameter("story")) { this.getStory(); var t,tiddler,slot; // See if the tiddler is already there for(t=0; t=0; t--) { if(this.story.tiddlers[t].title === event.tiddlerTitle) { this.story.tiddlers.splice(t,1); } } this.saveStory(); } event.stopPropagation(); return false; }; exports.executeMacro = function() { var attributes = {}; if(this.classes) { attributes["class"] = this.classes.slice(0); } for(var t=0; t