Skip to content

Commit

Permalink
Remove dependency on wiki.js for story-startup and navigator (#4200)
Browse files Browse the repository at this point in the history
* Update story.js

* Update wiki.js

* Update navigator.js

* Add deprecation console logs to addToHistory and addToStory
  • Loading branch information
BurningTreeC authored Nov 2, 2020
1 parent 70561bd commit d5c4aa2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
9 changes: 7 additions & 2 deletions core/modules/startup/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,21 @@ function openStartupTiddlers(options) {
// Save the story list
$tw.wiki.addTiddler({title: DEFAULT_STORY_TITLE, text: "", list: storyList},$tw.wiki.getModificationFields());
// Update history
var story = new $tw.Story({
wiki: $tw.wiki,
storyTitle: DEFAULT_STORY_TITLE,
historyTitle: DEFAULT_HISTORY_TITLE
});
if(!options.disableHistory) {
// If a target tiddler was specified add it to the history stack
if(target && target !== "") {
// The target tiddler doesn't need double square brackets, but we'll silently remove them if they're present
if(target.indexOf("[[") === 0 && target.substr(-2) === "]]") {
target = target.substr(2,target.length - 4);
}
$tw.wiki.addToHistory(target);
story.addToHistory(target);
} else if(storyList.length > 0) {
$tw.wiki.addToHistory(storyList[0]);
story.addToHistory(storyList[0]);
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions core/modules/widgets/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ NavigatorWidget.prototype.execute = function() {
this.historyTitle = this.getAttribute("history");
this.setVariable("tv-story-list",this.storyTitle);
this.setVariable("tv-history-list",this.historyTitle);
this.story = new $tw.Story({
wiki: this.wiki,
storyTitle: this.storyTitle,
historyTitle: this.historyTitle
});
// Construct the child widgets
this.makeChildWidgets();
};
Expand Down Expand Up @@ -123,7 +128,7 @@ NavigatorWidget.prototype.replaceFirstTitleInStory = function(storyList,oldTitle

NavigatorWidget.prototype.addToStory = function(title,fromTitle) {
if(this.storyTitle) {
this.wiki.addToStory(title,fromTitle,this.storyTitle,{
this.story.addToStory(title,fromTitle,this.storyTitle,{
openLinkFromInsideRiver: this.getAttribute("openLinkFromInsideRiver","top"),
openLinkFromOutsideRiver: this.getAttribute("openLinkFromOutsideRiver","top")
});
Expand All @@ -136,7 +141,7 @@ title: a title string or an array of title strings
fromPageRect: page coordinates of the origin of the navigation
*/
NavigatorWidget.prototype.addToHistory = function(title,fromPageRect) {
this.wiki.addToHistory(title,fromPageRect,this.historyTitle);
this.story.addToHistory(title,fromPageRect,this.historyTitle);
};

/*
Expand Down
6 changes: 4 additions & 2 deletions core/modules/wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,8 @@ 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);
story.addToHistory(title,fromPageRect);
console.log("$tw.wiki.addToHistory() is deprecated since V5.1.23! Use the this.story.addToHistory() from the story-object!")
};

/*
Expand All @@ -1438,7 +1439,8 @@ 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);
story.addToStory(title,fromTitle,options);
console.log("$tw.wiki.addToStory() is deprecated since V5.1.23! Use the this.story.addToStory() from the story-object!")
};

/*
Expand Down

0 comments on commit d5c4aa2

Please sign in to comment.