Module wonderful.event
The wonderful's event system.
Classes and inheritance
Event | The base event class, which represents an event. |
EventListener | The event listener class. |
EventTarget | The base event target class. |
Tables
EventPhase | The enumeration of event phases. |
Class Event
Event.cancelable | Whether the event can be canceled. |
Event.bubblable | Whether the event runs event listeners at bubbling phase. |
Event.capturable | Whether the event runs event listeners at capturing phase. |
Event:preventDefault() | Prevent the default listeners from running. |
Event:cancel() | Cancel the event, which stops propagation of the event. |
Class EventListener
EventListener:__new__(args) | Construct a new instance. |
EventListener:remove() | Removes the listener from the event target it's attached to. |
Class EventTarget
EventTarget:__new__() | Construct a new instance. |
EventTarget:addDefaultListener(args) | Add a default event listener for the class. |
EventTarget:addListener(args) | Add an event listener for the class. |
EventTarget:findListener(args) | Find a listener by its params. |
EventTarget:removeAllListeners([default=false]) | Remove all defined event listeners. |
EventTarget:getChildEventTargets() | Abstract getter of child event targets. |
EventTarget:getParentEventTarget() | Abstract getter of a parent event target. |
EventTarget:dispatchEvent(event, flood) | Dispatch an event at this event target. |
Classes and inheritance
- Event
- The base event class, which represents an event.
- EventListener
- The event listener class.
- EventTarget
- The base event target class.
Tables
- EventPhase
-
The enumeration of event phases.
An event generally goes through all of the phases, in the following order: None (just created, not yet dispatched), Capturing (dispatches at the root, and goes down the tree to the target; dispatches at the target as well), Bubbling (dispatches at the target, and goes up the tree to the root, inclusive).
Note that some phases may be skipped.
Fields:
- None The default phase.
- Capturing The event is descending the tree from its root to the target.
- Bubbling The event is ascending the tree from the target to the root.
Class Event
- Event.cancelable
- Whether the event can be canceled.
- Event.bubblable
- Whether the event runs event listeners at bubbling phase.
- Event.capturable
- Whether the event runs event listeners at capturing phase.
- Event:preventDefault()
-
Prevent the default listeners from running.
If a default listener has the
before
attribute set, itsonCancel
callback will be called.Note that this does not stop propagation of the event.
See also:
- Event:cancel()
-
Cancel the event, which stops propagation of the event.
Note that this does not prevent other listeners defined of the current target from running, including the default listeners.
See also:
Class EventListener
- EventListener:__new__(args)
-
Construct a new instance.
You don't usually need to instantiate this class directly.
Parameters:
- args a keyword argument table
- target a event target the listener is attached to
- event an Event subclass
- handler function(target,event,handler) a handler function
- default boolean whether this is a default listener
- before boolean whether to run it before the user listeners (default false)
- onCancel function(target,event,handler) a function to run if the default action gets prevented (optional)
- capture boolean whether to run it at capturing phase (default false)
- args a keyword argument table
- EventListener:remove()
- Removes the listener from the event target it's attached to.
Class EventTarget
- EventTarget:__new__()
- Construct a new instance.
- EventTarget:addDefaultListener(args)
-
Add a default event listener for the class.
Parameters:
- args a keyword argument table
- event an Event subclass
- handler function(target,event,handler) a handler function
- before boolean whether to run it before the user listeners (default false)
- onCancel function(target,event,handler) a function to run if the default action gets prevented (optional)
- capture boolean whether to run it at capturing phase (default false)
Returns:
-
EventListener
the listener instance
- args a keyword argument table
- EventTarget:addListener(args)
-
Add an event listener for the class.
Parameters:
- args a keyword argument table
- event an Event subclass
- handler function(target,event,handler) a handler function
- capture boolean whether to run it at capturing phase (default false)
Returns:
-
EventListener
the listener instance
- args a keyword argument table
- EventTarget:findListener(args)
-
Find a listener by its params.
Parameters:
- args a keyword argument table
- event the event to which the listener is assigned
- handler function(target,event,handler) the handler function
- default boolean whether the listener is default (default false)
- before boolean whether the listener runs before user-defined listeners (default false)
- onCancel function(target,event,handler) the function that runs if the default action gets prevented (optional)
- capture boolean whether the listener is run at capturing phase (default false)
Returns:
-
EventListener
the listener
Or
-
nil
no such listener
- args a keyword argument table
- EventTarget:removeAllListeners([default=false])
-
Remove all defined event listeners.
Parameters:
- default boolean whether to remove default listeners as well (default false)
- EventTarget:getChildEventTargets()
-
Abstract getter of child event targets.
Returns:
-
{EventTarget,...}
the children
- EventTarget:getParentEventTarget()
-
Abstract getter of a parent event target.
Returns:
-
EventTarget
the parent
- EventTarget:dispatchEvent(event, flood)
-
Dispatch an event at this event target.
Flood dispatch means that the event propagates to the entire element tree: depth-first, pre-order, left-to-right when capturing, and depth-first, post-order, right-to-left when bubbling. If the event is canceled, the propagation stops at that element.
Parameters:
- event the event to dispatch
- flood boolean whether to use flood dispatch
Returns:
-
boolean
whether the propagation was stopped