delegate.js revision 030b855bbf1937a46e1e2b88025d61e72a205469
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Adds event delegation support to the library.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @module event
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @submodule event-delegate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevar toArray = Y.Array,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * <p>Sets up event delegation on a container element. The delegated event
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will use a supplied selector or filtering function to test if the event
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * references at least one node that should trigger the subscription
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * callback.</p>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * <p>Selector string filters will trigger the callback if the event originated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from a node that matches it or is contained in a node that matches it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Function filters are called for each Node up the parent axis to the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * subscribing container node, and receive at each level the Node and the event
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * object. The function should return true (or a truthy value) if that Node
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * should trigger the subscription callback. Note, it is possible for filters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to match multiple Nodes for a single event. In this case, the delegate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * callback will be executed for each matching Node.</p>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * <p>For each matching Node, the callback will be executed with its 'this'
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * object set to the Node matched by the filter (unless a specific context was
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * provided during subscription), and the provided event's
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * <code>currentTarget</code> will also be set to the matching Node. The
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * containing Node from which the subscription was originally made can be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * referenced as <code>e.container</code>.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @method delegate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param type {String} the event type to delegate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param fn {Function} the callback function to execute. This function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will be provided the event object for the delegated event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param el {String|node} the element that is the delegation container
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param spec {string|Function} a selector that must match the target of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * event or a function to test target and its parents for a match
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param context optional argument that specifies what 'this' refers to.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param args* 0..n additional arguments to pass on to the callback function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * These arguments will be added after the event object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @return {EventHandle} the detach handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte typeBits, synth, container, categories, cat, i, len, handles, handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Support Y.delegate({ click: fnA, key: fnB }, context, filter, ...);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // and Y.delegate(['click', 'key'], fn, context, filter, ...);
for (i in type) {
if (!handle) {
}, el);
return handle;
if (this.args) {
if (currentTarget) {
return ret;
return function (target, e) {
match = [];
return match;