Javascript/hooks

The JS engine has a hooks system similar to the PHP engine's plugin hooks: hooks are triggered and plugins can register callbacks to react or alter information. There is no concept of Elgg events in the JS engine; everything in the JS engine is implemented as a hook.

Contents

Registering a callback to a hook

Callbacks are registered using elgg.register_hook_handler(). Multiple callbacks can be registered for the same hook.

The following example registers the `elgg.ui.initDatePicker` callback for the init, system event. Note that a difference in the JS engine is that instead of passing a string you pass the function itself to elgg.register_hook_handler() as the callback.

elgg.provide('elgg.ui.initDatePicker');
elgg.ui.initDatePicker = function() { ... }
 
elgg.register_hook_handler('init', 'system', elgg.ui.initDatePicker);

The callback

The callback accepts 4 arguments:

hook
The hook name.
type
The hook type.
params
An object or set of parameters specific to the hook.
value
The current value.

The value will be passed through each hook. Depending on the hook, callbacks can simply react or alter data.

Triggering custom hooks

Plugins can trigger their own hooks:

elgg.hook.trigger_hook('name', 'type', {params}, "value");

Available hooks

init, system
This hook is fired when the JS system is ready. Plugins should register their init functions for this hook.
ready, system
This hook is fired when the system has fully booted.
getOptions, ui.popup
This hook is fired for pop up displays (`rel`="popup") and allows for customized placement options.

Search docs