1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-10-26 13:17:38 +00:00

Merge pull request #1118 from welford/hook

Add hooks mechanism and th-opening-default-tiddlers-list hook
This commit is contained in:
Jeremy Ruston
2014-11-25 19:25:00 +00:00
5 changed files with 69 additions and 2 deletions

View File

@@ -1899,6 +1899,35 @@ $tw.boot.isStartupTaskEligible = function(taskModule) {
return true;
};
/*
Global Hooks mechanism which allows plugins to modify default functionality
*/
$tw.hooks = $tw.hooks || { names: {}};
/*
Add hooks to the hashmap
*/
$tw.hooks.addHook = function(hookName,definition) {
if($tw.utils.hop($tw.hooks.names,hookName)) {
$tw.hooks.names[hookName].push(definition);
}
else {
$tw.hooks.names[hookName] = [definition];
}
};
/*
Invoke the hook by key
*/
$tw.hooks.invokeHook = function(hookName, value) {
if($tw.utils.hop($tw.hooks.names,hookName)) {
for (var i = 0; i < $tw.hooks.names[hookName].length; i++) {
value = $tw.hooks.names[hookName][i](value);
}
}
return value;
};
/////////////////////////// Main boot function to decrypt tiddlers and then startup
$tw.boot.boot = function() {