|
525
|
1 |
/* |
|
|
2 |
YUI 3.10.3 (build 2fb5187) |
|
|
3 |
Copyright 2013 Yahoo! Inc. All rights reserved. |
|
|
4 |
Licensed under the BSD License. |
|
|
5 |
http://yuilibrary.com/license/ |
|
|
6 |
*/ |
|
|
7 |
|
|
|
8 |
(function () { |
|
|
9 |
var GLOBAL_ENV = YUI.Env; |
|
|
10 |
|
|
|
11 |
if (!GLOBAL_ENV._ready) { |
|
|
12 |
GLOBAL_ENV._ready = function() { |
|
|
13 |
GLOBAL_ENV.DOMReady = true; |
|
|
14 |
GLOBAL_ENV.remove(YUI.config.doc, 'DOMContentLoaded', GLOBAL_ENV._ready); |
|
|
15 |
}; |
|
|
16 |
|
|
|
17 |
GLOBAL_ENV.add(YUI.config.doc, 'DOMContentLoaded', GLOBAL_ENV._ready); |
|
|
18 |
} |
|
|
19 |
})(); |
|
|
20 |
YUI.add('event-base', function (Y, NAME) { |
|
|
21 |
|
|
|
22 |
/* |
|
|
23 |
* DOM event listener abstraction layer |
|
|
24 |
* @module event |
|
|
25 |
* @submodule event-base |
|
|
26 |
*/ |
|
|
27 |
|
|
|
28 |
/** |
|
|
29 |
* The domready event fires at the moment the browser's DOM is |
|
|
30 |
* usable. In most cases, this is before images are fully |
|
|
31 |
* downloaded, allowing you to provide a more responsive user |
|
|
32 |
* interface. |
|
|
33 |
* |
|
|
34 |
* In YUI 3, domready subscribers will be notified immediately if |
|
|
35 |
* that moment has already passed when the subscription is created. |
|
|
36 |
* |
|
|
37 |
* One exception is if the yui.js file is dynamically injected into |
|
|
38 |
* the page. If this is done, you must tell the YUI instance that |
|
|
39 |
* you did this in order for DOMReady (and window load events) to |
|
|
40 |
* fire normally. That configuration option is 'injected' -- set |
|
|
41 |
* it to true if the yui.js script is not included inline. |
|
|
42 |
* |
|
|
43 |
* This method is part of the 'event-ready' module, which is a |
|
|
44 |
* submodule of 'event'. |
|
|
45 |
* |
|
|
46 |
* @event domready |
|
|
47 |
* @for YUI |
|
|
48 |
*/ |
|
|
49 |
Y.publish('domready', { |
|
|
50 |
fireOnce: true, |
|
|
51 |
async: true |
|
|
52 |
}); |
|
|
53 |
|
|
|
54 |
if (YUI.Env.DOMReady) { |
|
|
55 |
Y.fire('domready'); |
|
|
56 |
} else { |
|
|
57 |
Y.Do.before(function() { Y.fire('domready'); }, YUI.Env, '_ready'); |
|
|
58 |
} |
|
|
59 |
|
|
|
60 |
/** |
|
|
61 |
* Custom event engine, DOM event listener abstraction layer, synthetic DOM |
|
|
62 |
* events. |
|
|
63 |
* @module event |
|
|
64 |
* @submodule event-base |
|
|
65 |
*/ |
|
|
66 |
|
|
|
67 |
/** |
|
|
68 |
* Wraps a DOM event, properties requiring browser abstraction are |
|
|
69 |
* fixed here. Provids a security layer when required. |
|
|
70 |
* @class DOMEventFacade |
|
|
71 |
* @param ev {Event} the DOM event |
|
|
72 |
* @param currentTarget {HTMLElement} the element the listener was attached to |
|
|
73 |
* @param wrapper {Event.Custom} the custom event wrapper for this DOM event |
|
|
74 |
*/ |
|
|
75 |
|
|
|
76 |
var ua = Y.UA, |
|
|
77 |
|
|
|
78 |
EMPTY = {}, |
|
|
79 |
|
|
|
80 |
/** |
|
|
81 |
* webkit key remapping required for Safari < 3.1 |
|
|
82 |
* @property webkitKeymap |
|
|
83 |
* @private |
|
|
84 |
*/ |
|
|
85 |
webkitKeymap = { |
|
|
86 |
63232: 38, // up |
|
|
87 |
63233: 40, // down |
|
|
88 |
63234: 37, // left |
|
|
89 |
63235: 39, // right |
|
|
90 |
63276: 33, // page up |
|
|
91 |
63277: 34, // page down |
|
|
92 |
25: 9, // SHIFT-TAB (Safari provides a different key code in |
|
|
93 |
// this case, even though the shiftKey modifier is set) |
|
|
94 |
63272: 46, // delete |
|
|
95 |
63273: 36, // home |
|
|
96 |
63275: 35 // end |
|
|
97 |
}, |
|
|
98 |
|
|
|
99 |
/** |
|
|
100 |
* Returns a wrapped node. Intended to be used on event targets, |
|
|
101 |
* so it will return the node's parent if the target is a text |
|
|
102 |
* node. |
|
|
103 |
* |
|
|
104 |
* If accessing a property of the node throws an error, this is |
|
|
105 |
* probably the anonymous div wrapper Gecko adds inside text |
|
|
106 |
* nodes. This likely will only occur when attempting to access |
|
|
107 |
* the relatedTarget. In this case, we now return null because |
|
|
108 |
* the anonymous div is completely useless and we do not know |
|
|
109 |
* what the related target was because we can't even get to |
|
|
110 |
* the element's parent node. |
|
|
111 |
* |
|
|
112 |
* @method resolve |
|
|
113 |
* @private |
|
|
114 |
*/ |
|
|
115 |
resolve = function(n) { |
|
|
116 |
if (!n) { |
|
|
117 |
return n; |
|
|
118 |
} |
|
|
119 |
try { |
|
|
120 |
if (n && 3 == n.nodeType) { |
|
|
121 |
n = n.parentNode; |
|
|
122 |
} |
|
|
123 |
} catch(e) { |
|
|
124 |
return null; |
|
|
125 |
} |
|
|
126 |
|
|
|
127 |
return Y.one(n); |
|
|
128 |
}, |
|
|
129 |
|
|
|
130 |
DOMEventFacade = function(ev, currentTarget, wrapper) { |
|
|
131 |
this._event = ev; |
|
|
132 |
this._currentTarget = currentTarget; |
|
|
133 |
this._wrapper = wrapper || EMPTY; |
|
|
134 |
|
|
|
135 |
// if not lazy init |
|
|
136 |
this.init(); |
|
|
137 |
}; |
|
|
138 |
|
|
|
139 |
Y.extend(DOMEventFacade, Object, { |
|
|
140 |
|
|
|
141 |
init: function() { |
|
|
142 |
|
|
|
143 |
var e = this._event, |
|
|
144 |
overrides = this._wrapper.overrides, |
|
|
145 |
x = e.pageX, |
|
|
146 |
y = e.pageY, |
|
|
147 |
c, |
|
|
148 |
currentTarget = this._currentTarget; |
|
|
149 |
|
|
|
150 |
this.altKey = e.altKey; |
|
|
151 |
this.ctrlKey = e.ctrlKey; |
|
|
152 |
this.metaKey = e.metaKey; |
|
|
153 |
this.shiftKey = e.shiftKey; |
|
|
154 |
this.type = (overrides && overrides.type) || e.type; |
|
|
155 |
this.clientX = e.clientX; |
|
|
156 |
this.clientY = e.clientY; |
|
|
157 |
|
|
|
158 |
this.pageX = x; |
|
|
159 |
this.pageY = y; |
|
|
160 |
|
|
|
161 |
// charCode is unknown in keyup, keydown. keyCode is unknown in keypress. |
|
|
162 |
// FF 3.6 - 8+? pass 0 for keyCode in keypress events. |
|
|
163 |
// Webkit, FF 3.6-8+?, and IE9+? pass 0 for charCode in keydown, keyup. |
|
|
164 |
// Webkit and IE9+? duplicate charCode in keyCode. |
|
|
165 |
// Opera never sets charCode, always keyCode (though with the charCode). |
|
|
166 |
// IE6-8 don't set charCode or which. |
|
|
167 |
// All browsers other than IE6-8 set which=keyCode in keydown, keyup, and |
|
|
168 |
// which=charCode in keypress. |
|
|
169 |
// |
|
|
170 |
// Moral of the story: (e.which || e.keyCode) will always return the |
|
|
171 |
// known code for that key event phase. e.keyCode is often different in |
|
|
172 |
// keypress from keydown and keyup. |
|
|
173 |
c = e.keyCode || e.charCode; |
|
|
174 |
|
|
|
175 |
if (ua.webkit && (c in webkitKeymap)) { |
|
|
176 |
c = webkitKeymap[c]; |
|
|
177 |
} |
|
|
178 |
|
|
|
179 |
this.keyCode = c; |
|
|
180 |
this.charCode = c; |
|
|
181 |
// Fill in e.which for IE - implementers should always use this over |
|
|
182 |
// e.keyCode or e.charCode. |
|
|
183 |
this.which = e.which || e.charCode || c; |
|
|
184 |
// this.button = e.button; |
|
|
185 |
this.button = this.which; |
|
|
186 |
|
|
|
187 |
this.target = resolve(e.target); |
|
|
188 |
this.currentTarget = resolve(currentTarget); |
|
|
189 |
this.relatedTarget = resolve(e.relatedTarget); |
|
|
190 |
|
|
|
191 |
if (e.type == "mousewheel" || e.type == "DOMMouseScroll") { |
|
|
192 |
this.wheelDelta = (e.detail) ? (e.detail * -1) : Math.round(e.wheelDelta / 80) || ((e.wheelDelta < 0) ? -1 : 1); |
|
|
193 |
} |
|
|
194 |
|
|
|
195 |
if (this._touch) { |
|
|
196 |
this._touch(e, currentTarget, this._wrapper); |
|
|
197 |
} |
|
|
198 |
}, |
|
|
199 |
|
|
|
200 |
stopPropagation: function() { |
|
|
201 |
this._event.stopPropagation(); |
|
|
202 |
this._wrapper.stopped = 1; |
|
|
203 |
this.stopped = 1; |
|
|
204 |
}, |
|
|
205 |
|
|
|
206 |
stopImmediatePropagation: function() { |
|
|
207 |
var e = this._event; |
|
|
208 |
if (e.stopImmediatePropagation) { |
|
|
209 |
e.stopImmediatePropagation(); |
|
|
210 |
} else { |
|
|
211 |
this.stopPropagation(); |
|
|
212 |
} |
|
|
213 |
this._wrapper.stopped = 2; |
|
|
214 |
this.stopped = 2; |
|
|
215 |
}, |
|
|
216 |
|
|
|
217 |
preventDefault: function(returnValue) { |
|
|
218 |
var e = this._event; |
|
|
219 |
e.preventDefault(); |
|
|
220 |
e.returnValue = returnValue || false; |
|
|
221 |
this._wrapper.prevented = 1; |
|
|
222 |
this.prevented = 1; |
|
|
223 |
}, |
|
|
224 |
|
|
|
225 |
halt: function(immediate) { |
|
|
226 |
if (immediate) { |
|
|
227 |
this.stopImmediatePropagation(); |
|
|
228 |
} else { |
|
|
229 |
this.stopPropagation(); |
|
|
230 |
} |
|
|
231 |
|
|
|
232 |
this.preventDefault(); |
|
|
233 |
} |
|
|
234 |
|
|
|
235 |
}); |
|
|
236 |
|
|
|
237 |
DOMEventFacade.resolve = resolve; |
|
|
238 |
Y.DOM2EventFacade = DOMEventFacade; |
|
|
239 |
Y.DOMEventFacade = DOMEventFacade; |
|
|
240 |
|
|
|
241 |
/** |
|
|
242 |
* The native event |
|
|
243 |
* @property _event |
|
|
244 |
* @type {Native DOM Event} |
|
|
245 |
* @private |
|
|
246 |
*/ |
|
|
247 |
|
|
|
248 |
/** |
|
|
249 |
The name of the event (e.g. "click") |
|
|
250 |
|
|
|
251 |
@property type |
|
|
252 |
@type {String} |
|
|
253 |
**/ |
|
|
254 |
|
|
|
255 |
/** |
|
|
256 |
`true` if the "alt" or "option" key is pressed. |
|
|
257 |
|
|
|
258 |
@property altKey |
|
|
259 |
@type {Boolean} |
|
|
260 |
**/ |
|
|
261 |
|
|
|
262 |
/** |
|
|
263 |
`true` if the shift key is pressed. |
|
|
264 |
|
|
|
265 |
@property shiftKey |
|
|
266 |
@type {Boolean} |
|
|
267 |
**/ |
|
|
268 |
|
|
|
269 |
/** |
|
|
270 |
`true` if the "Windows" key on a Windows keyboard, "command" key on an |
|
|
271 |
Apple keyboard, or "meta" key on other keyboards is pressed. |
|
|
272 |
|
|
|
273 |
@property metaKey |
|
|
274 |
@type {Boolean} |
|
|
275 |
**/ |
|
|
276 |
|
|
|
277 |
/** |
|
|
278 |
`true` if the "Ctrl" or "control" key is pressed. |
|
|
279 |
|
|
|
280 |
@property ctrlKey |
|
|
281 |
@type {Boolean} |
|
|
282 |
**/ |
|
|
283 |
|
|
|
284 |
/** |
|
|
285 |
* The X location of the event on the page (including scroll) |
|
|
286 |
* @property pageX |
|
|
287 |
* @type {Number} |
|
|
288 |
*/ |
|
|
289 |
|
|
|
290 |
/** |
|
|
291 |
* The Y location of the event on the page (including scroll) |
|
|
292 |
* @property pageY |
|
|
293 |
* @type {Number} |
|
|
294 |
*/ |
|
|
295 |
|
|
|
296 |
/** |
|
|
297 |
* The X location of the event in the viewport |
|
|
298 |
* @property clientX |
|
|
299 |
* @type {Number} |
|
|
300 |
*/ |
|
|
301 |
|
|
|
302 |
/** |
|
|
303 |
* The Y location of the event in the viewport |
|
|
304 |
* @property clientY |
|
|
305 |
* @type {Number} |
|
|
306 |
*/ |
|
|
307 |
|
|
|
308 |
/** |
|
|
309 |
* The keyCode for key events. Uses charCode if keyCode is not available |
|
|
310 |
* @property keyCode |
|
|
311 |
* @type {Number} |
|
|
312 |
*/ |
|
|
313 |
|
|
|
314 |
/** |
|
|
315 |
* The charCode for key events. Same as keyCode |
|
|
316 |
* @property charCode |
|
|
317 |
* @type {Number} |
|
|
318 |
*/ |
|
|
319 |
|
|
|
320 |
/** |
|
|
321 |
* The button that was pushed. 1 for left click, 2 for middle click, 3 for |
|
|
322 |
* right click. This is only reliably populated on `mouseup` events. |
|
|
323 |
* @property button |
|
|
324 |
* @type {Number} |
|
|
325 |
*/ |
|
|
326 |
|
|
|
327 |
/** |
|
|
328 |
* The button that was pushed. Same as button. |
|
|
329 |
* @property which |
|
|
330 |
* @type {Number} |
|
|
331 |
*/ |
|
|
332 |
|
|
|
333 |
/** |
|
|
334 |
* Node reference for the targeted element |
|
|
335 |
* @property target |
|
|
336 |
* @type {Node} |
|
|
337 |
*/ |
|
|
338 |
|
|
|
339 |
/** |
|
|
340 |
* Node reference for the element that the listener was attached to. |
|
|
341 |
* @property currentTarget |
|
|
342 |
* @type {Node} |
|
|
343 |
*/ |
|
|
344 |
|
|
|
345 |
/** |
|
|
346 |
* Node reference to the relatedTarget |
|
|
347 |
* @property relatedTarget |
|
|
348 |
* @type {Node} |
|
|
349 |
*/ |
|
|
350 |
|
|
|
351 |
/** |
|
|
352 |
* Number representing the direction and velocity of the movement of the mousewheel. |
|
|
353 |
* Negative is down, the higher the number, the faster. Applies to the mousewheel event. |
|
|
354 |
* @property wheelDelta |
|
|
355 |
* @type {Number} |
|
|
356 |
*/ |
|
|
357 |
|
|
|
358 |
/** |
|
|
359 |
* Stops the propagation to the next bubble target |
|
|
360 |
* @method stopPropagation |
|
|
361 |
*/ |
|
|
362 |
|
|
|
363 |
/** |
|
|
364 |
* Stops the propagation to the next bubble target and |
|
|
365 |
* prevents any additional listeners from being exectued |
|
|
366 |
* on the current target. |
|
|
367 |
* @method stopImmediatePropagation |
|
|
368 |
*/ |
|
|
369 |
|
|
|
370 |
/** |
|
|
371 |
* Prevents the event's default behavior |
|
|
372 |
* @method preventDefault |
|
|
373 |
* @param returnValue {string} sets the returnValue of the event to this value |
|
|
374 |
* (rather than the default false value). This can be used to add a customized |
|
|
375 |
* confirmation query to the beforeunload event). |
|
|
376 |
*/ |
|
|
377 |
|
|
|
378 |
/** |
|
|
379 |
* Stops the event propagation and prevents the default |
|
|
380 |
* event behavior. |
|
|
381 |
* @method halt |
|
|
382 |
* @param immediate {boolean} if true additional listeners |
|
|
383 |
* on the current target will not be executed |
|
|
384 |
*/ |
|
|
385 |
(function() { |
|
|
386 |
|
|
|
387 |
/** |
|
|
388 |
* The event utility provides functions to add and remove event listeners, |
|
|
389 |
* event cleansing. It also tries to automatically remove listeners it |
|
|
390 |
* registers during the unload event. |
|
|
391 |
* @module event |
|
|
392 |
* @main event |
|
|
393 |
* @submodule event-base |
|
|
394 |
*/ |
|
|
395 |
|
|
|
396 |
/** |
|
|
397 |
* The event utility provides functions to add and remove event listeners, |
|
|
398 |
* event cleansing. It also tries to automatically remove listeners it |
|
|
399 |
* registers during the unload event. |
|
|
400 |
* |
|
|
401 |
* @class Event |
|
|
402 |
* @static |
|
|
403 |
*/ |
|
|
404 |
|
|
|
405 |
Y.Env.evt.dom_wrappers = {}; |
|
|
406 |
Y.Env.evt.dom_map = {}; |
|
|
407 |
|
|
|
408 |
var _eventenv = Y.Env.evt, |
|
|
409 |
config = Y.config, |
|
|
410 |
win = config.win, |
|
|
411 |
add = YUI.Env.add, |
|
|
412 |
remove = YUI.Env.remove, |
|
|
413 |
|
|
|
414 |
onLoad = function() { |
|
|
415 |
YUI.Env.windowLoaded = true; |
|
|
416 |
Y.Event._load(); |
|
|
417 |
remove(win, "load", onLoad); |
|
|
418 |
}, |
|
|
419 |
|
|
|
420 |
onUnload = function() { |
|
|
421 |
Y.Event._unload(); |
|
|
422 |
}, |
|
|
423 |
|
|
|
424 |
EVENT_READY = 'domready', |
|
|
425 |
|
|
|
426 |
COMPAT_ARG = '~yui|2|compat~', |
|
|
427 |
|
|
|
428 |
shouldIterate = function(o) { |
|
|
429 |
try { |
|
|
430 |
// TODO: See if there's a more performant way to return true early on this, for the common case |
|
|
431 |
return (o && typeof o !== "string" && Y.Lang.isNumber(o.length) && !o.tagName && !Y.DOM.isWindow(o)); |
|
|
432 |
} catch(ex) { |
|
|
433 |
return false; |
|
|
434 |
} |
|
|
435 |
}, |
|
|
436 |
|
|
|
437 |
// aliases to support DOM event subscription clean up when the last |
|
|
438 |
// subscriber is detached. deleteAndClean overrides the DOM event's wrapper |
|
|
439 |
// CustomEvent _delete method. |
|
|
440 |
_ceProtoDelete = Y.CustomEvent.prototype._delete, |
|
|
441 |
_deleteAndClean = function(s) { |
|
|
442 |
var ret = _ceProtoDelete.apply(this, arguments); |
|
|
443 |
|
|
|
444 |
if (!this.hasSubs()) { |
|
|
445 |
Y.Event._clean(this); |
|
|
446 |
} |
|
|
447 |
|
|
|
448 |
return ret; |
|
|
449 |
}, |
|
|
450 |
|
|
|
451 |
Event = function() { |
|
|
452 |
|
|
|
453 |
/** |
|
|
454 |
* True after the onload event has fired |
|
|
455 |
* @property _loadComplete |
|
|
456 |
* @type boolean |
|
|
457 |
* @static |
|
|
458 |
* @private |
|
|
459 |
*/ |
|
|
460 |
var _loadComplete = false, |
|
|
461 |
|
|
|
462 |
/** |
|
|
463 |
* The number of times to poll after window.onload. This number is |
|
|
464 |
* increased if additional late-bound handlers are requested after |
|
|
465 |
* the page load. |
|
|
466 |
* @property _retryCount |
|
|
467 |
* @static |
|
|
468 |
* @private |
|
|
469 |
*/ |
|
|
470 |
_retryCount = 0, |
|
|
471 |
|
|
|
472 |
/** |
|
|
473 |
* onAvailable listeners |
|
|
474 |
* @property _avail |
|
|
475 |
* @static |
|
|
476 |
* @private |
|
|
477 |
*/ |
|
|
478 |
_avail = [], |
|
|
479 |
|
|
|
480 |
/** |
|
|
481 |
* Custom event wrappers for DOM events. Key is |
|
|
482 |
* 'event:' + Element uid stamp + event type |
|
|
483 |
* @property _wrappers |
|
|
484 |
* @type Y.Event.Custom |
|
|
485 |
* @static |
|
|
486 |
* @private |
|
|
487 |
*/ |
|
|
488 |
_wrappers = _eventenv.dom_wrappers, |
|
|
489 |
|
|
|
490 |
_windowLoadKey = null, |
|
|
491 |
|
|
|
492 |
/** |
|
|
493 |
* Custom event wrapper map DOM events. Key is |
|
|
494 |
* Element uid stamp. Each item is a hash of custom event |
|
|
495 |
* wrappers as provided in the _wrappers collection. This |
|
|
496 |
* provides the infrastructure for getListeners. |
|
|
497 |
* @property _el_events |
|
|
498 |
* @static |
|
|
499 |
* @private |
|
|
500 |
*/ |
|
|
501 |
_el_events = _eventenv.dom_map; |
|
|
502 |
|
|
|
503 |
return { |
|
|
504 |
|
|
|
505 |
/** |
|
|
506 |
* The number of times we should look for elements that are not |
|
|
507 |
* in the DOM at the time the event is requested after the document |
|
|
508 |
* has been loaded. The default is 1000@amp;40 ms, so it will poll |
|
|
509 |
* for 40 seconds or until all outstanding handlers are bound |
|
|
510 |
* (whichever comes first). |
|
|
511 |
* @property POLL_RETRYS |
|
|
512 |
* @type int |
|
|
513 |
* @static |
|
|
514 |
* @final |
|
|
515 |
*/ |
|
|
516 |
POLL_RETRYS: 1000, |
|
|
517 |
|
|
|
518 |
/** |
|
|
519 |
* The poll interval in milliseconds |
|
|
520 |
* @property POLL_INTERVAL |
|
|
521 |
* @type int |
|
|
522 |
* @static |
|
|
523 |
* @final |
|
|
524 |
*/ |
|
|
525 |
POLL_INTERVAL: 40, |
|
|
526 |
|
|
|
527 |
/** |
|
|
528 |
* addListener/removeListener can throw errors in unexpected scenarios. |
|
|
529 |
* These errors are suppressed, the method returns false, and this property |
|
|
530 |
* is set |
|
|
531 |
* @property lastError |
|
|
532 |
* @static |
|
|
533 |
* @type Error |
|
|
534 |
*/ |
|
|
535 |
lastError: null, |
|
|
536 |
|
|
|
537 |
|
|
|
538 |
/** |
|
|
539 |
* poll handle |
|
|
540 |
* @property _interval |
|
|
541 |
* @static |
|
|
542 |
* @private |
|
|
543 |
*/ |
|
|
544 |
_interval: null, |
|
|
545 |
|
|
|
546 |
/** |
|
|
547 |
* document readystate poll handle |
|
|
548 |
* @property _dri |
|
|
549 |
* @static |
|
|
550 |
* @private |
|
|
551 |
*/ |
|
|
552 |
_dri: null, |
|
|
553 |
|
|
|
554 |
/** |
|
|
555 |
* True when the document is initially usable |
|
|
556 |
* @property DOMReady |
|
|
557 |
* @type boolean |
|
|
558 |
* @static |
|
|
559 |
*/ |
|
|
560 |
DOMReady: false, |
|
|
561 |
|
|
|
562 |
/** |
|
|
563 |
* @method startInterval |
|
|
564 |
* @static |
|
|
565 |
* @private |
|
|
566 |
*/ |
|
|
567 |
startInterval: function() { |
|
|
568 |
if (!Event._interval) { |
|
|
569 |
Event._interval = setInterval(Event._poll, Event.POLL_INTERVAL); |
|
|
570 |
} |
|
|
571 |
}, |
|
|
572 |
|
|
|
573 |
/** |
|
|
574 |
* Executes the supplied callback when the item with the supplied |
|
|
575 |
* id is found. This is meant to be used to execute behavior as |
|
|
576 |
* soon as possible as the page loads. If you use this after the |
|
|
577 |
* initial page load it will poll for a fixed time for the element. |
|
|
578 |
* The number of times it will poll and the frequency are |
|
|
579 |
* configurable. By default it will poll for 10 seconds. |
|
|
580 |
* |
|
|
581 |
* <p>The callback is executed with a single parameter: |
|
|
582 |
* the custom object parameter, if provided.</p> |
|
|
583 |
* |
|
|
584 |
* @method onAvailable |
|
|
585 |
* |
|
|
586 |
* @param {string||string[]} id the id of the element, or an array |
|
|
587 |
* of ids to look for. |
|
|
588 |
* @param {function} fn what to execute when the element is found. |
|
|
589 |
* @param {object} p_obj an optional object to be passed back as |
|
|
590 |
* a parameter to fn. |
|
|
591 |
* @param {boolean|object} p_override If set to true, fn will execute |
|
|
592 |
* in the context of p_obj, if set to an object it |
|
|
593 |
* will execute in the context of that object |
|
|
594 |
* @param checkContent {boolean} check child node readiness (onContentReady) |
|
|
595 |
* @static |
|
|
596 |
* @deprecated Use Y.on("available") |
|
|
597 |
*/ |
|
|
598 |
// @TODO fix arguments |
|
|
599 |
onAvailable: function(id, fn, p_obj, p_override, checkContent, compat) { |
|
|
600 |
|
|
|
601 |
var a = Y.Array(id), i, availHandle; |
|
|
602 |
|
|
|
603 |
|
|
|
604 |
for (i=0; i<a.length; i=i+1) { |
|
|
605 |
_avail.push({ |
|
|
606 |
id: a[i], |
|
|
607 |
fn: fn, |
|
|
608 |
obj: p_obj, |
|
|
609 |
override: p_override, |
|
|
610 |
checkReady: checkContent, |
|
|
611 |
compat: compat |
|
|
612 |
}); |
|
|
613 |
} |
|
|
614 |
_retryCount = this.POLL_RETRYS; |
|
|
615 |
|
|
|
616 |
// We want the first test to be immediate, but async |
|
|
617 |
setTimeout(Event._poll, 0); |
|
|
618 |
|
|
|
619 |
availHandle = new Y.EventHandle({ |
|
|
620 |
|
|
|
621 |
_delete: function() { |
|
|
622 |
// set by the event system for lazy DOM listeners |
|
|
623 |
if (availHandle.handle) { |
|
|
624 |
availHandle.handle.detach(); |
|
|
625 |
return; |
|
|
626 |
} |
|
|
627 |
|
|
|
628 |
var i, j; |
|
|
629 |
|
|
|
630 |
// otherwise try to remove the onAvailable listener(s) |
|
|
631 |
for (i = 0; i < a.length; i++) { |
|
|
632 |
for (j = 0; j < _avail.length; j++) { |
|
|
633 |
if (a[i] === _avail[j].id) { |
|
|
634 |
_avail.splice(j, 1); |
|
|
635 |
} |
|
|
636 |
} |
|
|
637 |
} |
|
|
638 |
} |
|
|
639 |
|
|
|
640 |
}); |
|
|
641 |
|
|
|
642 |
return availHandle; |
|
|
643 |
}, |
|
|
644 |
|
|
|
645 |
/** |
|
|
646 |
* Works the same way as onAvailable, but additionally checks the |
|
|
647 |
* state of sibling elements to determine if the content of the |
|
|
648 |
* available element is safe to modify. |
|
|
649 |
* |
|
|
650 |
* <p>The callback is executed with a single parameter: |
|
|
651 |
* the custom object parameter, if provided.</p> |
|
|
652 |
* |
|
|
653 |
* @method onContentReady |
|
|
654 |
* |
|
|
655 |
* @param {string} id the id of the element to look for. |
|
|
656 |
* @param {function} fn what to execute when the element is ready. |
|
|
657 |
* @param {object} obj an optional object to be passed back as |
|
|
658 |
* a parameter to fn. |
|
|
659 |
* @param {boolean|object} override If set to true, fn will execute |
|
|
660 |
* in the context of p_obj. If an object, fn will |
|
|
661 |
* exectute in the context of that object |
|
|
662 |
* |
|
|
663 |
* @static |
|
|
664 |
* @deprecated Use Y.on("contentready") |
|
|
665 |
*/ |
|
|
666 |
// @TODO fix arguments |
|
|
667 |
onContentReady: function(id, fn, obj, override, compat) { |
|
|
668 |
return Event.onAvailable(id, fn, obj, override, true, compat); |
|
|
669 |
}, |
|
|
670 |
|
|
|
671 |
/** |
|
|
672 |
* Adds an event listener |
|
|
673 |
* |
|
|
674 |
* @method attach |
|
|
675 |
* |
|
|
676 |
* @param {String} type The type of event to append |
|
|
677 |
* @param {Function} fn The method the event invokes |
|
|
678 |
* @param {String|HTMLElement|Array|NodeList} el An id, an element |
|
|
679 |
* reference, or a collection of ids and/or elements to assign the |
|
|
680 |
* listener to. |
|
|
681 |
* @param {Object} context optional context object |
|
|
682 |
* @param {Boolean|object} args 0..n arguments to pass to the callback |
|
|
683 |
* @return {EventHandle} an object to that can be used to detach the listener |
|
|
684 |
* |
|
|
685 |
* @static |
|
|
686 |
*/ |
|
|
687 |
|
|
|
688 |
attach: function(type, fn, el, context) { |
|
|
689 |
return Event._attach(Y.Array(arguments, 0, true)); |
|
|
690 |
}, |
|
|
691 |
|
|
|
692 |
_createWrapper: function (el, type, capture, compat, facade) { |
|
|
693 |
|
|
|
694 |
var cewrapper, |
|
|
695 |
ek = Y.stamp(el), |
|
|
696 |
key = 'event:' + ek + type; |
|
|
697 |
|
|
|
698 |
if (false === facade) { |
|
|
699 |
key += 'native'; |
|
|
700 |
} |
|
|
701 |
if (capture) { |
|
|
702 |
key += 'capture'; |
|
|
703 |
} |
|
|
704 |
|
|
|
705 |
|
|
|
706 |
cewrapper = _wrappers[key]; |
|
|
707 |
|
|
|
708 |
|
|
|
709 |
if (!cewrapper) { |
|
|
710 |
// create CE wrapper |
|
|
711 |
cewrapper = Y.publish(key, { |
|
|
712 |
silent: true, |
|
|
713 |
bubbles: false, |
|
|
714 |
emitFacade:false, |
|
|
715 |
contextFn: function() { |
|
|
716 |
if (compat) { |
|
|
717 |
return cewrapper.el; |
|
|
718 |
} else { |
|
|
719 |
cewrapper.nodeRef = cewrapper.nodeRef || Y.one(cewrapper.el); |
|
|
720 |
return cewrapper.nodeRef; |
|
|
721 |
} |
|
|
722 |
} |
|
|
723 |
}); |
|
|
724 |
|
|
|
725 |
cewrapper.overrides = {}; |
|
|
726 |
|
|
|
727 |
// for later removeListener calls |
|
|
728 |
cewrapper.el = el; |
|
|
729 |
cewrapper.key = key; |
|
|
730 |
cewrapper.domkey = ek; |
|
|
731 |
cewrapper.type = type; |
|
|
732 |
cewrapper.fn = function(e) { |
|
|
733 |
cewrapper.fire(Event.getEvent(e, el, (compat || (false === facade)))); |
|
|
734 |
}; |
|
|
735 |
cewrapper.capture = capture; |
|
|
736 |
|
|
|
737 |
if (el == win && type == "load") { |
|
|
738 |
// window load happens once |
|
|
739 |
cewrapper.fireOnce = true; |
|
|
740 |
_windowLoadKey = key; |
|
|
741 |
} |
|
|
742 |
cewrapper._delete = _deleteAndClean; |
|
|
743 |
|
|
|
744 |
_wrappers[key] = cewrapper; |
|
|
745 |
_el_events[ek] = _el_events[ek] || {}; |
|
|
746 |
_el_events[ek][key] = cewrapper; |
|
|
747 |
|
|
|
748 |
add(el, type, cewrapper.fn, capture); |
|
|
749 |
} |
|
|
750 |
|
|
|
751 |
return cewrapper; |
|
|
752 |
|
|
|
753 |
}, |
|
|
754 |
|
|
|
755 |
_attach: function(args, conf) { |
|
|
756 |
|
|
|
757 |
var compat, |
|
|
758 |
handles, oEl, cewrapper, context, |
|
|
759 |
fireNow = false, ret, |
|
|
760 |
type = args[0], |
|
|
761 |
fn = args[1], |
|
|
762 |
el = args[2] || win, |
|
|
763 |
facade = conf && conf.facade, |
|
|
764 |
capture = conf && conf.capture, |
|
|
765 |
overrides = conf && conf.overrides; |
|
|
766 |
|
|
|
767 |
if (args[args.length-1] === COMPAT_ARG) { |
|
|
768 |
compat = true; |
|
|
769 |
} |
|
|
770 |
|
|
|
771 |
if (!fn || !fn.call) { |
|
|
772 |
// throw new TypeError(type + " attach call failed, callback undefined"); |
|
|
773 |
return false; |
|
|
774 |
} |
|
|
775 |
|
|
|
776 |
// The el argument can be an array of elements or element ids. |
|
|
777 |
if (shouldIterate(el)) { |
|
|
778 |
|
|
|
779 |
handles=[]; |
|
|
780 |
|
|
|
781 |
Y.each(el, function(v, k) { |
|
|
782 |
args[2] = v; |
|
|
783 |
handles.push(Event._attach(args.slice(), conf)); |
|
|
784 |
}); |
|
|
785 |
|
|
|
786 |
// return (handles.length === 1) ? handles[0] : handles; |
|
|
787 |
return new Y.EventHandle(handles); |
|
|
788 |
|
|
|
789 |
// If the el argument is a string, we assume it is |
|
|
790 |
// actually the id of the element. If the page is loaded |
|
|
791 |
// we convert el to the actual element, otherwise we |
|
|
792 |
// defer attaching the event until the element is |
|
|
793 |
// ready |
|
|
794 |
} else if (Y.Lang.isString(el)) { |
|
|
795 |
|
|
|
796 |
// oEl = (compat) ? Y.DOM.byId(el) : Y.Selector.query(el); |
|
|
797 |
|
|
|
798 |
if (compat) { |
|
|
799 |
oEl = Y.DOM.byId(el); |
|
|
800 |
} else { |
|
|
801 |
|
|
|
802 |
oEl = Y.Selector.query(el); |
|
|
803 |
|
|
|
804 |
switch (oEl.length) { |
|
|
805 |
case 0: |
|
|
806 |
oEl = null; |
|
|
807 |
break; |
|
|
808 |
case 1: |
|
|
809 |
oEl = oEl[0]; |
|
|
810 |
break; |
|
|
811 |
default: |
|
|
812 |
args[2] = oEl; |
|
|
813 |
return Event._attach(args, conf); |
|
|
814 |
} |
|
|
815 |
} |
|
|
816 |
|
|
|
817 |
if (oEl) { |
|
|
818 |
|
|
|
819 |
el = oEl; |
|
|
820 |
|
|
|
821 |
// Not found = defer adding the event until the element is available |
|
|
822 |
} else { |
|
|
823 |
|
|
|
824 |
ret = Event.onAvailable(el, function() { |
|
|
825 |
|
|
|
826 |
ret.handle = Event._attach(args, conf); |
|
|
827 |
|
|
|
828 |
}, Event, true, false, compat); |
|
|
829 |
|
|
|
830 |
return ret; |
|
|
831 |
|
|
|
832 |
} |
|
|
833 |
} |
|
|
834 |
|
|
|
835 |
// Element should be an html element or node |
|
|
836 |
if (!el) { |
|
|
837 |
return false; |
|
|
838 |
} |
|
|
839 |
|
|
|
840 |
if (Y.Node && Y.instanceOf(el, Y.Node)) { |
|
|
841 |
el = Y.Node.getDOMNode(el); |
|
|
842 |
} |
|
|
843 |
|
|
|
844 |
cewrapper = Event._createWrapper(el, type, capture, compat, facade); |
|
|
845 |
if (overrides) { |
|
|
846 |
Y.mix(cewrapper.overrides, overrides); |
|
|
847 |
} |
|
|
848 |
|
|
|
849 |
if (el == win && type == "load") { |
|
|
850 |
|
|
|
851 |
// if the load is complete, fire immediately. |
|
|
852 |
// all subscribers, including the current one |
|
|
853 |
// will be notified. |
|
|
854 |
if (YUI.Env.windowLoaded) { |
|
|
855 |
fireNow = true; |
|
|
856 |
} |
|
|
857 |
} |
|
|
858 |
|
|
|
859 |
if (compat) { |
|
|
860 |
args.pop(); |
|
|
861 |
} |
|
|
862 |
|
|
|
863 |
context = args[3]; |
|
|
864 |
|
|
|
865 |
// set context to the Node if not specified |
|
|
866 |
// ret = cewrapper.on.apply(cewrapper, trimmedArgs); |
|
|
867 |
ret = cewrapper._on(fn, context, (args.length > 4) ? args.slice(4) : null); |
|
|
868 |
|
|
|
869 |
if (fireNow) { |
|
|
870 |
cewrapper.fire(); |
|
|
871 |
} |
|
|
872 |
|
|
|
873 |
return ret; |
|
|
874 |
|
|
|
875 |
}, |
|
|
876 |
|
|
|
877 |
/** |
|
|
878 |
* Removes an event listener. Supports the signature the event was bound |
|
|
879 |
* with, but the preferred way to remove listeners is using the handle |
|
|
880 |
* that is returned when using Y.on |
|
|
881 |
* |
|
|
882 |
* @method detach |
|
|
883 |
* |
|
|
884 |
* @param {String} type the type of event to remove. |
|
|
885 |
* @param {Function} fn the method the event invokes. If fn is |
|
|
886 |
* undefined, then all event handlers for the type of event are |
|
|
887 |
* removed. |
|
|
888 |
* @param {String|HTMLElement|Array|NodeList|EventHandle} el An |
|
|
889 |
* event handle, an id, an element reference, or a collection |
|
|
890 |
* of ids and/or elements to remove the listener from. |
|
|
891 |
* @return {boolean} true if the unbind was successful, false otherwise. |
|
|
892 |
* @static |
|
|
893 |
*/ |
|
|
894 |
detach: function(type, fn, el, obj) { |
|
|
895 |
|
|
|
896 |
var args=Y.Array(arguments, 0, true), compat, l, ok, i, |
|
|
897 |
id, ce; |
|
|
898 |
|
|
|
899 |
if (args[args.length-1] === COMPAT_ARG) { |
|
|
900 |
compat = true; |
|
|
901 |
// args.pop(); |
|
|
902 |
} |
|
|
903 |
|
|
|
904 |
if (type && type.detach) { |
|
|
905 |
return type.detach(); |
|
|
906 |
} |
|
|
907 |
|
|
|
908 |
// The el argument can be a string |
|
|
909 |
if (typeof el == "string") { |
|
|
910 |
|
|
|
911 |
// el = (compat) ? Y.DOM.byId(el) : Y.all(el); |
|
|
912 |
if (compat) { |
|
|
913 |
el = Y.DOM.byId(el); |
|
|
914 |
} else { |
|
|
915 |
el = Y.Selector.query(el); |
|
|
916 |
l = el.length; |
|
|
917 |
if (l < 1) { |
|
|
918 |
el = null; |
|
|
919 |
} else if (l == 1) { |
|
|
920 |
el = el[0]; |
|
|
921 |
} |
|
|
922 |
} |
|
|
923 |
// return Event.detach.apply(Event, args); |
|
|
924 |
} |
|
|
925 |
|
|
|
926 |
if (!el) { |
|
|
927 |
return false; |
|
|
928 |
} |
|
|
929 |
|
|
|
930 |
if (el.detach) { |
|
|
931 |
args.splice(2, 1); |
|
|
932 |
return el.detach.apply(el, args); |
|
|
933 |
// The el argument can be an array of elements or element ids. |
|
|
934 |
} else if (shouldIterate(el)) { |
|
|
935 |
ok = true; |
|
|
936 |
for (i=0, l=el.length; i<l; ++i) { |
|
|
937 |
args[2] = el[i]; |
|
|
938 |
ok = ( Y.Event.detach.apply(Y.Event, args) && ok ); |
|
|
939 |
} |
|
|
940 |
|
|
|
941 |
return ok; |
|
|
942 |
} |
|
|
943 |
|
|
|
944 |
if (!type || !fn || !fn.call) { |
|
|
945 |
return Event.purgeElement(el, false, type); |
|
|
946 |
} |
|
|
947 |
|
|
|
948 |
id = 'event:' + Y.stamp(el) + type; |
|
|
949 |
ce = _wrappers[id]; |
|
|
950 |
|
|
|
951 |
if (ce) { |
|
|
952 |
return ce.detach(fn); |
|
|
953 |
} else { |
|
|
954 |
return false; |
|
|
955 |
} |
|
|
956 |
|
|
|
957 |
}, |
|
|
958 |
|
|
|
959 |
/** |
|
|
960 |
* Finds the event in the window object, the caller's arguments, or |
|
|
961 |
* in the arguments of another method in the callstack. This is |
|
|
962 |
* executed automatically for events registered through the event |
|
|
963 |
* manager, so the implementer should not normally need to execute |
|
|
964 |
* this function at all. |
|
|
965 |
* @method getEvent |
|
|
966 |
* @param {Event} e the event parameter from the handler |
|
|
967 |
* @param {HTMLElement} el the element the listener was attached to |
|
|
968 |
* @return {Event} the event |
|
|
969 |
* @static |
|
|
970 |
*/ |
|
|
971 |
getEvent: function(e, el, noFacade) { |
|
|
972 |
var ev = e || win.event; |
|
|
973 |
|
|
|
974 |
return (noFacade) ? ev : |
|
|
975 |
new Y.DOMEventFacade(ev, el, _wrappers['event:' + Y.stamp(el) + e.type]); |
|
|
976 |
}, |
|
|
977 |
|
|
|
978 |
/** |
|
|
979 |
* Generates an unique ID for the element if it does not already |
|
|
980 |
* have one. |
|
|
981 |
* @method generateId |
|
|
982 |
* @param el the element to create the id for |
|
|
983 |
* @return {string} the resulting id of the element |
|
|
984 |
* @static |
|
|
985 |
*/ |
|
|
986 |
generateId: function(el) { |
|
|
987 |
return Y.DOM.generateID(el); |
|
|
988 |
}, |
|
|
989 |
|
|
|
990 |
/** |
|
|
991 |
* We want to be able to use getElementsByTagName as a collection |
|
|
992 |
* to attach a group of events to. Unfortunately, different |
|
|
993 |
* browsers return different types of collections. This function |
|
|
994 |
* tests to determine if the object is array-like. It will also |
|
|
995 |
* fail if the object is an array, but is empty. |
|
|
996 |
* @method _isValidCollection |
|
|
997 |
* @param o the object to test |
|
|
998 |
* @return {boolean} true if the object is array-like and populated |
|
|
999 |
* @deprecated was not meant to be used directly |
|
|
1000 |
* @static |
|
|
1001 |
* @private |
|
|
1002 |
*/ |
|
|
1003 |
_isValidCollection: shouldIterate, |
|
|
1004 |
|
|
|
1005 |
/** |
|
|
1006 |
* hook up any deferred listeners |
|
|
1007 |
* @method _load |
|
|
1008 |
* @static |
|
|
1009 |
* @private |
|
|
1010 |
*/ |
|
|
1011 |
_load: function(e) { |
|
|
1012 |
if (!_loadComplete) { |
|
|
1013 |
_loadComplete = true; |
|
|
1014 |
|
|
|
1015 |
// Just in case DOMReady did not go off for some reason |
|
|
1016 |
// E._ready(); |
|
|
1017 |
if (Y.fire) { |
|
|
1018 |
Y.fire(EVENT_READY); |
|
|
1019 |
} |
|
|
1020 |
|
|
|
1021 |
// Available elements may not have been detected before the |
|
|
1022 |
// window load event fires. Try to find them now so that the |
|
|
1023 |
// the user is more likely to get the onAvailable notifications |
|
|
1024 |
// before the window load notification |
|
|
1025 |
Event._poll(); |
|
|
1026 |
} |
|
|
1027 |
}, |
|
|
1028 |
|
|
|
1029 |
/** |
|
|
1030 |
* Polling function that runs before the onload event fires, |
|
|
1031 |
* attempting to attach to DOM Nodes as soon as they are |
|
|
1032 |
* available |
|
|
1033 |
* @method _poll |
|
|
1034 |
* @static |
|
|
1035 |
* @private |
|
|
1036 |
*/ |
|
|
1037 |
_poll: function() { |
|
|
1038 |
if (Event.locked) { |
|
|
1039 |
return; |
|
|
1040 |
} |
|
|
1041 |
|
|
|
1042 |
if (Y.UA.ie && !YUI.Env.DOMReady) { |
|
|
1043 |
// Hold off if DOMReady has not fired and check current |
|
|
1044 |
// readyState to protect against the IE operation aborted |
|
|
1045 |
// issue. |
|
|
1046 |
Event.startInterval(); |
|
|
1047 |
return; |
|
|
1048 |
} |
|
|
1049 |
|
|
|
1050 |
Event.locked = true; |
|
|
1051 |
|
|
|
1052 |
// keep trying until after the page is loaded. We need to |
|
|
1053 |
// check the page load state prior to trying to bind the |
|
|
1054 |
// elements so that we can be certain all elements have been |
|
|
1055 |
// tested appropriately |
|
|
1056 |
var i, len, item, el, notAvail, executeItem, |
|
|
1057 |
tryAgain = !_loadComplete; |
|
|
1058 |
|
|
|
1059 |
if (!tryAgain) { |
|
|
1060 |
tryAgain = (_retryCount > 0); |
|
|
1061 |
} |
|
|
1062 |
|
|
|
1063 |
// onAvailable |
|
|
1064 |
notAvail = []; |
|
|
1065 |
|
|
|
1066 |
executeItem = function (el, item) { |
|
|
1067 |
var context, ov = item.override; |
|
|
1068 |
try { |
|
|
1069 |
if (item.compat) { |
|
|
1070 |
if (item.override) { |
|
|
1071 |
if (ov === true) { |
|
|
1072 |
context = item.obj; |
|
|
1073 |
} else { |
|
|
1074 |
context = ov; |
|
|
1075 |
} |
|
|
1076 |
} else { |
|
|
1077 |
context = el; |
|
|
1078 |
} |
|
|
1079 |
item.fn.call(context, item.obj); |
|
|
1080 |
} else { |
|
|
1081 |
context = item.obj || Y.one(el); |
|
|
1082 |
item.fn.apply(context, (Y.Lang.isArray(ov)) ? ov : []); |
|
|
1083 |
} |
|
|
1084 |
} catch (e) { |
|
|
1085 |
} |
|
|
1086 |
}; |
|
|
1087 |
|
|
|
1088 |
// onAvailable |
|
|
1089 |
for (i=0,len=_avail.length; i<len; ++i) { |
|
|
1090 |
item = _avail[i]; |
|
|
1091 |
if (item && !item.checkReady) { |
|
|
1092 |
|
|
|
1093 |
// el = (item.compat) ? Y.DOM.byId(item.id) : Y.one(item.id); |
|
|
1094 |
el = (item.compat) ? Y.DOM.byId(item.id) : Y.Selector.query(item.id, null, true); |
|
|
1095 |
|
|
|
1096 |
if (el) { |
|
|
1097 |
executeItem(el, item); |
|
|
1098 |
_avail[i] = null; |
|
|
1099 |
} else { |
|
|
1100 |
notAvail.push(item); |
|
|
1101 |
} |
|
|
1102 |
} |
|
|
1103 |
} |
|
|
1104 |
|
|
|
1105 |
// onContentReady |
|
|
1106 |
for (i=0,len=_avail.length; i<len; ++i) { |
|
|
1107 |
item = _avail[i]; |
|
|
1108 |
if (item && item.checkReady) { |
|
|
1109 |
|
|
|
1110 |
// el = (item.compat) ? Y.DOM.byId(item.id) : Y.one(item.id); |
|
|
1111 |
el = (item.compat) ? Y.DOM.byId(item.id) : Y.Selector.query(item.id, null, true); |
|
|
1112 |
|
|
|
1113 |
if (el) { |
|
|
1114 |
// The element is available, but not necessarily ready |
|
|
1115 |
// @todo should we test parentNode.nextSibling? |
|
|
1116 |
if (_loadComplete || (el.get && el.get('nextSibling')) || el.nextSibling) { |
|
|
1117 |
executeItem(el, item); |
|
|
1118 |
_avail[i] = null; |
|
|
1119 |
} |
|
|
1120 |
} else { |
|
|
1121 |
notAvail.push(item); |
|
|
1122 |
} |
|
|
1123 |
} |
|
|
1124 |
} |
|
|
1125 |
|
|
|
1126 |
_retryCount = (notAvail.length === 0) ? 0 : _retryCount - 1; |
|
|
1127 |
|
|
|
1128 |
if (tryAgain) { |
|
|
1129 |
// we may need to strip the nulled out items here |
|
|
1130 |
Event.startInterval(); |
|
|
1131 |
} else { |
|
|
1132 |
clearInterval(Event._interval); |
|
|
1133 |
Event._interval = null; |
|
|
1134 |
} |
|
|
1135 |
|
|
|
1136 |
Event.locked = false; |
|
|
1137 |
|
|
|
1138 |
return; |
|
|
1139 |
|
|
|
1140 |
}, |
|
|
1141 |
|
|
|
1142 |
/** |
|
|
1143 |
* Removes all listeners attached to the given element via addListener. |
|
|
1144 |
* Optionally, the node's children can also be purged. |
|
|
1145 |
* Optionally, you can specify a specific type of event to remove. |
|
|
1146 |
* @method purgeElement |
|
|
1147 |
* @param {HTMLElement} el the element to purge |
|
|
1148 |
* @param {boolean} recurse recursively purge this element's children |
|
|
1149 |
* as well. Use with caution. |
|
|
1150 |
* @param {string} type optional type of listener to purge. If |
|
|
1151 |
* left out, all listeners will be removed |
|
|
1152 |
* @static |
|
|
1153 |
*/ |
|
|
1154 |
purgeElement: function(el, recurse, type) { |
|
|
1155 |
// var oEl = (Y.Lang.isString(el)) ? Y.one(el) : el, |
|
|
1156 |
var oEl = (Y.Lang.isString(el)) ? Y.Selector.query(el, null, true) : el, |
|
|
1157 |
lis = Event.getListeners(oEl, type), i, len, children, child; |
|
|
1158 |
|
|
|
1159 |
if (recurse && oEl) { |
|
|
1160 |
lis = lis || []; |
|
|
1161 |
children = Y.Selector.query('*', oEl); |
|
|
1162 |
len = children.length; |
|
|
1163 |
for (i = 0; i < len; ++i) { |
|
|
1164 |
child = Event.getListeners(children[i], type); |
|
|
1165 |
if (child) { |
|
|
1166 |
lis = lis.concat(child); |
|
|
1167 |
} |
|
|
1168 |
} |
|
|
1169 |
} |
|
|
1170 |
|
|
|
1171 |
if (lis) { |
|
|
1172 |
for (i = 0, len = lis.length; i < len; ++i) { |
|
|
1173 |
lis[i].detachAll(); |
|
|
1174 |
} |
|
|
1175 |
} |
|
|
1176 |
|
|
|
1177 |
}, |
|
|
1178 |
|
|
|
1179 |
/** |
|
|
1180 |
* Removes all object references and the DOM proxy subscription for |
|
|
1181 |
* a given event for a DOM node. |
|
|
1182 |
* |
|
|
1183 |
* @method _clean |
|
|
1184 |
* @param wrapper {CustomEvent} Custom event proxy for the DOM |
|
|
1185 |
* subscription |
|
|
1186 |
* @private |
|
|
1187 |
* @static |
|
|
1188 |
* @since 3.4.0 |
|
|
1189 |
*/ |
|
|
1190 |
_clean: function (wrapper) { |
|
|
1191 |
var key = wrapper.key, |
|
|
1192 |
domkey = wrapper.domkey; |
|
|
1193 |
|
|
|
1194 |
remove(wrapper.el, wrapper.type, wrapper.fn, wrapper.capture); |
|
|
1195 |
delete _wrappers[key]; |
|
|
1196 |
delete Y._yuievt.events[key]; |
|
|
1197 |
if (_el_events[domkey]) { |
|
|
1198 |
delete _el_events[domkey][key]; |
|
|
1199 |
if (!Y.Object.size(_el_events[domkey])) { |
|
|
1200 |
delete _el_events[domkey]; |
|
|
1201 |
} |
|
|
1202 |
} |
|
|
1203 |
}, |
|
|
1204 |
|
|
|
1205 |
/** |
|
|
1206 |
* Returns all listeners attached to the given element via addListener. |
|
|
1207 |
* Optionally, you can specify a specific type of event to return. |
|
|
1208 |
* @method getListeners |
|
|
1209 |
* @param el {HTMLElement|string} the element or element id to inspect |
|
|
1210 |
* @param type {string} optional type of listener to return. If |
|
|
1211 |
* left out, all listeners will be returned |
|
|
1212 |
* @return {CustomEvent} the custom event wrapper for the DOM event(s) |
|
|
1213 |
* @static |
|
|
1214 |
*/ |
|
|
1215 |
getListeners: function(el, type) { |
|
|
1216 |
var ek = Y.stamp(el, true), evts = _el_events[ek], |
|
|
1217 |
results=[] , key = (type) ? 'event:' + ek + type : null, |
|
|
1218 |
adapters = _eventenv.plugins; |
|
|
1219 |
|
|
|
1220 |
if (!evts) { |
|
|
1221 |
return null; |
|
|
1222 |
} |
|
|
1223 |
|
|
|
1224 |
if (key) { |
|
|
1225 |
// look for synthetic events |
|
|
1226 |
if (adapters[type] && adapters[type].eventDef) { |
|
|
1227 |
key += '_synth'; |
|
|
1228 |
} |
|
|
1229 |
|
|
|
1230 |
if (evts[key]) { |
|
|
1231 |
results.push(evts[key]); |
|
|
1232 |
} |
|
|
1233 |
|
|
|
1234 |
// get native events as well |
|
|
1235 |
key += 'native'; |
|
|
1236 |
if (evts[key]) { |
|
|
1237 |
results.push(evts[key]); |
|
|
1238 |
} |
|
|
1239 |
|
|
|
1240 |
} else { |
|
|
1241 |
Y.each(evts, function(v, k) { |
|
|
1242 |
results.push(v); |
|
|
1243 |
}); |
|
|
1244 |
} |
|
|
1245 |
|
|
|
1246 |
return (results.length) ? results : null; |
|
|
1247 |
}, |
|
|
1248 |
|
|
|
1249 |
/** |
|
|
1250 |
* Removes all listeners registered by pe.event. Called |
|
|
1251 |
* automatically during the unload event. |
|
|
1252 |
* @method _unload |
|
|
1253 |
* @static |
|
|
1254 |
* @private |
|
|
1255 |
*/ |
|
|
1256 |
_unload: function(e) { |
|
|
1257 |
Y.each(_wrappers, function(v, k) { |
|
|
1258 |
if (v.type == 'unload') { |
|
|
1259 |
v.fire(e); |
|
|
1260 |
} |
|
|
1261 |
v.detachAll(); |
|
|
1262 |
}); |
|
|
1263 |
remove(win, "unload", onUnload); |
|
|
1264 |
}, |
|
|
1265 |
|
|
|
1266 |
/** |
|
|
1267 |
* Adds a DOM event directly without the caching, cleanup, context adj, etc |
|
|
1268 |
* |
|
|
1269 |
* @method nativeAdd |
|
|
1270 |
* @param {HTMLElement} el the element to bind the handler to |
|
|
1271 |
* @param {string} type the type of event handler |
|
|
1272 |
* @param {function} fn the callback to invoke |
|
|
1273 |
* @param {boolen} capture capture or bubble phase |
|
|
1274 |
* @static |
|
|
1275 |
* @private |
|
|
1276 |
*/ |
|
|
1277 |
nativeAdd: add, |
|
|
1278 |
|
|
|
1279 |
/** |
|
|
1280 |
* Basic remove listener |
|
|
1281 |
* |
|
|
1282 |
* @method nativeRemove |
|
|
1283 |
* @param {HTMLElement} el the element to bind the handler to |
|
|
1284 |
* @param {string} type the type of event handler |
|
|
1285 |
* @param {function} fn the callback to invoke |
|
|
1286 |
* @param {boolen} capture capture or bubble phase |
|
|
1287 |
* @static |
|
|
1288 |
* @private |
|
|
1289 |
*/ |
|
|
1290 |
nativeRemove: remove |
|
|
1291 |
}; |
|
|
1292 |
|
|
|
1293 |
}(); |
|
|
1294 |
|
|
|
1295 |
Y.Event = Event; |
|
|
1296 |
|
|
|
1297 |
if (config.injected || YUI.Env.windowLoaded) { |
|
|
1298 |
onLoad(); |
|
|
1299 |
} else { |
|
|
1300 |
add(win, "load", onLoad); |
|
|
1301 |
} |
|
|
1302 |
|
|
|
1303 |
// Process onAvailable/onContentReady items when when the DOM is ready in IE |
|
|
1304 |
if (Y.UA.ie) { |
|
|
1305 |
Y.on(EVENT_READY, Event._poll); |
|
|
1306 |
} |
|
|
1307 |
|
|
|
1308 |
try { |
|
|
1309 |
add(win, "unload", onUnload); |
|
|
1310 |
} catch(e) { |
|
|
1311 |
/*jshint maxlen:300*/ |
|
|
1312 |
} |
|
|
1313 |
|
|
|
1314 |
Event.Custom = Y.CustomEvent; |
|
|
1315 |
Event.Subscriber = Y.Subscriber; |
|
|
1316 |
Event.Target = Y.EventTarget; |
|
|
1317 |
Event.Handle = Y.EventHandle; |
|
|
1318 |
Event.Facade = Y.EventFacade; |
|
|
1319 |
|
|
|
1320 |
Event._poll(); |
|
|
1321 |
|
|
|
1322 |
}()); |
|
|
1323 |
|
|
|
1324 |
/** |
|
|
1325 |
* DOM event listener abstraction layer |
|
|
1326 |
* @module event |
|
|
1327 |
* @submodule event-base |
|
|
1328 |
*/ |
|
|
1329 |
|
|
|
1330 |
/** |
|
|
1331 |
* Executes the callback as soon as the specified element |
|
|
1332 |
* is detected in the DOM. This function expects a selector |
|
|
1333 |
* string for the element(s) to detect. If you already have |
|
|
1334 |
* an element reference, you don't need this event. |
|
|
1335 |
* @event available |
|
|
1336 |
* @param type {string} 'available' |
|
|
1337 |
* @param fn {function} the callback function to execute. |
|
|
1338 |
* @param el {string} an selector for the element(s) to attach |
|
|
1339 |
* @param context optional argument that specifies what 'this' refers to. |
|
|
1340 |
* @param args* 0..n additional arguments to pass on to the callback function. |
|
|
1341 |
* These arguments will be added after the event object. |
|
|
1342 |
* @return {EventHandle} the detach handle |
|
|
1343 |
* @for YUI |
|
|
1344 |
*/ |
|
|
1345 |
Y.Env.evt.plugins.available = { |
|
|
1346 |
on: function(type, fn, id, o) { |
|
|
1347 |
var a = arguments.length > 4 ? Y.Array(arguments, 4, true) : null; |
|
|
1348 |
return Y.Event.onAvailable.call(Y.Event, id, fn, o, a); |
|
|
1349 |
} |
|
|
1350 |
}; |
|
|
1351 |
|
|
|
1352 |
/** |
|
|
1353 |
* Executes the callback as soon as the specified element |
|
|
1354 |
* is detected in the DOM with a nextSibling property |
|
|
1355 |
* (indicating that the element's children are available). |
|
|
1356 |
* This function expects a selector |
|
|
1357 |
* string for the element(s) to detect. If you already have |
|
|
1358 |
* an element reference, you don't need this event. |
|
|
1359 |
* @event contentready |
|
|
1360 |
* @param type {string} 'contentready' |
|
|
1361 |
* @param fn {function} the callback function to execute. |
|
|
1362 |
* @param el {string} an selector for the element(s) to attach. |
|
|
1363 |
* @param context optional argument that specifies what 'this' refers to. |
|
|
1364 |
* @param args* 0..n additional arguments to pass on to the callback function. |
|
|
1365 |
* These arguments will be added after the event object. |
|
|
1366 |
* @return {EventHandle} the detach handle |
|
|
1367 |
* @for YUI |
|
|
1368 |
*/ |
|
|
1369 |
Y.Env.evt.plugins.contentready = { |
|
|
1370 |
on: function(type, fn, id, o) { |
|
|
1371 |
var a = arguments.length > 4 ? Y.Array(arguments, 4, true) : null; |
|
|
1372 |
return Y.Event.onContentReady.call(Y.Event, id, fn, o, a); |
|
|
1373 |
} |
|
|
1374 |
}; |
|
|
1375 |
|
|
|
1376 |
|
|
|
1377 |
}, '3.10.3', {"requires": ["event-custom-base"]}); |