Class: DOMListener

.base. DOMListener

An Event Emitter for DOM Nodes. Accepts a single DOM Node as input, and allows events to be registered on the Node with the usual emitter methods (`.on()`, `.off()`, etc.), except for `.emit()` (since the DOM emits the event automatically). This allows for easy registering and deregistering of events. The event map is stored directly on the DOM node, so that it isn't necessary to retain a reference to the element.

new DOMListener(el)

Create a new DOMListener
Parameters:
Name Type Description
el Object | String The DOM Node or DOM selector string to use for this element

Methods


off( [event] [, callback] [, options])

Unsubscribe one or more listeners from the element.
Parameters:
Name Type Argument Description
event String <optional>
The event to remove. If none is specified, all events will be removed.
callback function <optional>
The callback to remove. If none is specified, all callbacks for the specified event will be removed.
options Object <optional>
The options for the event listener. See the options object of the DOM's addEventListener method.
Returns:
Returns the DOM Listener object.
Type
Object

on(event, callback [, options])

Subscribe a callback to an event
Parameters:
Name Type Argument Description
event String The name of the event to subscribe to. Must be a valid event type.
callback function The function to invoke when the event is fired
options Object <optional>
The options for the event listener. See the options object of the DOM's addEventListener method.
Returns:
Returns the DOM Listener object
Type
Object

once(event, callback)

Subscribe a callback to an event to fire exactly once. After the callback is invoked, it will be removed from the listeners.
Parameters:
Name Type Description
event String The name of the event to subscribe to. Must be a valid event type.
callback function The function to invoke when the event is fired.
Returns:
Returns the DOM Listener object
Type
Object