1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-26 07:13:15 +00:00

Parse the wiki link tooltip as wiki text

This commit is contained in:
Jermolene 2014-03-08 16:06:57 +00:00
parent 8bd1fa50dc
commit 289bec0fd5
2 changed files with 34 additions and 6 deletions

View File

@ -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'/></$transclude>"});
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;
}

View File

@ -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 `<a>` tag.
The default tooltip is:
```
<$transclude field="tooltip"><$transclude field="title"/></$transclude>
```
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 `<a>` 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"/>
```