From f718c597e3b5d636d716cc7cd6aa9d540ca8b938 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 22 Jun 2012 18:02:34 +0100 Subject: [PATCH] New method for the story macro --- core/modules/macros/story/story.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/modules/macros/story/story.js b/core/modules/macros/story/story.js index bcc6bbe90..7298b7b06 100644 --- a/core/modules/macros/story/story.js +++ b/core/modules/macros/story/story.js @@ -67,6 +67,25 @@ exports.findStoryElementContainingNode = function(node) { return slot; }; +/* +Return the index of the story element that corresponds to a particular title +startIndex: index to start search (use zero to search from the top) +tiddlerTitle: tiddler title to seach for +templateTitle: optional template title to search for +*/ +exports.findStoryElementByTitle = function(startIndex,tiddlerTitle,templateTitle) { + while(startIndex < this.storyNode.children.length) { + var params = this.storyNode.children[startIndex].children[0].params; + if(params.target === tiddlerTitle) { + if(!templateTitle || params.template === templateTitle) { + return startIndex; + } + } + startIndex++; + } + return undefined; +}; + exports.eventMap = {}; // Navigate to a specified tiddler