1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-10 11:59:58 +00:00

Make permalink behaviour configurable

In the process introducing a new advanced settings tab

Fixes #600
This commit is contained in:
Jermolene 2014-05-13 14:16:58 +01:00
parent 4e07b3335b
commit ad43958571
7 changed files with 133 additions and 18 deletions

View File

@ -4,6 +4,17 @@ Advanced/Caption: Advanced
Advanced/Hint: Internal information about this TiddlyWiki Advanced/Hint: Internal information about this TiddlyWiki
Advanced/LoadedModules/Caption: Loaded Modules Advanced/LoadedModules/Caption: Loaded Modules
Advanced/LoadedModules/Hint: These are the currently loaded tiddler modules linked to their source tiddlers. Any italicised modules lack a source tiddler, typically because they were setup during the boot process. Advanced/LoadedModules/Hint: These are the currently loaded tiddler modules linked to their source tiddlers. Any italicised modules lack a source tiddler, typically because they were setup during the boot process.
Advanced/Settings/Caption: Settings
Advanced/Settings/Hint: These advanced settings let you customise the behaviour of TiddlyWiki.
Advanced/Settings/NavigationAddressBar/Caption: Navigation Address Bar
Advanced/Settings/NavigationAddressBar/Hint: Behaviour of the browser address bar when navigating to a tiddler:
Advanced/Settings/NavigationAddressBar/No/Description: Do not update the address bar
Advanced/Settings/NavigationAddressBar/Permalink/Description: Include the target tiddler
Advanced/Settings/NavigationAddressBar/Permaview/Description: Include the target tiddler and the current story sequence
Advanced/Settings/NavigationHistory/Caption: Navigation History
Advanced/Settings/NavigationHistory/Hint: Update browser history when navigating to a tiddler:
Advanced/Settings/NavigationHistory/No/Description: Do not update history
Advanced/Settings/NavigationHistory/Yes/Description: Update history
Advanced/TiddlerFields/Caption: Tiddler Fields Advanced/TiddlerFields/Caption: Tiddler Fields
Advanced/TiddlerFields/Hint: This is the full set of TiddlerFields in use in this wiki (including system tiddlers but excluding shadow tiddlers). Advanced/TiddlerFields/Hint: This is the full set of TiddlerFields in use in this wiki (including system tiddlers but excluding shadow tiddlers).
Appearance/Caption: Appearance Appearance/Caption: Appearance

View File

@ -24,6 +24,10 @@ var DEFAULT_HISTORY_TITLE = "$:/HistoryList";
// Default tiddlers // Default tiddlers
var DEFAULT_TIDDLERS_TITLE = "$:/DefaultTiddlers"; var DEFAULT_TIDDLERS_TITLE = "$:/DefaultTiddlers";
// Config
var CONFIG_UPDATE_ADDRESS_BAR = "$:/config/Navigation/UpdateAddressBar"; // Can be "no", "permalink", "permaview"
var CONFIG_UPDATE_HISTORY = "$:/config/Navigation/UpdateHistory"; // Can be "yes" or "no"
exports.startup = function() { exports.startup = function() {
// Open startup tiddlers // Open startup tiddlers
openStartupTiddlers(); openStartupTiddlers();
@ -97,24 +101,36 @@ function openStartupTiddlers(options) {
} }
function updateLocationHash() { function updateLocationHash() {
// Get the story and the history stack var updateAddressBar = $tw.wiki.getTiddlerText(CONFIG_UPDATE_ADDRESS_BAR,"permaview").trim();
var storyList = $tw.wiki.getTiddlerList(DEFAULT_STORY_TITLE), if(updateAddressBar !== "no") {
historyList = $tw.wiki.getTiddlerData(DEFAULT_HISTORY_TITLE,[]); // Get the story and the history stack
var targetTiddler = ""; var storyList = $tw.wiki.getTiddlerList(DEFAULT_STORY_TITLE),
// The target tiddler is the one at the top of the stack historyList = $tw.wiki.getTiddlerData(DEFAULT_HISTORY_TITLE,[]);
if(historyList.length > 0) { var targetTiddler = "";
targetTiddler = historyList[historyList.length-1].title; // The target tiddler is the one at the top of the stack
} if(historyList.length > 0) {
// Blank the target tiddler if it isn't present in the story targetTiddler = historyList[historyList.length-1].title;
if(storyList.indexOf(targetTiddler) === -1) { }
targetTiddler = ""; // Blank the target tiddler if it isn't present in the story
} if(storyList.indexOf(targetTiddler) === -1) {
// Assemble the location hash targetTiddler = "";
$tw.locationHash = "#" + encodeURIComponent(targetTiddler) + ":" + encodeURIComponent($tw.utils.stringifyList(storyList)); }
// Only change the location hash if we must, thus avoiding unnecessary onhashchange events // Assemble the location hash
if($tw.utils.getLocationHash() !== $tw.locationHash) { if(updateAddressBar === "permalink") {
// We use replace so that browser history isn't affected $tw.locationHash = "#" + encodeURIComponent(targetTiddler)
window.location.replace(window.location.toString().split("#")[0] + $tw.locationHash); } else {
$tw.locationHash = "#" + encodeURIComponent(targetTiddler) + ":" + encodeURIComponent($tw.utils.stringifyList(storyList));
}
// Only change the location hash if we must, thus avoiding unnecessary onhashchange events
if($tw.utils.getLocationHash() !== $tw.locationHash) {
if($tw.wiki.getTiddlerText(CONFIG_UPDATE_HISTORY,"no").trim() === "yes") {
// Assign the location hash so that history is updated
window.location.hash = $tw.locationHash;
} else {
// We use replace so that browser history isn't affected
window.location.replace(window.location.toString().split("#")[0] + $tw.locationHash);
}
}
} }
} }

View File

@ -0,0 +1,19 @@
title: $:/core/ui/ControlPanel/Advanced/Settings
tags: $:/tags/ControlPanel/Advanced
caption: {{$:/language/ControlPanel/Advanced/Settings/Caption}}
\define lingo-base() $:/language/ControlPanel/Advanced/Settings/
<<lingo Hint>>
<$list filter="[all[shadows+tiddlers]tag[$:/tags/ControlPanel/Advanced/Settings]]">
<div style="border-top:1px solid #eee;">
!! <$link><$transclude field="caption"/></$link>
<$transclude/>
</div>
</$list>

View File

@ -0,0 +1,34 @@
title: $:/core/ui/ControlPanel/Advanced/Settings/NavigationAddressBar
tags: $:/tags/ControlPanel/Advanced/Settings
caption: {{$:/language/ControlPanel/Advanced/Settings/NavigationAddressBar/Caption}}
\define lingo-base() $:/language/ControlPanel/Advanced/Settings/NavigationAddressBar/
<<lingo Hint>>
<div style="position:relative;">
<$button popup=<<qualify "$:/state/navaddressbarpopup">> class="btn-invisible btn-dropdown">
<$view tiddler="$:/config/Navigation/UpdateAddressBar" field="text"/>:
<$reveal state="$:/config/Navigation/UpdateAddressBar" type="match" text="no">
''<<lingo No/Description>>''
</$reveal>
<$reveal state="$:/config/Navigation/UpdateAddressBar" type="match" text="permalink">
''<<lingo Permalink/Description>>''
</$reveal>
<$reveal state="$:/config/Navigation/UpdateAddressBar" type="match" text="permaview">
''<<lingo Permaview/Description>>''
</$reveal>
{{$:/core/images/down-arrow}}
</$button>
<div class="tw-block-dropdown-wrapper">
<$reveal state=<<qualify "$:/state/navaddressbarpopup">> type="popup" position="below" animate="yes" default="">
<$linkcatcher to="$:/config/Navigation/UpdateAddressBar">
<div class="tw-block-dropdown tw-edit-type-dropdown">
<$list filter="no permalink permaview">
<$link to={{!!title}}>
<$view field="title"/>
</$link>
</$list>
</div>
</$linkcatcher>
</$reveal>
</div>
</div>

View File

@ -0,0 +1,31 @@
title: $:/core/ui/ControlPanel/Advanced/Settings/NavigationHistory
tags: $:/tags/ControlPanel/Advanced/Settings
caption: {{$:/language/ControlPanel/Advanced/Settings/NavigationHistory/Caption}}
\define lingo-base() $:/language/ControlPanel/Advanced/Settings/NavigationHistory/
<<lingo Hint>>
<div style="position:relative;">
<$button popup=<<qualify "$:/state/navhistorypopup">> class="btn-invisible btn-dropdown">
<$view tiddler="$:/config/Navigation/UpdateHistory" field="text"/>:
<$reveal state="$:/config/Navigation/UpdateHistory" type="match" text="no">
''<<lingo No/Description>>''
</$reveal>
<$reveal state="$:/config/Navigation/UpdateHistory" type="match" text="yes">
''<<lingo Yes/Description>>''
</$reveal>
{{$:/core/images/down-arrow}}
</$button>
<div class="tw-block-dropdown-wrapper">
<$reveal state=<<qualify "$:/state/navhistorypopup">> type="popup" position="below" animate="yes" default="">
<$linkcatcher to="$:/config/Navigation/UpdateHistory">
<div class="tw-block-dropdown tw-edit-type-dropdown">
<$list filter="no yes">
<$link to={{!!title}}>
<$view field="title"/>
</$link>
</$list>
</div>
</$linkcatcher>
</$reveal>
</div>
</div>

View File

@ -0,0 +1,2 @@
title: $:/config/Navigation/UpdateAddressBar
text: permaview

View File

@ -0,0 +1,2 @@
title: $:/config/Navigation/UpdateHistory
text: no