mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Fix navigator widget when story and/or history attributes are missing
To fix the crash described here: https://groups.google.com/d/msgid/tiddlywiki/c5461591-bf27-4c85-9f27-9eef14c38816%40googlegroups.com?utm_medium=email&utm_source=footer
This commit is contained in:
parent
0903fd2fec
commit
8159c4a865
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user