From 289bec0fd557f9f05b189771ad54308d1d2a97a6 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sat, 8 Mar 2014 16:06:57 +0000 Subject: [PATCH] Parse the wiki link tooltip as wiki text --- core/modules/widgets/link.js | 16 +++++++++---- .../tw5.com/tiddlers/widgets/LinkWidget.tid | 24 +++++++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/core/modules/widgets/link.js b/core/modules/widgets/link.js index 52f9fb7e4..e2a9be6bb 100755 --- a/core/modules/widgets/link.js +++ b/core/modules/widgets/link.js @@ -73,9 +73,17 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) { wikiLinkText = wikiLinkTemplate.replace("$uri_encoded$",encodeURIComponent(this.to)); wikiLinkText = wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to))); domNode.setAttribute("href",wikiLinkText); - // Set the title - if(this.tooltip) { - domNode.setAttribute("title",this.tooltip); + // Set the tooltip + var tooltipWikiText = this.tooltip || this.getVariable("tw-wikilink-tooltip",{defaultValue: "<$transclude field='tooltip'><$transclude field='title'/>"}); + if(tooltipWikiText) { + var tooltipText = this.wiki.renderText("text/plain","text/vnd.tiddlywiki",tooltipWikiText,{ + parseAsInline: true, + variables: { + currentTiddler: this.to + }, + parentWidget: this + }); + domNode.setAttribute("title",tooltipText); } // Add a click event handler $tw.utils.addEventListeners(domNode,[ @@ -180,7 +188,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of */ LinkWidget.prototype.refresh = function(changedTiddlers) { var changedAttributes = this.computeAttributes(); - if(changedAttributes.to || changedTiddlers[this.to]) { + if(changedAttributes.to || changedTiddlers[this.to] || changedAttributes.tooltip) { this.refreshSelf(); return true; } diff --git a/editions/tw5.com/tiddlers/widgets/LinkWidget.tid b/editions/tw5.com/tiddlers/widgets/LinkWidget.tid index 1d41ddaca..c09566094 100644 --- a/editions/tw5.com/tiddlers/widgets/LinkWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/LinkWidget.tid @@ -7,10 +7,18 @@ The `link` widget generates links to tiddlers. |!Attribute |!Description | |to |The title of the target tiddler for the link (defaults to the [[WidgetVariable: currentTiddler]]) | -|tooltip |Optional tooltip text | +|tooltip |Optional tooltip WikiText | The content of the link widget is rendered within the `` tag. +The default tooltip is: + +``` +<$transclude field="tooltip"><$transclude field="title"/> +``` + +Note that the tooltip is rendered with the current tiddler set to the target of the link. + ! CSS Classes * `tw-tiddlylink` - applied to all links @@ -33,10 +41,22 @@ Links are suppressed if the macro `tw-wikilinks` evaluates to the string `no`. F !! tw-wikilink-template -Link targets default to the URL encoded title of the tiddler. The `href` can be templated by defining the configuration macro `tw-wikilink-template`, and including within it the token `$uri_encoded$`. For example: +The target of the link widget defaults to the URL encoded title of the tiddler. The `href` can be templated by defining the configuration macro `tw-wikilink-template`, and including within it the token `$uri_encoded$`. For example: ``` \define tw-wikilink-template() http://tiddlywiki.com/#$uri_encoded$ ``` +The token `$uri_doubleencoded$` is replaced by the double encoded title of the tiddler. + Note that in the browser the `` element generated by the link widget has a JavaScript event handler that navigates directly to the target tiddler, ignoring the `href` attribute. + +!! tw-wikilink-tooltip + +Provides default text for the link tooltip: + +``` +\define tw-wikilink-tooltip() This is a link to {{!!title}} +<$link to="HelloThere"/> +``` +