diff --git a/core/modules/macros/navigationcatcher.js b/core/modules/macros/navigationcatcher.js new file mode 100644 index 000000000..fc969e85e --- /dev/null +++ b/core/modules/macros/navigationcatcher.js @@ -0,0 +1,230 @@ +/*\ +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 -<< +<< {{navigation-panel{ @@ -93,7 +93,7 @@ title: $:/templates/PageTemplate
-<> +<>
>> diff --git a/tw5.com/wiki/StoryList.tid b/tw5.com/wiki/StoryList.tid new file mode 100644 index 000000000..b87699f62 --- /dev/null +++ b/tw5.com/wiki/StoryList.tid @@ -0,0 +1,6 @@ +title: $:/StoryList + +HelloThere +Introduction +Improvements +Docs \ No newline at end of file