mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-28 04:19:56 +00:00
Added linkMassager callback
This commit is contained in:
parent
b44f6b47cc
commit
d13e2bacaf
@ -96,6 +96,12 @@ var App = function() {
|
|||||||
this.store.installMacro(require("./macros/video.js").macro);
|
this.store.installMacro(require("./macros/video.js").macro);
|
||||||
this.store.installMacro(require("./macros/view.js").macro);
|
this.store.installMacro(require("./macros/view.js").macro);
|
||||||
this.store.installMacro(require("./macros/zoomer.js").macro);
|
this.store.installMacro(require("./macros/zoomer.js").macro);
|
||||||
|
// Install the default link massager
|
||||||
|
this.store.linkMassager = function(linkInfo) {
|
||||||
|
if(!linkInfo.isExternal) {
|
||||||
|
linkInfo.target = encodeURIComponent(linkInfo.target);
|
||||||
|
}
|
||||||
|
};
|
||||||
// Set up navigation if we're in the browser
|
// Set up navigation if we're in the browser
|
||||||
if(this.isBrowser) {
|
if(this.isBrowser) {
|
||||||
// Open the PageTemplate
|
// Open the PageTemplate
|
||||||
|
@ -1,6 +1,25 @@
|
|||||||
/*\
|
/*\
|
||||||
title: js/macros/link.js
|
title: js/macros/link.js
|
||||||
|
|
||||||
|
Implements the link macro.
|
||||||
|
|
||||||
|
A special callback function is used to massage links according to the needs of the host platform.
|
||||||
|
|
||||||
|
The linkMassager is stored in the `linkMassager` property of the store object. It is a function
|
||||||
|
that takes a `linkInfo` structure as the only parameter. It contains a hashmap of information
|
||||||
|
as follows:
|
||||||
|
|
||||||
|
{
|
||||||
|
target: the target of the link
|
||||||
|
space: an optional space associated with the link
|
||||||
|
isExternal: true if the link has been determined to be an external link by the default heuristics
|
||||||
|
isMissing: true if a non-external link references a missing tiddler
|
||||||
|
classes: an array of strings representing the CSS classes to be applied to the link. The default classes are already applied
|
||||||
|
href: the href to be used in the link
|
||||||
|
}
|
||||||
|
|
||||||
|
The linkMassager can modify the `classes` and `href` fields as required.
|
||||||
|
|
||||||
\*/
|
\*/
|
||||||
(function(){
|
(function(){
|
||||||
|
|
||||||
@ -17,7 +36,8 @@ var isLinkExternal = function(target) {
|
|||||||
exports.macro = {
|
exports.macro = {
|
||||||
name: "link",
|
name: "link",
|
||||||
params: {
|
params: {
|
||||||
target: {byName: "default", type: "tiddler", skinny: true}
|
target: {byName: "default", type: "tiddler", skinny: true},
|
||||||
|
space: {byName: true, type: "text"}
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
click: function(event) {
|
click: function(event) {
|
||||||
@ -35,23 +55,38 @@ exports.macro = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
execute: function() {
|
execute: function() {
|
||||||
var classes = ["tw-tiddlylink"],
|
// Assemble the information about the link
|
||||||
target = this.params.target;
|
var linkInfo = {
|
||||||
if(isLinkExternal(target)) {
|
target: this.params.target,
|
||||||
classes.push("tw-tiddlylink-external");
|
space: this.params.space
|
||||||
} else {
|
};
|
||||||
classes.push("tw-tiddlylink-internal");
|
// Generate the default link characteristics
|
||||||
if(this.store.tiddlerExists(target)) {
|
linkInfo.isExternal = isLinkExternal(linkInfo.target);
|
||||||
classes.push("tw-tiddlylink-resolves");
|
if(!linkInfo.isExternal) {
|
||||||
} else {
|
linkInfo.isMissing = !this.store.tiddlerExists(linkInfo.target);
|
||||||
classes.push("tw-tiddlylink-missing");
|
|
||||||
}
|
}
|
||||||
target = encodeURIComponent(target);
|
linkInfo.href = encodeURIComponent(linkInfo.target);
|
||||||
|
// Generate the default classes for the link
|
||||||
|
linkInfo.classes = ["tw-tiddlylink"];
|
||||||
|
if(linkInfo.isExternal) {
|
||||||
|
linkInfo.classes.push("tw-tiddlylink-external");
|
||||||
|
} else {
|
||||||
|
linkInfo.classes.push("tw-tiddlylink-internal");
|
||||||
|
if(linkInfo.isMissing) {
|
||||||
|
linkInfo.classes.push("tw-tiddlylink-missing");
|
||||||
|
} else {
|
||||||
|
linkInfo.classes.push("tw-tiddlylink-resolves");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// Invoke the link massager if defined
|
||||||
|
if(this.store.linkMassager) {
|
||||||
|
this.store.linkMassager(linkInfo);
|
||||||
|
}
|
||||||
|
// Figure out the classes to assign to the link
|
||||||
var content = [Renderer.ElementNode(
|
var content = [Renderer.ElementNode(
|
||||||
"a",{
|
"a",{
|
||||||
href: target,
|
href: linkInfo.target,
|
||||||
"class": classes
|
"class": linkInfo.classes
|
||||||
},this.cloneChildren())];
|
},this.cloneChildren())];
|
||||||
for(var t=0; t<content.length; t++) {
|
for(var t=0; t<content.length; t++) {
|
||||||
content[t].execute(this.parents,this.tiddlerTitle);
|
content[t].execute(this.parents,this.tiddlerTitle);
|
||||||
|
Loading…
Reference in New Issue
Block a user