diff --git a/core/modules/widgets/navigator.js b/core/modules/widgets/navigator.js index 9494346fb..4825e7a02 100755 --- a/core/modules/widgets/navigator.js +++ b/core/modules/widgets/navigator.js @@ -84,39 +84,50 @@ NavigatorWidget.prototype.getStoryList = function() { }; NavigatorWidget.prototype.saveStoryList = function(storyList) { - var storyTiddler = this.wiki.getTiddler(this.storyTitle); - this.wiki.addTiddler(new $tw.Tiddler( - {title: this.storyTitle}, - storyTiddler, - {list: storyList} - )); + if(this.storyTitle) { + var storyTiddler = this.wiki.getTiddler(this.storyTitle); + this.wiki.addTiddler(new $tw.Tiddler( + {title: this.storyTitle}, + storyTiddler, + {list: storyList} + )); + } }; NavigatorWidget.prototype.removeTitleFromStory = function(storyList,title) { - var p = storyList.indexOf(title); - while(p !== -1) { - storyList.splice(p,1); - p = storyList.indexOf(title); + if(storyList) { + var p = storyList.indexOf(title); + while(p !== -1) { + storyList.splice(p,1); + p = storyList.indexOf(title); + } } }; NavigatorWidget.prototype.replaceFirstTitleInStory = function(storyList,oldTitle,newTitle) { - var pos = storyList.indexOf(oldTitle); - if(pos !== -1) { - storyList[pos] = newTitle; - do { - pos = storyList.indexOf(oldTitle,pos + 1); - if(pos !== -1) { - storyList.splice(pos,1); - } - } while(pos !== -1); - } else { - storyList.splice(0,0,newTitle); + if(storyList) { + var pos = storyList.indexOf(oldTitle); + if(pos !== -1) { + storyList[pos] = newTitle; + do { + pos = storyList.indexOf(oldTitle,pos + 1); + if(pos !== -1) { + storyList.splice(pos,1); + } + } while(pos !== -1); + } else { + storyList.splice(0,0,newTitle); + } } }; NavigatorWidget.prototype.addToStory = function(title,fromTitle) { - this.wiki.addToStory(title,fromTitle,this.storyTitle,{openLinkFromInsideRiver: this.getAttribute("openLinkFromInsideRiver","top"),openLinkFromOutsideRiver: this.getAttribute("openLinkFromOutsideRiver","top")}); + if(this.storyTitle) { + this.wiki.addToStory(title,fromTitle,this.storyTitle,{ + openLinkFromInsideRiver: this.getAttribute("openLinkFromInsideRiver","top"), + openLinkFromOutsideRiver: this.getAttribute("openLinkFromOutsideRiver","top") + }); + } }; /* @@ -458,14 +469,14 @@ NavigatorWidget.prototype.handleNewTiddlerEvent = function(event) { },this.wiki.getModificationFields()); this.wiki.addTiddler(draftTiddler); // Update the story to insert the new draft at the top and remove any existing tiddler - if(storyList.indexOf(draftTitle) === -1) { + if(storyList && storyList.indexOf(draftTitle) === -1) { var slot = storyList.indexOf(event.navigateFromTitle); if(slot === -1) { slot = this.getAttribute("openLinkFromOutsideRiver","top") === "bottom" ? storyList.length - 1 : slot; } storyList.splice(slot + 1,0,draftTitle); } - if(storyList.indexOf(title) !== -1) { + if(storyList && storyList.indexOf(title) !== -1) { storyList.splice(storyList.indexOf(title),1); } this.saveStoryList(storyList); @@ -521,7 +532,7 @@ NavigatorWidget.prototype.handleImportTiddlersEvent = function(event) { var storyList = this.getStoryList(), history = []; // Add it to the story - if(storyList.indexOf(IMPORT_TITLE) === -1) { + if(storyList && storyList.indexOf(IMPORT_TITLE) === -1) { storyList.unshift(IMPORT_TITLE); } // And to history diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 3e5687638..a4bc7b650 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -1388,8 +1388,10 @@ fromPageRect: page coordinates of the origin of the navigation historyTitle: title of history tiddler (defaults to $:/HistoryList) */ exports.addToHistory = function(title,fromPageRect,historyTitle) { - var story = new $tw.Story({wiki: this, historyTitle: historyTitle}); - story.addToHistory(title,fromPageRect); + if(historyTitle) { + var story = new $tw.Story({wiki: this, historyTitle: historyTitle}); + story.addToHistory(title,fromPageRect); + } }; /* @@ -1400,8 +1402,10 @@ storyTitle: title of story tiddler (defaults to $:/StoryList) options: see story.js */ exports.addToStory = function(title,fromTitle,storyTitle,options) { - var story = new $tw.Story({wiki: this, storyTitle: storyTitle}); - story.addToStory(title,fromTitle,options); + if(storyTitle) { + var story = new $tw.Story({wiki: this, storyTitle: storyTitle}); + story.addToStory(title,fromTitle,options); + } }; /*