X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=view%2Fjs%2Faddon-hooks.js;h=3e1cb4849e96a1d6d1ad6b6cb0c0233186d94d58;hb=761bdafa34bfdf1b2b43a3f06ae092e0925898ac;hp=2530f10beab05ee5b542ab2dff1034147d29da96;hpb=ef01dfefd48c890dc2c2aae4f34ce5929714e983;p=friendica.git diff --git a/view/js/addon-hooks.js b/view/js/addon-hooks.js index 2530f10bea..3e1cb4849e 100644 --- a/view/js/addon-hooks.js +++ b/view/js/addon-hooks.js @@ -1,10 +1,41 @@ -var addon_hooks={}; +/** + * @file addon-hooks.js + * @brief Provide a way for add-ons to register a JavaScript hook + */ -function Addon_registerHook( type, hookfnstr ) +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] = []; } - addon_hooks[type].push( hookfnstr ); + 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(); + } + } + } + } }