Event Hooks
Event hooks are, essentially, event callbacks that apply to all jCanvas layers. They do not override any existing event callbacks, but rather, complement them.
Canvas Event Hooks
jCanvas supports a type of event hook called a canvas event hook. Canvas event hooks apply only to layers on the selected canvases.
To define an event hook, call the setEventHooks()
method with the event hooks you would like to set. If you wish to remove an existing event hook, simply set its value to null
.
Similarly, to retrieve the object containing all event hooks for a canvas, use the getEventHooks()
method.
Global Event Hooks
jCanvas supports another type of event hook called a global event hook. Global event hooks apply to all layers on all canvases, and do not override canvas event hooks.
Event Bubbling
With the addition of event hooks, all jCanvas events bubble up, meaning for any jCanvas event that is triggered:
- The layer event callback runs first (if it exists)
- The canvas event hook runs second (if it exists)
- The global event hook runs last (if it exists)
Notes
Event hooks can also be leveraged by jCanvas plugin developers to give their plugins tighter integration with jCanvas