event-delegate-debug.js revision 7d1157dbcdfedd79881117578f3790d06a2cd317
279N/A * Adds event delegation support to the library. 279N/A * @submodule event-delegate 447N/A // The target is a descendant of an element matching 279N/A // the selector, so crawl up to find the ancestor that 447N/A // matches the selector * Sets up event delegation on a container element. The delegated event * will use a supplied selector to test if the target or one of the * descendants of the target match it. The supplied callback function * will only be executed if a match was encountered, and, in fact, * will be executed for each element that matches if you supply an * The event object for the delegated event is supplied to the callback * function. It is modified slightly in order to support all properties * that may be needed for event delegation. 'currentTarget' is set to * the element that matched the delegation specifcation. 'container' is * set to the element that the listener is bound to (this normally would * be the 'currentTarget'). * @param type {string} the event type to delegate * @param fn {function} the callback function to execute. This function * will be provided the event object for the delegated event. * @param el {string|node} the element that is the delegation container * @param spec {string} a selector that must match the target of the * @param context optional argument that specifies what 'this' refers to. * @param args* 0..n additional arguments to pass on to the callback function. * These arguments will be added after the event object. * @return {EventHandle} the detach handle Y.
log(
'delegate: no spec, nothing to do',
'warn',
'event');
element =
el,
// HTML element serving as the delegation container // Y.Selector.query returns an array of matches unless specified // to return just the first match. Since the primary use case for // event delegation is to use a single event handler on a container, // Y.delegate doesn't currently support being able to bind a // single listener to multiple containers. if (!
element) {
// Not found, check using onAvailable // The Custom Event for the delegation spec // The key to the listener for the event type and container Y.
log(
"Delegating a " +
type +
" event requires the event-mouseenter submodule.",
"error",
"Event");
// Create the DOM Event wrapper that will fire the Custom Event // Hook into the _delete method for the Custom Event wrapper of this // DOM Event in order to clean up the 'delegates' map and unsubscribe // the associated Custom Event listeners fired by this DOM event // listener if/when the user calls "purgeElement" OR removes all // listeners of the Custom Event. // Delete this event from the map of known delegates Y.
log(
"DOM event listener associated with the " +
ename +
" Custom Event removed. Removing all " +
ename +
" listeners.",
"info",
"Event");
// Unsubscribe all listeners of the Custom Event fired // Remove element, delegation spec // Subscribe to the Custom Event for the delegation spec // Hook into the detach method of the handle in order to clean up the // 'delegates' map and remove the associated DOM event handler // responsible for firing this Custom Event if all listener for this // event have been removed. Y.
log(
"No more listeners for the " +
ename +
" Custom Event. Removing its associated DOM event listener.",
"info",
"Event");
},
'@VERSION@' ,{
requires:[
'node-base']});