Start adding support for permalinks

At this point we respect any permalink at startup, but we don’t yet
dynamically update the permalink, nor do we respond to ongoing
permalink changes.

The permalink separator being `%00` seems like it might be a bit
controversial. It buys us not having to wrap tiddler titles in double
square brackets if they contain spaces.

Another thing is that this scheme doesn’t support tiddler filters; the
plan is to support them like this:

http://tiddlywiki.com/#!Target%00%00[tag[task]sort[created]]
print-window-tiddler
Jermolene 2014-05-02 19:21:32 +01:00
rodzic cb914ae853
commit 327b53a641
5 zmienionych plików z 109 dodań i 22 usunięć

Wyświetl plik

@ -1621,8 +1621,15 @@ readBrowserTiddlers: whether to read tiddlers from the HTML file we're executing
*/
$tw.boot.startup = function(options) {
options = options || {};
// Check for safe mode
$tw.safeMode = $tw.browser && location.hash === "#:safe";
// Get the URL hash and check for safe mode
$tw.locationHash = "#";
if($tw.browser) {
if(location.hash === "#:safe") {
$tw.safeMode = true;
} else {
$tw.locationHash = location.hash;
}
}
// Initialise some more $tw properties
$tw.utils.deepDefaults($tw,{
modules: { // Information about each module

Wyświetl plik

@ -18,6 +18,14 @@ var PERFORMANCE_INSTRUMENTATION = false;
// Time (in ms) that we defer refreshing changes to draft tiddlers
var DRAFT_TIDDLER_TIMEOUT = 400;
// Default story and history lists
var DEFAULT_STORY_TITLE = "$:/StoryList";
var DEFAULT_HISTORY_TITLE = "$:/HistoryList";
// Default tiddlers
var DEFAULT_TIDDLERS_TITLE = "$:/DefaultTiddlers";
var widget = require("$:/core/modules/widgets/widget.js");
exports.startup = function() {
@ -64,26 +72,37 @@ exports.startup = function() {
"$:/themes/tiddlywiki/vanilla"
]
});
// Display the default tiddlers
var displayDefaultTiddlers = function() {
// Get the default tiddlers
var defaultTiddlersTitle = "$:/DefaultTiddlers",
defaultTiddlersTiddler = $tw.wiki.getTiddler(defaultTiddlersTitle),
defaultTiddlers = [];
if(defaultTiddlersTiddler) {
defaultTiddlers = $tw.wiki.filterTiddlers(defaultTiddlersTiddler.fields.text);
}
// Initialise the story
var storyTitle = "$:/StoryList",
story = [];
for(var t=0; t<defaultTiddlers.length; t++) {
story[t] = defaultTiddlers[t];
}
$tw.wiki.addTiddler({title: storyTitle, text: "", list: story},$tw.wiki.getModificationFields());
};
displayDefaultTiddlers();
// Clear outstanding tiddler store change events to avoid an unnecessary refresh cycle at startup
$tw.wiki.clearTiddlerEventQueue();
// Decode the hash portion of our URL
var parts = [];
if($tw.locationHash.charAt(1) === "!") {
parts = decodeURIComponent($tw.locationHash.substr(2)).split("\u0000")
}
if(parts[0]) {
// Set the history
var historyList = [{title: parts[0]}];
$tw.wiki.setTiddlerData(DEFAULT_HISTORY_TITLE, historyList, {"current-tiddler": parts[0]});
// Set the story
var story = [];
for(var t=1; t<parts.length; t++) {
if(parts[t]) {
story.push(parts[t]);
}
}
// If the story is empty use the default tiddlers
if(story.length === 0) {
story = getDefaultTiddlers();
}
// If the target tiddler isn't included then splice it in at the top
if(story.indexOf(parts[0]) === -1) {
story.unshift(parts[0]);
}
$tw.wiki.addTiddler({title: DEFAULT_STORY_TITLE, text: "", list: story},$tw.wiki.getModificationFields());
} else {
// Display the default tiddlers if the hash portion was empty
displayDefaultTiddlers();
}
// Set up the syncer object
$tw.syncer = new $tw.Syncer({wiki: $tw.wiki});
// Host-specific startup
@ -248,6 +267,34 @@ exports.startup = function() {
};
/*
Helper to display the default tiddlers
*/
function displayDefaultTiddlers() {
// Get the default tiddlers
var defaultTiddlersTitle = "$:/DefaultTiddlers",
defaultTiddlersTiddler = $tw.wiki.getTiddler(defaultTiddlersTitle),
defaultTiddlers = [];
if(defaultTiddlersTiddler) {
defaultTiddlers = $tw.wiki.filterTiddlers(defaultTiddlersTiddler.fields.text);
}
// Initialise the story
var story = [];
for(var t=0; t<defaultTiddlers.length; t++) {
story[t] = defaultTiddlers[t];
}
$tw.wiki.addTiddler({title: DEFAULT_STORY_TITLE, text: "", list: story},$tw.wiki.getModificationFields());
}
function getDefaultTiddlers() {
var defaultTiddlersTiddler = $tw.wiki.getTiddler(DEFAULT_TIDDLERS_TITLE),
defaultTiddlers = [];
if(defaultTiddlersTiddler) {
defaultTiddlers = $tw.wiki.filterTiddlers(defaultTiddlersTiddler.fields.text);
}
return defaultTiddlers;
}
/*
Main render function for PageMacros, which includes the PageTemplate
*/

Wyświetl plik

@ -15,10 +15,16 @@ Zooms between individual tiddlers
var ZoominListView = function(listWidget) {
var self = this;
this.listWidget = listWidget;
// Make all the tiddlers position absolute, and hide all but the first one
// Get the index of the tiddler that is at the top of the history
var history = this.listWidget.wiki.getTiddlerData(this.listWidget.historyTitle,[]),
targetTiddler;
if(history.length > 0) {
targetTiddler = history[history.length-1].title;
}
// Make all the tiddlers position absolute, and hide all but the top (or first) one
$tw.utils.each(this.listWidget.children,function(itemWidget,index) {
var domNode = itemWidget.findFirstDomNode();
if(index) {
if(targetTiddler !== itemWidget.parseTreeNode.itemTitle || (!targetTiddler && index)) {
domNode.style.display = "none";
} else {
self.currentTiddlerDomNode = domNode;

Wyświetl plik

@ -18,6 +18,7 @@ See [[Notes for upgrading to 5.0.11-beta]] for more details of these changes:
!! Usability Improvements
* Added support for PermaLinks and browser navigation buttons
* [[Replaced|https://github.com/Jermolene/TiddlyWiki5/issues/580]] hamburger menu icon with double chevron icon
* [[Enhance|https://github.com/Jermolene/TiddlyWiki5/commit/552657fc584dbb36754d3fcabca2cdef7e916ec9]] plain text parsing to use the CodeBlockWidget, and hence use syntax highlighting if the plugin is installed. This gives us syntax highlighting for JavaScript shadow tiddlers, amongst other things
* Improvements to Chinese, Japanese and French translations

Wyświetl plik

@ -0,0 +1,26 @@
created: 20140502213500000
modified: 20140502213500000
tags: concepts
title: PermaLinks
type: text/vnd.tiddlywiki
Permalinks allow direct links to individual tiddlers within a TiddlyWiki.
The simplest form of permalink is a single target tiddler title appended to the base URL with "#!":
http://tiddlywiki.com/#!HelloThere
The tiddler title can contain spaces if required:
[[http://tiddlywiki.com/#!Using TiddlyWiki on Node.js]]
The permalink can also specify the story list of tiddlers that should be opened alongside the target tiddler. The tiddler titles are separated by `%00`:
http://tiddlywiki.com/#!Tiddlers%00Tags%00TiddlerFields%00Tiddlers
In this form, the first tiddler title is taken to be the target tiddler, and the remaining titles give the sequence of tiddlers in the story list.
If the target tiddler isn't present in the story list then it is automatically inserted at the top. This means that the following two examples both target the tiddler `Tiddlers` within the story sequence `Tiddlers`, `Tags`, `TiddlerFields`:
http://tiddlywiki.com/#!Tiddlers%00Tags%00TiddlerFields
http://tiddlywiki.com/#!Tiddlers%00Tiddlers%00Tags%00TiddlerFields