~andreserl/maas/packaging_precise_rebase

« back to all changes in this revision

Viewing changes to debian/extras/jslibs/yui/event-mouseenter/event-mouseenter.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-mouseenter', function(Y) {
 
8
 
 
9
/**
 
10
 * <p>Adds subscription and delegation support for mouseenter and mouseleave
 
11
 * events.  Unlike mouseover and mouseout, these events aren't fired from child
 
12
 * elements of a subscribed node.</p>
 
13
 *
 
14
 * <p>This avoids receiving three mouseover notifications from a setup like</p>
 
15
 *
 
16
 * <pre><code>div#container > p > a[href]</code></pre>
 
17
 *
 
18
 * <p>where</p>
 
19
 *
 
20
 * <pre><code>Y.one('#container').on('mouseover', callback)</code></pre>
 
21
 *
 
22
 * <p>When the mouse moves over the link, one mouseover event is fired from
 
23
 * #container, then when the mouse moves over the p, another mouseover event is
 
24
 * fired and bubbles to #container, causing a second notification, and finally
 
25
 * when the mouse moves over the link, a third mouseover event is fired and
 
26
 * bubbles to #container for a third notification.</p>
 
27
 *
 
28
 * <p>By contrast, using mouseenter instead of mouseover, the callback would be
 
29
 * executed only once when the mouse moves over #container.</p>
 
30
 *
 
31
 * @module event
 
32
 * @submodule event-mouseenter
 
33
 */
 
34
 
 
35
var domEventProxies = Y.Env.evt.dom_wrappers,
 
36
    contains = Y.DOM.contains,
 
37
    toArray = Y.Array,
 
38
    noop = function () {},
 
39
 
 
40
    config = {
 
41
        proxyType: "mouseover",
 
42
        relProperty: "fromElement",
 
43
 
 
44
        _notify: function (e, property, notifier) {
 
45
            var el = this._node,
 
46
                related = e.relatedTarget || e[property];
 
47
 
 
48
            if (el !== related && !contains(el, related)) {
 
49
                notifier.fire(new Y.DOMEventFacade(e, el,
 
50
                    domEventProxies['event:' + Y.stamp(el) + e.type]));
 
51
            }
 
52
        },
 
53
 
 
54
        on: function (node, sub, notifier) {
 
55
            var el = Y.Node.getDOMNode(node),
 
56
                args = [
 
57
                    this.proxyType,
 
58
                    this._notify,
 
59
                    el,
 
60
                    null,
 
61
                    this.relProperty,
 
62
                    notifier];
 
63
 
 
64
            sub.handle = Y.Event._attach(args, { facade: false });
 
65
            // node.on(this.proxyType, notify, null, notifier);
 
66
        },
 
67
 
 
68
        detach: function (node, sub) {
 
69
            sub.handle.detach();
 
70
        },
 
71
 
 
72
        delegate: function (node, sub, notifier, filter) {
 
73
            var el = Y.Node.getDOMNode(node),
 
74
                args = [
 
75
                    this.proxyType,
 
76
                    noop,
 
77
                    el,
 
78
                    null,
 
79
                    notifier
 
80
                ];
 
81
 
 
82
            sub.handle = Y.Event._attach(args, { facade: false });
 
83
            sub.handle.sub.filter = filter;
 
84
            sub.handle.sub.relProperty = this.relProperty;
 
85
            sub.handle.sub._notify = this._filterNotify;
 
86
        },
 
87
 
 
88
        _filterNotify: function (thisObj, args, ce) {
 
89
            args = args.slice();
 
90
            if (this.args) {
 
91
                args.push.apply(args, this.args);
 
92
            }
 
93
 
 
94
            var currentTarget = Y.delegate._applyFilter(this.filter, args, ce),
 
95
                related = args[0].relatedTarget || args[0][this.relProperty],
 
96
                e, i, len, ret, ct;
 
97
 
 
98
            if (currentTarget) {
 
99
                currentTarget = toArray(currentTarget);
 
100
                
 
101
                for (i = 0, len = currentTarget.length && (!e || !e.stopped); i < len; ++i) {
 
102
                    ct = currentTarget[0];
 
103
                    if (!contains(ct, related)) {
 
104
                        if (!e) {
 
105
                            e = new Y.DOMEventFacade(args[0], ct, ce);
 
106
                            e.container = Y.one(ce.el);
 
107
                        }
 
108
                        e.currentTarget = Y.one(ct);
 
109
 
 
110
                        // TODO: where is notifier? args? this.notifier?
 
111
                        ret = args[1].fire(e);
 
112
 
 
113
                        if (ret === false) {
 
114
                            break;
 
115
                        }
 
116
                    }
 
117
                }
 
118
            }
 
119
 
 
120
            return ret;
 
121
        },
 
122
 
 
123
        detachDelegate: function (node, sub) {
 
124
            sub.handle.detach();
 
125
        }
 
126
    };
 
127
 
 
128
Y.Event.define("mouseenter", config, true);
 
129
Y.Event.define("mouseleave", Y.merge(config, {
 
130
    proxyType: "mouseout",
 
131
    relProperty: "toElement"
 
132
}), true);
 
133
 
 
134
 
 
135
}, '3.5.1' ,{requires:['event-synthetic']});