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