]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/event/event-mouseenter.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / event / event-mouseenter.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('event-mouseenter', function(Y) {
9
10 /**
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>
14  *
15  * <p>This avoids receiving three mouseover notifications from a setup like</p>
16  *
17  * <pre><code>div#container > p > a[href]</code></pre>
18  *
19  * <p>where</p>
20  *
21  * <pre><code>Y.one('#container').on('mouseover', callback)</code></pre>
22  *
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>
28  *
29  * <p>By contrast, using mouseenter instead of mouseover, the callback would be
30  * executed only once when the mouse moves over #container.</p>
31  *
32  * @module event
33  * @submodule event-mouseenter
34  */
35 function notify(e, notifier) {
36     var current = e.currentTarget,
37         related = e.relatedTarget;
38
39     if (current !== related && !current.contains(related)) {
40         notifier.fire(e);
41     }
42 }
43
44 var config = {
45     proxyType: "mouseover",
46
47     on: function (node, sub, notifier) {
48         sub.onHandle = node.on(this.proxyType, notify, null, notifier);
49     },
50
51     detach: function (node, sub) {
52         sub.onHandle.detach();
53     },
54
55     delegate: function (node, sub, notifier, filter) {
56         sub.delegateHandle =
57             Y.delegate(this.proxyType, notify, node, filter, null, notifier);
58     },
59
60     detachDelegate: function (node, sub) {
61         sub.delegateHandle.detach();
62     }
63 };
64
65 Y.Event.define("mouseenter", config, true);
66 Y.Event.define("mouseleave", Y.merge(config, { proxyType: "mouseout" }), true);
67
68
69 }, '3.3.0' ,{requires:['event-synthetic']});