From 4d91a7762e444f3e9fa9ec599503b804ab04a4f5 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sat, 5 Apr 2014 17:37:58 +0100 Subject: [PATCH] Optimise link widget Handle the classes better, and stop using a default tooltip (parsing the tooltip was a performance hog) --- core/modules/widgets/link.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/modules/widgets/link.js b/core/modules/widgets/link.js index e2a9be6bb..3885ea08f 100755 --- a/core/modules/widgets/link.js +++ b/core/modules/widgets/link.js @@ -56,17 +56,18 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) { // Create our element var domNode = this.document.createElement("a"); // Assign classes - $tw.utils.addClass(domNode,"tw-tiddlylink"); + var classes = ["tw-tiddlylink"]; if(this.isShadow) { - $tw.utils.addClass(domNode,"tw-tiddlylink-shadow"); + classes.push("tw-tiddlylink-shadow"); } if(this.isMissing && !this.isShadow) { - $tw.utils.addClass(domNode,"tw-tiddlylink-missing"); + classes.push("tw-tiddlylink-missing"); } else { if(!this.isMissing) { - $tw.utils.addClass(domNode,"tw-tiddlylink-resolves"); + classes.push("tw-tiddlylink-resolves"); } } + domNode.setAttribute("class",classes.join(" ")); // Set an href var wikiLinkTemplateMacro = this.getVariable("tw-wikilink-template"), 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))); domNode.setAttribute("href",wikiLinkText); // Set the tooltip - var tooltipWikiText = this.tooltip || this.getVariable("tw-wikilink-tooltip",{defaultValue: "<$transclude field='tooltip'><$transclude field='title'/>"}); + // HACK: Performance issues with re-parsing the tooltip prevent us defaulting the tooltip to "<$transclude field='tooltip'><$transclude field='title'/>" + var tooltipWikiText = this.tooltip || this.getVariable("tw-wikilink-tooltip"); if(tooltipWikiText) { var tooltipText = this.wiki.renderText("text/plain","text/vnd.tiddlywiki",tooltipWikiText,{ parseAsInline: true,