~andreserl/maas/packaging_precise_rebase

« back to all changes in this revision

Viewing changes to debian/extras/jslibs/yui/event-outside/event-outside.js

  • Committer: Andres Rodriguez
  • Date: 2013-03-20 18:12:30 UTC
  • mfrom: (145.2.22 precise.sru)
  • Revision ID: andreserl@ubuntu.com-20130320181230-6l5guc0nhlv2z4p7
Re-base againts latest quantal released branch towards SRU

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.5.1 (build 22)
 
3
Copyright 2012 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
YUI.add('event-outside', function(Y) {
 
8
 
 
9
/**
 
10
 * Outside events are synthetic DOM events that fire when a corresponding native
 
11
 * or synthetic DOM event occurs outside a bound element.
 
12
 *
 
13
 * The following outside events are pre-defined by this module:
 
14
 * <ul>
 
15
 *   <li>blur</li>
 
16
 *   <li>change</li>
 
17
 *   <li>click</li>
 
18
 *   <li>dblclick</li>
 
19
 *   <li>focus</li>
 
20
 *   <li>keydown</li>
 
21
 *   <li>keypress</li>
 
22
 *   <li>keyup</li>
 
23
 *   <li>mousedown</li>
 
24
 *   <li>mousemove</li>
 
25
 *   <li>mouseout</li>
 
26
 *   <li>mouseover</li>
 
27
 *   <li>mouseup</li>
 
28
 *   <li>select</li>
 
29
 *   <li>submit</li>
 
30
 * </ul>
 
31
 *
 
32
 * Define new outside events with
 
33
 * <code>Y.Event.defineOutside(eventType);</code>.
 
34
 * By default, the created synthetic event name will be the name of the event
 
35
 * with "outside" appended (e.g. "click" becomes "clickoutside"). If you want
 
36
 * a different name for the created Event, pass it as a second argument like so:
 
37
 * <code>Y.Event.defineOutside(eventType, "yonderclick")</code>.
 
38
 *
 
39
 * @module event
 
40
 * @submodule event-outside
 
41
 */
 
42
 
 
43
// Outside events are pre-defined for each of these native DOM events
 
44
var nativeEvents = [
 
45
        'blur', 'change', 'click', 'dblclick', 'focus', 'keydown', 'keypress',
 
46
        'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup',
 
47
        'select', 'submit'
 
48
    ];
 
49
 
 
50
/**
 
51
 * Defines a new outside event to correspond with the given DOM event.
 
52
 *
 
53
 * By default, the created synthetic event name will be the name of the event
 
54
 * with "outside" appended (e.g. "click" becomes "clickoutside"). If you want
 
55
 * a different name for the created Event, pass it as a second argument like so:
 
56
 * <code>Y.Event.defineOutside(eventType, "yonderclick")</code>.
 
57
 *
 
58
 * @method Y.Event.defineOutside
 
59
 * @param {String} event DOM event
 
60
 * @param {String} name (optional) custom outside event name
 
61
 * @static
 
62
 */
 
63
Y.Event.defineOutside = function (event, name) {
 
64
    name = name || (event + 'outside');
 
65
 
 
66
    var config = {
 
67
    
 
68
        on: function (node, sub, notifier) {
 
69
            sub.handle = Y.one('doc').on(event, function(e) {
 
70
                if (this.isOutside(node, e.target)) {
 
71
                    e.currentTarget = node;
 
72
                    notifier.fire(e);
 
73
                }
 
74
            }, this);
 
75
        },
 
76
        
 
77
        detach: function (node, sub, notifier) {
 
78
            sub.handle.detach();
 
79
        },
 
80
        
 
81
        delegate: function (node, sub, notifier, filter) {
 
82
            sub.handle = Y.one('doc').delegate(event, function (e) {
 
83
                if (this.isOutside(node, e.target)) {
 
84
                    notifier.fire(e);
 
85
                }
 
86
            }, filter, this);
 
87
        },
 
88
        
 
89
        isOutside: function (node, target) {
 
90
            return target !== node && !target.ancestor(function (p) {
 
91
                    return p === node;
 
92
                });
 
93
        }
 
94
    };
 
95
    config.detachDelegate = config.detach;
 
96
 
 
97
    Y.Event.define(name, config);
 
98
};
 
99
 
 
100
// Define outside events for some common native DOM events
 
101
Y.Array.each(nativeEvents, function (event) {
 
102
    Y.Event.defineOutside(event);
 
103
});
 
104
 
 
105
 
 
106
}, '3.5.1' ,{requires:['event-synthetic']});