2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
8 YUI.add('event-mouseenter', function(Y) {
11 * <p>Adds subscription and delegation support for mouseenter and mouseleave
12 * events. Unlike mouseover and mouseout, these events aren't fired from child
13 * elements of a subscribed node.</p>
15 * <p>This avoids receiving three mouseover notifications from a setup like</p>
17 * <pre><code>div#container > p > a[href]</code></pre>
21 * <pre><code>Y.one('#container').on('mouseover', callback)</code></pre>
23 * <p>When the mouse moves over the link, one mouseover event is fired from
24 * #container, then when the mouse moves over the p, another mouseover event is
25 * fired and bubbles to #container, causing a second notification, and finally
26 * when the mouse moves over the link, a third mouseover event is fired and
27 * bubbles to #container for a third notification.</p>
29 * <p>By contrast, using mouseenter instead of mouseover, the callback would be
30 * executed only once when the mouse moves over #container.</p>
33 * @submodule event-mouseenter
35 function notify(e, notifier) {
36 var current = e.currentTarget,
37 related = e.relatedTarget;
39 if (current !== related && !current.contains(related)) {
45 proxyType: "mouseover",
47 on: function (node, sub, notifier) {
48 sub.onHandle = node.on(this.proxyType, notify, null, notifier);
51 detach: function (node, sub) {
52 sub.onHandle.detach();
55 delegate: function (node, sub, notifier, filter) {
57 Y.delegate(this.proxyType, notify, node, filter, null, notifier);
60 detachDelegate: function (node, sub) {
61 sub.delegateHandle.detach();
65 Y.Event.define("mouseenter", config, true);
66 Y.Event.define("mouseleave", Y.merge(config, { proxyType: "mouseout" }), true);
69 }, '3.3.0' ,{requires:['event-synthetic']});