mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-08 23:03:50 +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) {
|
NavigatorWidget.prototype.saveStoryList = function(storyList) {
|
||||||
var storyTiddler = this.wiki.getTiddler(this.storyTitle);
|
if(this.storyTitle) {
|
||||||
this.wiki.addTiddler(new $tw.Tiddler(
|
var storyTiddler = this.wiki.getTiddler(this.storyTitle);
|
||||||
{title: this.storyTitle},
|
this.wiki.addTiddler(new $tw.Tiddler(
|
||||||
storyTiddler,
|
{title: this.storyTitle},
|
||||||
{list: storyList}
|
storyTiddler,
|
||||||
));
|
{list: storyList}
|
||||||
|
));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
NavigatorWidget.prototype.removeTitleFromStory = function(storyList,title) {
|
NavigatorWidget.prototype.removeTitleFromStory = function(storyList,title) {
|
||||||
var p = storyList.indexOf(title);
|
if(storyList) {
|
||||||
while(p !== -1) {
|
var p = storyList.indexOf(title);
|
||||||
storyList.splice(p,1);
|
while(p !== -1) {
|
||||||
p = storyList.indexOf(title);
|
storyList.splice(p,1);
|
||||||
|
p = storyList.indexOf(title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
NavigatorWidget.prototype.replaceFirstTitleInStory = function(storyList,oldTitle,newTitle) {
|
NavigatorWidget.prototype.replaceFirstTitleInStory = function(storyList,oldTitle,newTitle) {
|
||||||
var pos = storyList.indexOf(oldTitle);
|
if(storyList) {
|
||||||
if(pos !== -1) {
|
var pos = storyList.indexOf(oldTitle);
|
||||||
storyList[pos] = newTitle;
|
if(pos !== -1) {
|
||||||
do {
|
storyList[pos] = newTitle;
|
||||||
pos = storyList.indexOf(oldTitle,pos + 1);
|
do {
|
||||||
if(pos !== -1) {
|
pos = storyList.indexOf(oldTitle,pos + 1);
|
||||||
storyList.splice(pos,1);
|
if(pos !== -1) {
|
||||||
}
|
storyList.splice(pos,1);
|
||||||
} while(pos !== -1);
|
}
|
||||||
} else {
|
} while(pos !== -1);
|
||||||
storyList.splice(0,0,newTitle);
|
} else {
|
||||||
|
storyList.splice(0,0,newTitle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
NavigatorWidget.prototype.addToStory = function(title,fromTitle) {
|
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.getModificationFields());
|
||||||
this.wiki.addTiddler(draftTiddler);
|
this.wiki.addTiddler(draftTiddler);
|
||||||
// Update the story to insert the new draft at the top and remove any existing tiddler
|
// 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);
|
var slot = storyList.indexOf(event.navigateFromTitle);
|
||||||
if(slot === -1) {
|
if(slot === -1) {
|
||||||
slot = this.getAttribute("openLinkFromOutsideRiver","top") === "bottom" ? storyList.length - 1 : slot;
|
slot = this.getAttribute("openLinkFromOutsideRiver","top") === "bottom" ? storyList.length - 1 : slot;
|
||||||
}
|
}
|
||||||
storyList.splice(slot + 1,0,draftTitle);
|
storyList.splice(slot + 1,0,draftTitle);
|
||||||
}
|
}
|
||||||
if(storyList.indexOf(title) !== -1) {
|
if(storyList && storyList.indexOf(title) !== -1) {
|
||||||
storyList.splice(storyList.indexOf(title),1);
|
storyList.splice(storyList.indexOf(title),1);
|
||||||
}
|
}
|
||||||
this.saveStoryList(storyList);
|
this.saveStoryList(storyList);
|
||||||
@ -521,7 +532,7 @@ NavigatorWidget.prototype.handleImportTiddlersEvent = function(event) {
|
|||||||
var storyList = this.getStoryList(),
|
var storyList = this.getStoryList(),
|
||||||
history = [];
|
history = [];
|
||||||
// Add it to the story
|
// Add it to the story
|
||||||
if(storyList.indexOf(IMPORT_TITLE) === -1) {
|
if(storyList && storyList.indexOf(IMPORT_TITLE) === -1) {
|
||||||
storyList.unshift(IMPORT_TITLE);
|
storyList.unshift(IMPORT_TITLE);
|
||||||
}
|
}
|
||||||
// And to history
|
// And to history
|
||||||
|
@ -1388,8 +1388,10 @@ fromPageRect: page coordinates of the origin of the navigation
|
|||||||
historyTitle: title of history tiddler (defaults to $:/HistoryList)
|
historyTitle: title of history tiddler (defaults to $:/HistoryList)
|
||||||
*/
|
*/
|
||||||
exports.addToHistory = function(title,fromPageRect,historyTitle) {
|
exports.addToHistory = function(title,fromPageRect,historyTitle) {
|
||||||
var story = new $tw.Story({wiki: this, historyTitle: historyTitle});
|
if(historyTitle) {
|
||||||
story.addToHistory(title,fromPageRect);
|
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
|
options: see story.js
|
||||||
*/
|
*/
|
||||||
exports.addToStory = function(title,fromTitle,storyTitle,options) {
|
exports.addToStory = function(title,fromTitle,storyTitle,options) {
|
||||||
var story = new $tw.Story({wiki: this, storyTitle: storyTitle});
|
if(storyTitle) {
|
||||||
story.addToStory(title,fromTitle,options);
|
var story = new $tw.Story({wiki: this, storyTitle: storyTitle});
|
||||||
|
story.addToStory(title,fromTitle,options);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user