kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Add hooks mechanism and th-opening-default-tiddlers-list hook
see: https://github.com/Jermolene/TiddlyWiki5/issues/1064print-window-tiddler
rodzic
d6c5e51501
commit
90caf5bf42
30
boot/boot.js
30
boot/boot.js
|
@ -1899,6 +1899,36 @@ $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)) {
|
||||
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
|
||||
|
||||
$tw.boot.boot = function() {
|
||||
|
|
|
@ -58,6 +58,8 @@ exports.startup = function() {
|
|||
window.location.hash = "";
|
||||
var storyFilter = $tw.wiki.getTiddlerText(DEFAULT_TIDDLERS_TITLE),
|
||||
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());
|
||||
if(storyList[0]) {
|
||||
$tw.wiki.addToHistory(storyList[0]);
|
||||
|
@ -116,6 +118,8 @@ function openStartupTiddlers(options) {
|
|||
}
|
||||
// Process the story filter to get the story list
|
||||
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(target && storyList.indexOf(target) === -1) {
|
||||
storyList.unshift(target);
|
||||
|
|
Ładowanie…
Reference in New Issue