1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-11 18:00:26 +00:00

Optimise link widget

Handle the classes better, and stop using a default tooltip (parsing
the tooltip was a performance hog)
This commit is contained in:
Jermolene 2014-04-05 17:37:58 +01:00
parent 272a4bbe61
commit 4d91a7762e

View File

@ -56,17 +56,18 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
// Create our element // Create our element
var domNode = this.document.createElement("a"); var domNode = this.document.createElement("a");
// Assign classes // Assign classes
$tw.utils.addClass(domNode,"tw-tiddlylink"); var classes = ["tw-tiddlylink"];
if(this.isShadow) { if(this.isShadow) {
$tw.utils.addClass(domNode,"tw-tiddlylink-shadow"); classes.push("tw-tiddlylink-shadow");
} }
if(this.isMissing && !this.isShadow) { if(this.isMissing && !this.isShadow) {
$tw.utils.addClass(domNode,"tw-tiddlylink-missing"); classes.push("tw-tiddlylink-missing");
} else { } else {
if(!this.isMissing) { if(!this.isMissing) {
$tw.utils.addClass(domNode,"tw-tiddlylink-resolves"); classes.push("tw-tiddlylink-resolves");
} }
} }
domNode.setAttribute("class",classes.join(" "));
// Set an href // Set an href
var wikiLinkTemplateMacro = this.getVariable("tw-wikilink-template"), var wikiLinkTemplateMacro = this.getVariable("tw-wikilink-template"),
wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$", wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$",
@ -74,7 +75,8 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
wikiLinkText = wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to))); wikiLinkText = wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to)));
domNode.setAttribute("href",wikiLinkText); domNode.setAttribute("href",wikiLinkText);
// Set the tooltip // Set the tooltip
var tooltipWikiText = this.tooltip || this.getVariable("tw-wikilink-tooltip",{defaultValue: "<$transclude field='tooltip'><$transclude field='title'/></$transclude>"}); // HACK: Performance issues with re-parsing the tooltip prevent us defaulting the tooltip to "<$transclude field='tooltip'><$transclude field='title'/></$transclude>"
var tooltipWikiText = this.tooltip || this.getVariable("tw-wikilink-tooltip");
if(tooltipWikiText) { if(tooltipWikiText) {
var tooltipText = this.wiki.renderText("text/plain","text/vnd.tiddlywiki",tooltipWikiText,{ var tooltipText = this.wiki.renderText("text/plain","text/vnd.tiddlywiki",tooltipWikiText,{
parseAsInline: true, parseAsInline: true,