src/cm/media/js/lib/yui/yui_3.10.3/build/node-event-delegate/node-event-delegate-debug.js
author Yves-Marie Haussonne <ymh.work+github@gmail.com>
Fri, 09 May 2014 18:35:26 +0200
changeset 656 a84519031134
parent 525 89ef5ed3c48b
permissions -rw-r--r--
add link to "privacy policy" in the header test
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
525
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     1
/*
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     2
YUI 3.10.3 (build 2fb5187)
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     3
Copyright 2013 Yahoo! Inc. All rights reserved.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     4
Licensed under the BSD License.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     5
http://yuilibrary.com/license/
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     6
*/
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     7
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     8
YUI.add('node-event-delegate', function (Y, NAME) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
     9
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    10
/**
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    11
 * Functionality to make the node a delegated event container
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    12
 * @module node
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    13
 * @submodule node-event-delegate
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    14
 */
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    15
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    16
/**
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    17
 * <p>Sets up a delegation listener for an event occurring inside the Node.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    18
 * The delegated event will be verified against a supplied selector or
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    19
 * filtering function to test if the event references at least one node that
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    20
 * should trigger the subscription callback.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    21
 *
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    22
 * <p>Selector string filters will trigger the callback if the event originated
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    23
 * from a node that matches it or is contained in a node that matches it.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    24
 * Function filters are called for each Node up the parent axis to the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    25
 * subscribing container node, and receive at each level the Node and the event
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    26
 * object.  The function should return true (or a truthy value) if that Node
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    27
 * should trigger the subscription callback.  Note, it is possible for filters
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    28
 * to match multiple Nodes for a single event.  In this case, the delegate
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    29
 * callback will be executed for each matching Node.</p>
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    30
 *
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    31
 * <p>For each matching Node, the callback will be executed with its 'this'
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    32
 * object set to the Node matched by the filter (unless a specific context was
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    33
 * provided during subscription), and the provided event's
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    34
 * <code>currentTarget</code> will also be set to the matching Node.  The
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    35
 * containing Node from which the subscription was originally made can be
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    36
 * referenced as <code>e.container</code>.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    37
 *
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    38
 * @method delegate
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    39
 * @param type {String} the event type to delegate
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    40
 * @param fn {Function} the callback function to execute.  This function
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    41
 *              will be provided the event object for the delegated event.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    42
 * @param spec {String|Function} a selector that must match the target of the
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    43
 *              event or a function to test target and its parents for a match
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    44
 * @param context {Object} optional argument that specifies what 'this' refers to.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    45
 * @param args* {any} 0..n additional arguments to pass on to the callback function.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    46
 *              These arguments will be added after the event object.
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    47
 * @return {EventHandle} the detach handle
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    48
 * @for Node
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    49
 */
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    50
Y.Node.prototype.delegate = function(type) {
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    51
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    52
    var args = Y.Array(arguments, 0, true),
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    53
        index = (Y.Lang.isObject(type) && !Y.Lang.isArray(type)) ? 1 : 2;
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    54
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    55
    args.splice(index, 0, this._node);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    56
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    57
    return Y.delegate.apply(Y, args);
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    58
};
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    59
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    60
89ef5ed3c48b Upgrades to yui 3.10.3
gibus
parents:
diff changeset
    61
}, '3.10.3', {"requires": ["node-base", "event-delegate"]});