Skip to content

Commit

Permalink
More permalink tweaks
Browse files Browse the repository at this point in the history
And more documentation this time!
  • Loading branch information
Jermolene committed May 29, 2014
1 parent 412cde6 commit 3f25db0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 8 additions & 3 deletions core/modules/startup/story.js
Expand Up @@ -61,8 +61,8 @@ defaultToCurrentStory: If true, the current story is retained as the default, in
*/
function openStartupTiddlers(options) {
options = options || {};
// Decode the hash portion of our URL
var target,
// Work out the target tiddler and the story filter. "null" means "unspecified"
var target = null,
storyFilter = null;
if($tw.locationHash.length > 1) {
var hash = $tw.locationHash.substr(1),
Expand All @@ -80,9 +80,14 @@ function openStartupTiddlers(options) {
var currStoryList = $tw.wiki.getTiddlerList(DEFAULT_STORY_TITLE);
storyFilter = $tw.utils.stringifyList(currStoryList);
} else {
storyFilter = "";
if(target && target !== "") {
storyFilter = "";
} else {
storyFilter = $tw.wiki.getTiddlerText(DEFAULT_TIDDLERS_TITLE);
}
}
}
// Process the story filter to get the story list
var storyList = $tw.wiki.filterTiddlers(storyFilter);
// If the target tiddler isn't included then splice it in at the top
if(target && storyList.indexOf(target) === -1) {
Expand Down
12 changes: 12 additions & 0 deletions editions/tw5.com/tiddlers/concepts/PermaLinks.tid
Expand Up @@ -48,3 +48,15 @@ Two important aspects of TiddlyWiki's behaviour with permalinks can be controlle
* Whether the updates to the address bar should affect browser history. The default is ''no''; when switched to ''yes'' you can rewind navigation between tiddlers using the browser back and forward buttons

Note that typing or navigating to a permalink will always cause the permalink to be processed, and tiddlers opened and closed as appropriate.

!! Technical Details

When TiddlyWiki starts up it processes permalinks according to the following steps; the same steps are repeated if the permalink changes dynamically (this happens in response to the user editing the address bar, for example).

# If the permalink contains a colon, treat the string before as the ''target'' and the string after it as the ''story filter''
# If the permalink doesn't contain a colon, treat the entire string as the ''target'' and mark the ''story filter'' as //unspecified//
# If the ''story filter'' was unspecified and we're in the process of starting up, then set the ''story filter'' to the empty string if the ''target'' is specified, or to the default tiddlers if the ''target'' is unspecified
# If the ''story filter'' was unspecified and we're not starting up, then set the ''story filter'' to the current story list
# Evaluate the ''story filter'' as the ''story list''
# If the ''target'' is specified and not present in the ''story list'' then add it at the top
# If the ''target'' is specified then navigate to it, otherwise navigate to the first tiddler in the ''story list''

0 comments on commit 3f25db0

Please sign in to comment.