Rewrite JS hooks

- Use event listeners instead of homebrew hooks
- Remove view/js/addon-hooks.js and its references
- Update Addon docs
This commit is contained in:
Hypolite Petovan 2018-09-19 22:51:51 -04:00
parent 68c6895e1a
commit 7dd6fb3b3c
5 changed files with 8 additions and 59 deletions

View file

@ -1,41 +0,0 @@
/**
* @file addon-hooks.js
* @brief Provide a way for add-ons to register a JavaScript hook
*/
var addon_hooks = {};
/**
* @brief Register a JavaScript hook to be called from other Javascript files
* @pre the .js file from which the hook will be called is included in the document response
* @param type which type of hook i.e. where should it be called along with other hooks of the same type
* @param hookfnstr name of the JavaScript function name that needs to be called
*/
function Addon_registerHook(type, hookfnstr)
{
if (!addon_hooks.hasOwnProperty(type)) {
addon_hooks[type] = [];
}
addon_hooks[type].push(hookfnstr);
}
/**
* @brief Call all registered hooks of a certain type, i.e. at the same point of the JavaScript code execution
* @param typeOfHook string indicating which type of hooks to be called among the registered hooks
*/
function callAddonHooks(typeOfHook)
{
if (typeof addon_hooks !== 'undefined') {
var myTypeOfHooks = addon_hooks[typeOfHook];
if (typeof myTypeOfHooks !== 'undefined') {
for (addon_hook_idx = 0; addon_hook_idx < myTypeOfHooks.length; addon_hook_idx++) {
var hookfnstr = myTypeOfHooks[addon_hook_idx];
var hookfn = window[hookfnstr];
if (typeof hookfn === "function") {
hookfn();
}
}
}
}
}

View file

@ -478,14 +478,12 @@ function liveUpdate(src) {
$('.wall-item-body', data).imagesLoaded(function() {
updateConvItems(data);
document.dispatchEvent(new Event('postprocess_liveupdate'));
// Update the scroll position.
$(window).scrollTop($(window).scrollTop() + $("section").height() - orgHeight);
});
callAddonHooks("postprocess_liveupdate");
});
}
function imgbright(node) {
@ -735,6 +733,8 @@ function loadScrollContent() {
} else {
$("#scroll-end").fadeIn('normal');
}
document.dispatchEvent(new Event('postprocess_liveupdate'));
});
}