
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 |
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 accepts 4 arguments:
The value will be passed through each hook. Depending on the hook, callbacks can simply react or alter data.
Plugins can trigger their own hooks:
elgg.hook.trigger_hook('name', 'type', {params}, "value");