1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-17 07:14:50 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/widgets/LinkWidget.tid
2014-10-12 13:59:26 +02:00

93 lines
2.7 KiB
Plaintext

title: LinkWidget
created: 201310241419
modified: 201408280837
tags: Widgets
caption: link
The `link` widget generates links to tiddlers. (Use the HTML `<a>` element to generate external links).
! Content and Attributes
|!Attribute |!Description |
|to |The title of the target tiddler for the link (defaults to the CurrentTiddler) |
|aria-label |Optional [[Accessibility]] label |
|tooltip |Optional tooltip WikiText |
The content of the link widget is rendered within the `<a>` tag.
The default value of the tooltip attribute is `<<tv-wikilink-tooltip>>`.
This means that you can control the text of a link tooltip in several ways:
```
<$link to="HelloThere" tooltip="Custom tooltip">Link 1</$link>
<$set name="tv-wikilink-tooltip" value="I'm a link to {{!!title}}">
<$link to="HelloThere">Link 2</$link>
</$set>
```
Renders as:
<$link to="HelloThere" tooltip="Custom tooltip">Link 1</$link>
<$set name="tv-wikilink-tooltip" value="I'm a link to {{!!title}}">
<$link to="HelloThere">Link 2</$link>
</$set>
Note that the tooltip is rendered with the current tiddler set to the target of the link.
A useful convention is to set the tooltip like this:
```
\define tv-wikilink-tooltip()
<$transclude field="tooltip"><$transclude field="title"/></$transclude>
\end
```
This causes the tooltip to be the ''tooltip'' field of the target tiddler. If the field isn't present, then the title is used instead.
! CSS Classes
* `tc-tiddlylink` - applied to all links
* `tc-tiddlylink-external` - applied to external, non-tiddler links
* `tc-tiddlylink-internal` - applied to tiddler links
* `tc-tiddlylink-missing` - applied to tiddler links where the target tiddler doesn't exist
* `tc-tiddlylink-resolves` - applied to tiddler links when the target tiddler does exist
! Configuration macros
Configuration macros can be used to modify the behaviour of the link widget.
!! tv-wikilinks
Links are suppressed if the macro `tv-wikilinks` evaluates to the string `no`. For example:
```
\define tv-wikilinks() no
```
!! tv-wikilink-template
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 `tv-wikilink-template`, and including within it the token `$uri_encoded$`. For example:
```
\define tv-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.
!! tv-wikilink-tooltip
Provides default text for the link tooltip:
```
\define tv-wikilink-tooltip() This is a link to {{!!title}}
<$link to="HelloThere"/>
```