conglomerate-dom-event
v2.2.3
Published
Create and manage a DOM event delegator.
Downloads
7
Readme
conglomerate-dom-event
Adaptation of DOM Delegate, developed by FT Labs, part of the Financial Times.
Simple, easy-to-use component for binding to events on all target elements matching the given selector, irrespective of whether anything exists in the DOM at registration time or not. This allows developers to implement the event delegation pattern.
Thanks
The developers of ftdomdelegate are Matthew Andrews and Matthew Caruana Galizia. Test engineering by Sam Giles. The API is influenced by jQuery Live. All open source code released by FT Labs is licenced under the MIT licence. We welcome comments, feedback and suggestions. Please feel free to raise an issue or pull request.
Thanks to Sauce Labs for providing the infrastructure that allows us to run our build in real browsers.
Documentation
Delegate
DOM event delegator
The delegator will listen for events that bubble up to the root node.
Parameters
captureForType
Parameters
eventType
string
Returns **** boolean
destroy
Short hand for off() and root(), ie both with no parameters
Returns **** void
fire
Fire a listener on a target.
Parameters
Returns boolean
handle
Handle an arbitrary event.
Parameters
event
Event
off
Remove an event handler for elements that match the selector, forever
Parameters
eventType
string= Remove handlers for events matching this type, considering the other parametersselector
string= If this parameter is omitted, only handlers which match the other two will be removedhandler
function ()= If this parameter is omitted, only handlers which match the previous two will be removeduseCapture
Returns Delegate This method is chainable
on
Attach a handler to one event for all elements that match the selector, now or in the future
The handler function receives three arguments: the DOM event object, the node that matched the selector while the event was bubbling and a reference to itself. Within the handler, 'this' is equal to the second argument.
The node that actually received the event can be accessed via 'event.target'.
Parameters
eventType
string Listen for these eventsselector
(string|undefined) Only handle events on elements matching this selector, if undefined match root elementhandler
function () Handler function - event data passed here will be in event.dataeventData
Object= Data to pass in event.datauseCapture
Returns Delegate This method is chainable
root
Start listening for events on the provided DOM element
Parameters
Returns Delegate This method is chainable
handle
listenerMap
Maintain a map of listener lists, keyed by event name.
matches
Check whether an element matches a generic selector.
Parameters
selector
string A CSS selector
matchesId
Check whether the ID of the element in 'this' matches the given ID.
IDs are case-sensitive.
Parameters
Returns **** boolean
matchesRoot
Check whether an element matches the root.
Parameters
selector
?String In this case this is always passed through as null and not usedelement
Element The element to test with
Returns **** boolean
matchesTag
Check whether an element matches a tag selector.
Tags are NOT case-sensitive, except in XML (and XML-based languages such as XHTML).
Parameters
Returns **** boolean
rootElement
The root node at which listeners are attached.
License
conglomerate-dom-event is released under the terms of the BSD-3-Clause license.
This software includes or is derivative of works distributed under the licenses listed below. Please refer to the specific files and/or packages for more detailed information about the authors, copyright notices, and licenses.
- ftdomdelegate is released under the terms of the MIT license.