1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-08 10:59:57 +00:00
TiddlyWiki5/js/macros/link.js
Jeremy Ruston 58ab36ef51 Refactored navigation to use new macro event mechanism
Phew. This gets rid of a lot of hacks
2012-02-02 18:00:42 +00:00

44 lines
907 B
JavaScript

/*\
title: js/macros/link.js
\*/
(function(){
/*jslint node: true, browser: true */
"use strict";
var utils = require("../Utils.js");
exports.macro = {
name: "link",
wrapperTag: "span",
types: ["text/html","text/plain"],
params: {
target: {byName: "default", type: "tiddler", optional: false}
},
events: {
click: function(event,node,tiddler,store,params) {
var navEvent = document.createEvent("Event");
navEvent.initEvent("tw-navigate",true,true);
navEvent.navigateTo = params.target;
node.dispatchEvent(navEvent);
event.preventDefault();
return false;
}
},
render: function(type,tiddler,store,params,content) {
if(type === "text/html") {
return utils.stitchElement("a",{
href: params.target
},{
content: content,
classes: store.adjustClassesForLink([],params.target)
});
} else if (type === "text/plain") {
return content;
}
}
};
})();