diff --git a/core/modules/macros/story/story.js b/core/modules/macros/story/story.js index 1f2ca1562..093521f3a 100644 --- a/core/modules/macros/story/story.js +++ b/core/modules/macros/story/story.js @@ -31,6 +31,18 @@ exports.info = { events: ["tw-navigate","tw-EditTiddler","tw-SaveTiddler"] }; +exports.getStory = function() { + var storyTiddler = this.wiki.getTiddler(this.params.story), + story = {tiddlers: []}; + if(storyTiddler && $tw.utils.hop(storyTiddler.fields,"text")) { + return JSON.parse(storyTiddler.fields.text); + } else { + return { + tiddlers: [] + }; + } +}; + exports.handleEvent = function(event) { if(this.eventMap[event.type]) { this.eventMap[event.type].call(this,event); @@ -42,13 +54,8 @@ exports.eventMap = {}; // Navigate to a specified tiddler exports.eventMap["tw-navigate"] = function(event) { var template = this.params.defaultViewTemplate || "$:/templates/ViewTemplate", - storyTiddler = this.wiki.getTiddler(this.params.story), - story = {tiddlers: []}, + story = this.getStory(), navTiddler,t,tiddler; - // Get the story - if(storyTiddler && $tw.utils.hop(storyTiddler.fields,"text")) { - story = JSON.parse(storyTiddler.fields.text); - } // See if the tiddler we want is already there for(t=0; t