mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-10-04 15:11:41 +00:00
Add hooks mechanism and th-opening-default-tiddlers-list hook
see: https://github.com/Jermolene/TiddlyWiki5/issues/1064
This commit is contained in:
@@ -1899,6 +1899,36 @@ $tw.boot.isStartupTaskEligible = function(taskModule) {
|
|||||||
return true;
|
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)) {
|
||||||
|
alert($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
|
/////////////////////////// Main boot function to decrypt tiddlers and then startup
|
||||||
|
|
||||||
$tw.boot.boot = function() {
|
$tw.boot.boot = function() {
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ exports.startup = function() {
|
|||||||
window.location.hash = "";
|
window.location.hash = "";
|
||||||
var storyFilter = $tw.wiki.getTiddlerText(DEFAULT_TIDDLERS_TITLE),
|
var storyFilter = $tw.wiki.getTiddlerText(DEFAULT_TIDDLERS_TITLE),
|
||||||
storyList = $tw.wiki.filterTiddlers(storyFilter);
|
storyList = $tw.wiki.filterTiddlers(storyFilter);
|
||||||
|
//invoke any hooks that might change the default story list
|
||||||
|
storyList = $tw.hooks.invokeHook("th-opening-default-tiddlers-list",storyList);
|
||||||
$tw.wiki.addTiddler({title: DEFAULT_STORY_TITLE, text: "", list: storyList},$tw.wiki.getModificationFields());
|
$tw.wiki.addTiddler({title: DEFAULT_STORY_TITLE, text: "", list: storyList},$tw.wiki.getModificationFields());
|
||||||
if(storyList[0]) {
|
if(storyList[0]) {
|
||||||
$tw.wiki.addToHistory(storyList[0]);
|
$tw.wiki.addToHistory(storyList[0]);
|
||||||
@@ -116,6 +118,8 @@ function openStartupTiddlers(options) {
|
|||||||
}
|
}
|
||||||
// Process the story filter to get the story list
|
// Process the story filter to get the story list
|
||||||
var storyList = $tw.wiki.filterTiddlers(storyFilter);
|
var storyList = $tw.wiki.filterTiddlers(storyFilter);
|
||||||
|
//invoke any hooks that might change the default story list
|
||||||
|
storyList = $tw.hooks.invokeHook("th-opening-default-tiddlers-list",storyList);
|
||||||
// If the target tiddler isn't included then splice it in at the top
|
// If the target tiddler isn't included then splice it in at the top
|
||||||
if(target && storyList.indexOf(target) === -1) {
|
if(target && storyList.indexOf(target) === -1) {
|
||||||
storyList.unshift(target);
|
storyList.unshift(target);
|
||||||
|
|||||||
Reference in New Issue
Block a user