From d1c396507bce664390617cefdc7cc6eb73bd2368 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 24 Oct 2012 22:15:16 +0100 Subject: [PATCH] Update the PageTemplate to use the list macro instead of the story macro We're going to drop the story macro, which will break some things in the short term. But it's awesome to be using the one macro for so many different purposes (the main story, the tags listing, recent changes, etc.) --- core/modules/macros/navigationcatcher.js | 230 +++++++++++++++++++++++ core/templates/PageTemplate.tid | 4 +- tw5.com/wiki/StoryList.tid | 6 + 3 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 core/modules/macros/navigationcatcher.js create mode 100644 tw5.com/wiki/StoryList.tid 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