mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-07-07 12:34:22 +00:00
![Jeremy Ruston](/assets/img/avatar_default.png)
Not done yet, but the tests are passing so it's a good point to check in. The idea is to let macros register for events to handle both the click and the navigation request.
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
/*\
|
|
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(event) {
|
|
var el = event.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"),event);
|
|
if(!r) {
|
|
event.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;
|
|
|
|
})();
|