1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Added skeleton browser support for navigating between tiddlers

This commit is contained in:
Jeremy Ruston 2011-12-13 16:20:56 +00:00
parent 5383368b51
commit 364d891ca6
4 changed files with 102 additions and 4 deletions

View File

@ -15,7 +15,9 @@ var WikiStore = require("./WikiStore.js").WikiStore,
tiddlerOutput = require("./TiddlerOutput.js"), tiddlerOutput = require("./TiddlerOutput.js"),
TextProcessors = require("./TextProcessors.js").TextProcessors, TextProcessors = require("./TextProcessors.js").TextProcessors,
WikiTextProcessor = require("./WikiTextProcessor.js").WikiTextProcessor, WikiTextProcessor = require("./WikiTextProcessor.js").WikiTextProcessor,
TiddlerConverters = require("./TiddlerConverters.js").TiddlerConverters; TiddlerConverters = require("./TiddlerConverters.js").TiddlerConverters,
Navigators = require("./Navigators.js").Navigators,
StoryNavigator = require("./StoryNavigator.js").StoryNavigator;
var textProcessors = new TextProcessors(), var textProcessors = new TextProcessors(),
tiddlerConverters = new TiddlerConverters(), tiddlerConverters = new TiddlerConverters(),
@ -76,7 +78,17 @@ for(t=0; t<tiddlers.length; t++) {
store.addTiddler(new Tiddler(tiddlers[t])); store.addTiddler(new Tiddler(tiddlers[t]));
} }
// Render HelloThere // Install the standard navigators
$("<div/>").html(store.renderTiddler("text/html","HelloThere")).appendTo("body"); var navigators = new Navigators({
document: document,
store: store
});
})(); navigators.registerNavigator("StoryNavigator",new StoryNavigator(navigators));
// Use the story navigator for all links
navigators.install("a","StoryNavigator");
// Navigate to HelloThere
navigators.navigateTo("HelloThere","StoryNavigator");
})();

56
js/Navigators.js Normal file
View File

@ -0,0 +1,56 @@
/*\
title: js/Navigators.js
This browser component manages the available navigators that handle clicking on links to tiddlers.
\*/
(function(){
/*jslint node: true */
"use strict";
var util = require("util");
/*
Options hashmap has mandatory members:
document: the DOM document to use
store: the wiki store to use
*/
var Navigators = function(options) {
this.document = options.document;
this.store = options.store;
this.navigators = {};
};
Navigators.prototype.registerNavigator = function(name,nav) {
this.navigators[name] = nav;
};
Navigators.prototype.install = function(selector,navname) {
var nav = this.navigators[navname];
this.document.addEventListener("click",function(e) {
var el = e.target,
matchesSelector = el.matchesSelector || el.mozMatchesSelector ||
el.webkitMatchesSelector || el.oMatchesSelector || el.msMatchesSelector
if(matchesSelector && matchesSelector.call(el,selector)) {
var r = nav.navigateTo(el.getAttribute("href"));
if(!r) {
e.preventDefault();
} else {
el.setAttribute("target","_blank");
}
return r;
}
},false);
};
Navigators.prototype.navigateTo = function(title,navname) {
var nav = this.navigators[navname];
if(nav) {
nav.navigateTo(title);
}
};
exports.Navigators = Navigators;
})();

28
js/StoryNavigator.js Normal file
View File

@ -0,0 +1,28 @@
/*\
title: js/StoryNavigator.js
This browser component manages navigating to new tiddlers in a TiddlyWiki classic story style
\*/
(function(){
/*jslint node: true */
"use strict";
var StoryNavigator = function(navigators) {
this.navigators = navigators;
}
StoryNavigator.prototype.navigateTo = function(title) {
var tiddlerHtml = this.navigators.store.renderTiddler("text/html",title);
if(tiddlerHtml) {
$("<div/>").html(tiddlerHtml).appendTo("body");
return false;
} else {
return true;
}
}
exports.StoryNavigator = StoryNavigator;
})();

View File

@ -16,6 +16,8 @@ jsmodule: ../js/WikiTextProcessor.js
jsmodule: ../js/WikiTextParser.js jsmodule: ../js/WikiTextParser.js
jsmodule: ../js/WikiTextRules.js jsmodule: ../js/WikiTextRules.js
jsmodule: ../js/WikiTextRenderer.js jsmodule: ../js/WikiTextRenderer.js
jsmodule: ../js/Navigators.js
jsmodule: ../js/StoryNavigator.js
jsmodule: ../js/Main.js jsmodule: ../js/Main.js
jsbootstart: BootStart.js jsbootstart: BootStart.js