comparison rhodecode/public/js/yui/event-mouseenter/event-mouseenter.js @ 547:1e757ac98988

renamed project to rhodecode
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 06 Oct 2010 03:18:16 +0200
parents pylons_app/public/js/yui/event-mouseenter/event-mouseenter.js@564e40829f80
children 289ff43cc190
comparison
equal deleted inserted replaced
546:7c2f5e4d7bbf 547:1e757ac98988
1 /*
2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
5 version: 2.8.0r4
6 */
7 /**
8 * Augments the Event Utility with support for the mouseenter and mouseleave
9 * events: A mouseenter event fires the first time the mouse enters an
10 * element; a mouseleave event first the first time the mouse leaves an
11 * element.
12 *
13 * @module event-mouseenter
14 * @title Event Utility mouseenter and mouseout Module
15 * @namespace YAHOO.util
16 * @requires event
17 */
18
19 (function () {
20
21 var Event = YAHOO.util.Event,
22 Lang = YAHOO.lang,
23
24 addListener = Event.addListener,
25 removeListener = Event.removeListener,
26 getListeners = Event.getListeners,
27
28 delegates = [],
29
30 specialTypes = {
31 mouseenter: "mouseover",
32 mouseleave: "mouseout"
33 },
34
35 remove = function(el, type, fn) {
36
37 var index = Event._getCacheIndex(delegates, el, type, fn),
38 cacheItem,
39 returnVal;
40
41 if (index >= 0) {
42 cacheItem = delegates[index];
43 }
44
45 if (el && cacheItem) {
46
47 // removeListener will translate the value of type
48 returnVal = removeListener.call(Event, cacheItem[0], type, cacheItem[3]);
49
50 if (returnVal) {
51 delete delegates[index][2];
52 delete delegates[index][3];
53 delegates.splice(index, 1);
54 }
55
56 }
57
58 return returnVal;
59
60 };
61
62
63 Lang.augmentObject(Event._specialTypes, specialTypes);
64
65 Lang.augmentObject(Event, {
66
67 /**
68 * Creates a delegate function used to call mouseover and mouseleave
69 * event listeners specified via the
70 * <code>YAHOO.util.Event.addListener</code>
71 * or <code>YAHOO.util.Event.on</code> method.
72 *
73 * @method _createMouseDelegate
74 *
75 * @param {Function} fn The method (event listener) to call
76 * @param {Object} obj An arbitrary object that will be
77 * passed as a parameter to the listener
78 * @param {Boolean|object} overrideContext If true, the value of the
79 * obj parameter becomes the execution context
80 * of the listener. If an object, this object
81 * becomes the execution context.
82 * @return {Function} Function that will call the event listener
83 * specified by either the <code>YAHOO.util.Event.addListener</code>
84 * or <code>YAHOO.util.Event.on</code> method.
85 * @private
86 * @static
87 * @for Event
88 */
89 _createMouseDelegate: function (fn, obj, overrideContext) {
90
91 return function (event, container) {
92
93 var el = this,
94 relatedTarget = Event.getRelatedTarget(event),
95 context,
96 args;
97
98 if (el != relatedTarget && !YAHOO.util.Dom.isAncestor(el, relatedTarget)) {
99
100 context = el;
101
102 if (overrideContext) {
103 if (overrideContext === true) {
104 context = obj;
105 } else {
106 context = overrideContext;
107 }
108 }
109
110 // The default args passed back to a mouseenter or
111 // mouseleave listener are: the event, the element
112 // to which the listener is bound, and any object the
113 // user passed when subscribing
114
115 args = [event, el, obj];
116
117 // Add the delegation container as an argument when
118 // delegating mouseenter and mouseleave
119
120 if (container) {
121 args.splice(2, 0, container);
122 }
123
124 return fn.apply(context, args);
125
126 }
127
128 };
129
130 },
131
132 addListener: function (el, type, fn, obj, overrideContext) {
133
134 var fnDelegate,
135 returnVal;
136
137 if (specialTypes[type]) {
138
139 fnDelegate = Event._createMouseDelegate(fn, obj, overrideContext);
140
141 fnDelegate.mouseDelegate = true;
142
143 delegates.push([el, type, fn, fnDelegate]);
144
145 // addListener will translate the value of type
146 returnVal = addListener.call(Event, el, type, fnDelegate);
147
148 }
149 else {
150 returnVal = addListener.apply(Event, arguments);
151 }
152
153 return returnVal;
154
155 },
156
157 removeListener: function (el, type, fn) {
158
159 var returnVal;
160
161 if (specialTypes[type]) {
162 returnVal = remove.apply(Event, arguments);
163 }
164 else {
165 returnVal = removeListener.apply(Event, arguments);
166 }
167
168 return returnVal;
169
170 },
171
172 getListeners: function (el, type) {
173
174 // If the user specified the type as mouseover or mouseout,
175 // need to filter out those used by mouseenter and mouseleave.
176 // If the user specified the type as mouseenter or mouseleave,
177 // need to filter out the true mouseover and mouseout listeners.
178
179 var listeners = [],
180 elListeners,
181 bMouseOverOrOut = (type === "mouseover" || type === "mouseout"),
182 bMouseDelegate,
183 i,
184 l;
185
186 if (type && (bMouseOverOrOut || specialTypes[type])) {
187
188 elListeners = getListeners.call(Event, el, this._getType(type));
189
190 if (elListeners) {
191
192 for (i=elListeners.length-1; i>-1; i--) {
193
194 l = elListeners[i];
195 bMouseDelegate = l.fn.mouseDelegate;
196
197 if ((specialTypes[type] && bMouseDelegate) || (bMouseOverOrOut && !bMouseDelegate)) {
198 listeners.push(l);
199 }
200
201 }
202
203 }
204
205 }
206 else {
207 listeners = getListeners.apply(Event, arguments);
208 }
209
210 return (listeners && listeners.length) ? listeners : null;
211
212 }
213
214 }, true);
215
216 Event.on = Event.addListener;
217
218 }());
219 YAHOO.register("event-mouseenter", YAHOO.util.Event, {version: "2.8.0r4", build: "2449"});