1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-05 01:26:18 +00:00
TiddlyWiki5/editions/dev/tiddlers/new/HookMechanism.tid

27 lines
1.0 KiB
Plaintext
Raw Normal View History

2014-11-22 20:06:18 +00:00
created: 20141122200310516
2017-02-09 15:42:55 +00:00
modified: 20170209130807520
2014-11-25 19:33:12 +00:00
title: HookMechanism
2014-11-22 20:06:18 +00:00
type: text/vnd.tiddlywiki
2014-11-25 19:33:12 +00:00
The hook mechanism provides a way for plugins to intercept and modify default functionality. Hooks are added as follows:
2014-11-22 20:06:18 +00:00
2014-11-28 10:06:17 +00:00
```js
$tw.hooks.addHook(name,handler);
```
2014-11-22 20:06:18 +00:00
2014-11-25 19:33:12 +00:00
Multiple handlers can be assigned to the same name using repeated calls. When a hook is invoked by name all registered functions will be called sequentially in their order of addition.
2014-11-22 20:06:18 +00:00
2014-11-25 19:33:12 +00:00
Though not essential care should be taken to ensure that hooks are added before they are invoked. For example: [[Hook: tc-opening-default-tiddlers-list]] should ideally be added before the story startup module is invoked otherwise any hook specified additions to the default tiddlers will not be seen on the initial loading of the page, though will be visible if the user clicks the home button.
2014-11-22 20:06:18 +00:00
2014-11-25 19:33:12 +00:00
!! Example
2014-11-22 20:06:18 +00:00
2014-11-25 19:33:12 +00:00
A working example of a hook that adds "test" to the default tiddlers.
2014-11-22 20:06:18 +00:00
2014-11-28 10:06:17 +00:00
```js
2014-11-22 20:06:18 +00:00
$tw.hooks.addHook("th-opening-default-tiddlers-list",function(list) {
list.push("test");
return list;
});
```