Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('node-event-delegate', function (Y, NAME) {
2
 
3
/**
4
 * Functionality to make the node a delegated event container
5
 * @module node
6
 * @submodule node-event-delegate
7
 */
8
 
9
/**
10
 * <p>Sets up a delegation listener for an event occurring inside the Node.
11
 * The delegated event will be verified against a supplied selector or
12
 * filtering function to test if the event references at least one node that
13
 * should trigger the subscription callback.</p>
14
 *
15
 * <p>Selector string filters will trigger the callback if the event originated
16
 * from a node that matches it or is contained in a node that matches it.
17
 * Function filters are called for each Node up the parent axis to the
18
 * subscribing container node, and receive at each level the Node and the event
19
 * object.  The function should return true (or a truthy value) if that Node
20
 * should trigger the subscription callback.  Note, it is possible for filters
21
 * to match multiple Nodes for a single event.  In this case, the delegate
22
 * callback will be executed for each matching Node.</p>
23
 *
24
 * <p>For each matching Node, the callback will be executed with its 'this'
25
 * object set to the Node matched by the filter (unless a specific context was
26
 * provided during subscription), and the provided event's
27
 * <code>currentTarget</code> will also be set to the matching Node.  The
28
 * containing Node from which the subscription was originally made can be
29
 * referenced as <code>e.container</code>.
30
 *
31
 * @method delegate
32
 * @param type {String} the event type to delegate
33
 * @param fn {Function} the callback function to execute.  This function
34
 *              will be provided the event object for the delegated event.
35
 * @param spec {String|Function} a selector that must match the target of the
36
 *              event or a function to test target and its parents for a match
37
 * @param context {Object} optional argument that specifies what 'this' refers to.
38
 * @param args* {any} 0..n additional arguments to pass on to the callback function.
39
 *              These arguments will be added after the event object.
40
 * @return {EventHandle} the detach handle
41
 * @for Node
42
 */
43
Y.Node.prototype.delegate = function(type) {
44
 
45
    var args = Y.Array(arguments, 0, true),
46
        index = (Y.Lang.isObject(type) && !Y.Lang.isArray(type)) ? 1 : 2;
47
 
48
    args.splice(index, 0, this._node);
49
 
50
    return Y.delegate.apply(Y, args);
51
};
52
 
53
 
54
}, '3.18.1', {"requires": ["node-base", "event-delegate"]});