1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-07 22:33:50 +00:00

Renamed "target" parameter of link macro to "to"

To avoid confusion with the HTML target attribute of link elements
This commit is contained in:
Jeremy Ruston 2012-04-07 11:32:41 +01:00
parent 9e4404bb97
commit 5d10e7b750
4 changed files with 16 additions and 16 deletions

View File

@ -102,7 +102,7 @@ var App = function() {
// Install the default link massager // Install the default link massager
this.store.linkMassager = function(linkInfo) { this.store.linkMassager = function(linkInfo) {
if(!linkInfo.isExternal) { if(!linkInfo.isExternal) {
linkInfo.target = encodeURIComponent(linkInfo.target); linkInfo.to = encodeURIComponent(linkInfo.to);
} }
}; };
// Set up for the browser // Set up for the browser

View File

@ -467,7 +467,7 @@ var rules = [
// Pretty bracketted link // Pretty bracketted link
link = lookaheadMatch[3]; link = lookaheadMatch[3];
} }
insertMacroCall(w,w.output,"link",{target: link},[Renderer.TextNode(text)]); insertMacroCall(w,w.output,"link",{to: link},[Renderer.TextNode(text)]);
w.nextMatch = this.lookaheadRegExp.lastIndex; w.nextMatch = this.lookaheadRegExp.lastIndex;
} }
} }
@ -492,7 +492,7 @@ var rules = [
} }
} }
if(w.autoLinkWikiWords) { if(w.autoLinkWikiWords) {
insertMacroCall(w,w.output,"link",{target: w.matchText},[Renderer.TextNode(w.source.substring(w.matchStart,w.nextMatch))]); insertMacroCall(w,w.output,"link",{to: w.matchText},[Renderer.TextNode(w.source.substring(w.matchStart,w.nextMatch))]);
} else { } else {
w.outputText(w.output,w.matchStart,w.nextMatch); w.outputText(w.output,w.matchStart,w.nextMatch);
} }
@ -504,7 +504,7 @@ var rules = [
match: textPrimitives.urlPattern, match: textPrimitives.urlPattern,
handler: function(w) handler: function(w)
{ {
insertMacroCall(w,w.output,"link",{target: w.matchText},[Renderer.TextNode(w.source.substring(w.matchStart,w.nextMatch))]); insertMacroCall(w,w.output,"link",{to: w.matchText},[Renderer.TextNode(w.source.substring(w.matchStart,w.nextMatch))]);
} }
}, },

View File

@ -10,7 +10,7 @@ that takes a `linkInfo` structure as the only parameter. It contains a hashmap o
as follows: as follows:
{ {
target: the target of the link to: the target of the link
space: an optional space associated with 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 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 isMissing: true if a non-external link references a missing tiddler
@ -28,26 +28,26 @@ The linkMassager can modify the `classes` and `href` fields as required.
var Renderer = require("../Renderer.js").Renderer; var Renderer = require("../Renderer.js").Renderer;
var isLinkExternal = function(target) { var isLinkExternal = function(to) {
var externalRegExp = /(?:file|http|https|mailto|ftp|irc|news|data):[^\s'"]+(?:\/|\b)/i; var externalRegExp = /(?:file|http|https|mailto|ftp|irc|news|data):[^\s'"]+(?:\/|\b)/i;
return externalRegExp.test(target); return externalRegExp.test(to);
}; };
exports.macro = { exports.macro = {
name: "link", name: "link",
params: { params: {
target: {byName: "default", type: "tiddler", skinny: true}, to: {byName: "default", type: "tiddler", skinny: true},
space: {byName: true, type: "text"} space: {byName: true, type: "text"}
}, },
events: { events: {
click: function(event) { click: function(event) {
if(isLinkExternal(this.params.target)) { if(isLinkExternal(this.params.to)) {
event.target.setAttribute("target","_blank"); event.target.setAttribute("target","_blank");
return true; return true;
} else { } else {
var navEvent = document.createEvent("Event"); var navEvent = document.createEvent("Event");
navEvent.initEvent("tw-navigate",true,true); navEvent.initEvent("tw-navigate",true,true);
navEvent.navigateTo = this.params.target; navEvent.navigateTo = this.params.to;
event.target.dispatchEvent(navEvent); event.target.dispatchEvent(navEvent);
event.preventDefault(); event.preventDefault();
return false; return false;
@ -57,15 +57,15 @@ exports.macro = {
execute: function() { execute: function() {
// Assemble the information about the link // Assemble the information about the link
var linkInfo = { var linkInfo = {
target: this.params.target, to: this.params.to,
space: this.params.space space: this.params.space
}; };
// Generate the default link characteristics // Generate the default link characteristics
linkInfo.isExternal = isLinkExternal(linkInfo.target); linkInfo.isExternal = isLinkExternal(linkInfo.to);
if(!linkInfo.isExternal) { if(!linkInfo.isExternal) {
linkInfo.isMissing = !this.store.tiddlerExists(linkInfo.target); linkInfo.isMissing = !this.store.tiddlerExists(linkInfo.to);
} }
linkInfo.href = encodeURIComponent(linkInfo.target); linkInfo.href = encodeURIComponent(linkInfo.to);
// Generate the default classes for the link // Generate the default classes for the link
linkInfo.classes = ["tw-tiddlylink"]; linkInfo.classes = ["tw-tiddlylink"];
if(linkInfo.isExternal) { if(linkInfo.isExternal) {
@ -85,7 +85,7 @@ exports.macro = {
// Figure out the classes to assign to the link // Figure out the classes to assign to the link
var content = [Renderer.ElementNode( var content = [Renderer.ElementNode(
"a",{ "a",{
href: linkInfo.target, href: linkInfo.href,
"class": linkInfo.classes "class": linkInfo.classes
},this.cloneChildren())]; },this.cloneChildren())];
for(var t=0; t<content.length; t++) { for(var t=0; t<content.length; t++) {

View File

@ -52,7 +52,7 @@ exports.macro = {
return []; return [];
} else { } else {
var link = Renderer.MacroNode("link", var link = Renderer.MacroNode("link",
{target: value}, {to: value},
[Renderer.TextNode(value)], [Renderer.TextNode(value)],
this.store); this.store);
link.execute(parents,this.tiddlerTitle); link.execute(parents,this.tiddlerTitle);