3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('event-mouseenter', function(Y) {
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>
14
* <p>This avoids receiving three mouseover notifications from a setup like</p>
16
* <pre><code>div#container > p > a[href]</code></pre>
20
* <pre><code>Y.one('#container').on('mouseover', callback)</code></pre>
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>
28
* <p>By contrast, using mouseenter instead of mouseover, the callback would be
29
* executed only once when the mouse moves over #container.</p>
32
* @submodule event-mouseenter
35
var domEventProxies = Y.Env.evt.dom_wrappers,
36
contains = Y.DOM.contains,
38
noop = function () {},
41
proxyType: "mouseover",
42
relProperty: "fromElement",
44
_notify: function (e, property, notifier) {
46
related = e.relatedTarget || e[property];
48
if (el !== related && !contains(el, related)) {
49
notifier.fire(new Y.DOMEventFacade(e, el,
50
domEventProxies['event:' + Y.stamp(el) + e.type]));
54
on: function (node, sub, notifier) {
55
var el = Y.Node.getDOMNode(node),
64
sub.handle = Y.Event._attach(args, { facade: false });
65
// node.on(this.proxyType, notify, null, notifier);
68
detach: function (node, sub) {
72
delegate: function (node, sub, notifier, filter) {
73
var el = Y.Node.getDOMNode(node),
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;
88
_filterNotify: function (thisObj, args, ce) {
91
args.push.apply(args, this.args);
94
var currentTarget = Y.delegate._applyFilter(this.filter, args, ce),
95
related = args[0].relatedTarget || args[0][this.relProperty],
99
currentTarget = toArray(currentTarget);
101
for (i = 0, len = currentTarget.length && (!e || !e.stopped); i < len; ++i) {
102
ct = currentTarget[0];
103
if (!contains(ct, related)) {
105
e = new Y.DOMEventFacade(args[0], ct, ce);
106
e.container = Y.one(ce.el);
108
e.currentTarget = Y.one(ct);
110
// TODO: where is notifier? args? this.notifier?
111
ret = args[1].fire(e);
123
detachDelegate: function (node, sub) {
128
Y.Event.define("mouseenter", config, true);
129
Y.Event.define("mouseleave", Y.merge(config, {
130
proxyType: "mouseout",
131
relProperty: "toElement"
135
}, '3.5.1' ,{requires:['event-synthetic']});