/*\ title: $:/core/modules/macros/navigationcatcher.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: "navigationcatcher", 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.getList = function(title) { return this.wiki.getTextReference(title,"").split("\n"); }; exports.saveList = function(title,list) { var storyTiddler = this.wiki.getTiddler(title); this.wiki.addTiddler(new $tw.Tiddler({ title: title },storyTiddler,{text: list.join("\n")})); }; 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 this.story = this.getList(this.storyTitle); var t,tiddler,slot; // See if the tiddler is already there for(t=0; t=0; t--) { if(this.story[t] === event.tiddlerTitle) { this.story.splice(t,1); } } this.saveList(this.storyTitle,this.story); event.stopPropagation(); return false; }; // Place a tiddler in edit mode exports.eventMap["tw-EditTiddler"] = function(event) { this.story = this.getList(this.storyTitle); // Replace the specified tiddler with a draft in edit mode for(var t=0; t