2018-06-13 03:31:08 -04:00
|
|
|
/**
|
|
|
|
* @file addon-hooks.js
|
|
|
|
* @brief Provide a way for add-ons to register a JavaScript hook
|
|
|
|
*/
|
|
|
|
|
2018-06-13 15:03:19 -04:00
|
|
|
var addon_hooks = {};
|
2018-06-07 16:23:30 -04:00
|
|
|
|
2018-06-13 03:31:08 -04:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2018-06-13 15:03:19 -04:00
|
|
|
function Addon_registerHook(type, hookfnstr)
|
2018-06-07 16:23:30 -04:00
|
|
|
{
|
|
|
|
if (!addon_hooks.hasOwnProperty(type)) {
|
2018-06-13 15:03:19 -04:00
|
|
|
addon_hooks[type] = [];
|
2018-06-07 16:23:30 -04:00
|
|
|
}
|
|
|
|
|
2018-06-13 15:03:19 -04:00
|
|
|
addon_hooks[type].push(hookfnstr);
|
2018-06-07 16:23:30 -04:00
|
|
|
}
|
2018-06-13 03:31:08 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2018-06-13 15:03:19 -04:00
|
|
|
function callAddonHooks(typeOfHook)
|
|
|
|
{
|
2018-06-13 03:31:08 -04:00
|
|
|
if (typeof addon_hooks !== 'undefined') {
|
2018-06-13 15:03:19 -04:00
|
|
|
var myTypeOfHooks = addon_hooks[typeOfHook];
|
2018-06-13 03:31:08 -04:00
|
|
|
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];
|
2018-06-13 15:03:19 -04:00
|
|
|
if (typeof hookfn === "function") {
|
|
|
|
hookfn();
|
|
|
|
}
|
2018-06-13 03:31:08 -04:00
|
|
|
}
|
|
|
|
}
|
2018-06-13 15:03:19 -04:00
|
|
|
}
|
2018-06-13 03:31:08 -04:00
|
|
|
}
|