event-debug.js revision f6baa527839e75655081768c365a749c59edc80d
665a24faf6b3711e4012ac02ae5f0981c093ac1eTinderbox User * DOM event listener abstraction layer
75c0816e8295e180f4bc7f10db3d0d880383bc1cMark Andrews * @module event
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @submodule event-base
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews// Unlike most of the library, this code has to be executed as soon as it is
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews// introduced into the page -- and it should only be executed one time
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein// regardless of the number of instances that use it.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein doScrollCap = docElement && docElement.doScroll,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein targetEvent = (doScrollCap) ? 'onreadystatechange' : 'DOMContentLoaded',
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein _ready = function(e) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein remove(doc, targetEvent, _ready); // remove DOMContentLoaded listener
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein/*! DOMReady: based on work by: Dean Edwards/John Resig/Matthias Miller/Diego Perini */
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User// Internet Explorer: use the doScroll() method on the root element. This isolates what
665a24faf6b3711e4012ac02ae5f0981c093ac1eTinderbox User// appears to be a safe moment to manipulate the DOM prior to when the document's readyState
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User// suggests it is safe to do so.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein remove(doc, targetEvent, stateChangeListener); // remove onreadystatechange listener
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein add(doc, targetEvent, stateChangeListener); // add onreadystatechange listener
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein } else { // FireFox, Opera, Safari 3+ provide an event for this moment.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein add(doc, targetEvent, _ready); // add DOMContentLoaded listener
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * DOM event listener abstraction layer
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @module event
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User * @submodule event-base
b3cbb2f1ad021349e89807f3492df6e4e679cd56Mark Andrews yready = function() {
b3cbb2f1ad021349e89807f3492df6e4e679cd56Mark Andrews * The domready event fires at the moment the browser's DOM is
b3cbb2f1ad021349e89807f3492df6e4e679cd56Mark Andrews * usable. In most cases, this is before images are fully
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * downloaded, allowing you to provide a more responsive user
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * In YUI 3, domready subscribers will be notified immediately if
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User * that moment has already passed when the subscription is created.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * One exception is if the yui.js file is dynamically injected into
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * the page. If this is done, you must tell the YUI instance that
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * you did this in order for DOMReady (and window load events) to
61e1dc26d62c2a0059e3ca7efe2ad0f4a5b8df92Mark Andrews * fire normally. That configuration option is 'injected' -- set
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * it to true if the yui.js script is not included inline.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * This method is part of the 'event-ready' module, which is a
d8620c7234281056fdfd2ee40cf16636b8281092Tinderbox User * submodule of 'event'.
d8620c7234281056fdfd2ee40cf16636b8281092Tinderbox User * @event domready
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User // console.log('DOMReady already fired', 'info', 'event');
d8620c7234281056fdfd2ee40cf16636b8281092Tinderbox User // console.log('setting up before listener', 'info', 'event');
d8620c7234281056fdfd2ee40cf16636b8281092Tinderbox User // console.log('env: ' + YUI.Env.windowLoaded, 'info', 'event');
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Custom event engine, DOM event listener abstraction layer, synthetic DOM
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @module event
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @submodule event-base
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Wraps a DOM event, properties requiring browser abstraction are
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * fixed here. Provids a security layer when required.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @class DOMEventFacade
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @param ev {Event} the DOM event
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User * @param currentTarget {HTMLElement} the element the listener was attached to
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @param wrapper {Event.Custom} the custom event wrapper for this DOM event
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @TODO constants? LEFTBUTTON, MIDDLEBUTTON, RIGHTBUTTON, keys
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinvar whitelist = {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "button" : 1, // we supply
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "bubbles" : 1, // needed?
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "cancelable" : 1, // needed?
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "charCode" : 1, // we supply
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein cancelBubble : 1,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "currentTarget" : 1, // we supply
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ctrlKey : 1,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein clientX : 1, // needed?
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein clientY : 1, // needed?
a1b05dea35aa30b152a47115e18bbe679d3fcf19Mark Andrews detail : 1, // not fully implemented
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "fromElement" : 1,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein keyCode : 1,
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User // "height" : 1, // needed?
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "initEvent" : 1, // need the init events?
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "initMouseEvent" : 1,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "initUIEvent" : 1,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "layerX" : 1, // needed?
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews // "layerY" : 1, // needed?
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein metaKey : 1,
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User // "modifiers" : 1, // needed?
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "offsetX" : 1, // needed?
1c09d68dfd18b6e839c8cd68b78c11b3ccca4160Automatic Updater // "offsetY" : 1, // needed?
1c09d68dfd18b6e839c8cd68b78c11b3ccca4160Automatic Updater // "preventDefault" : 1, // we supply
1c09d68dfd18b6e839c8cd68b78c11b3ccca4160Automatic Updater // "reason" : 1, // IE proprietary
1c09d68dfd18b6e839c8cd68b78c11b3ccca4160Automatic Updater // "relatedTarget" : 1,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "returnValue" : 1, // needed?
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein shiftKey : 1,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "srcUrn" : 1, // IE proprietary
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User // "srcElement" : 1,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "srcFilter" : 1, IE proprietary
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "stopPropagation" : 1, // we supply
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "target" : 1,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "timeStamp" : 1, // needed?
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "toElement" : 1,
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User // "view" : 1,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "which" : 1, // we supply
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // "width" : 1, // needed?
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * webkit key remapping required for Safari < 3.1
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @property webkitKeymap
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein 25: 9, // SHIFT-TAB (Safari provides a different key code in
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews // this case, even though the shiftKey modifier is set)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Returns a wrapped node. Intended to be used on event targets,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * so it will return the node's parent if the target is a text
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * If accessing a property of the node throws an error, this is
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * probably the anonymous div wrapper Gecko adds inside text
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * nodes. This likely will only occur when attempting to access
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * the relatedTarget. In this case, we now return null because
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * the anonymous div is completely useless and we do not know
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * what the related target was because we can't even get to
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User * the element's parent node.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @method resolve
7329012471d165cd3dc4180ad2a0a43de91e7f01Mark Andrews resolve = function(n) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein } catch(e) {
61e1dc26d62c2a0059e3ca7efe2ad0f4a5b8df92Mark Andrews return null;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return Y.one(n);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein// provide a single event with browser abstractions resolved
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein// include all properties for both browers?
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein// include only DOM2 spec properties?
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein// provide browser-specific facade?
665a24faf6b3711e4012ac02ae5f0981c093ac1eTinderbox UserY.DOMEventFacade = function(ev, currentTarget, wrapper) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein var e = ev, ot = currentTarget, d = Y.config.doc, b = d.body,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein x = e.pageX, y = e.pageY, c, t, de = d.documentElement,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein //////////////////////////////////////////////////////
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * The native event
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @property _event
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * The X location of the event on the page (including scroll)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @property pageX
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * The Y location of the event on the page (including scroll)
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User * @property pageY
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein //////////////////////////////////////////////////////
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews * The keyCode for key events. Uses charCode if keyCode is not available
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews * @property keyCode
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * The charCode for key events. Same as keyCode
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @property charCode
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein //////////////////////////////////////////////////////
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * The button that was pushed.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @property button
370c55dfcdc559b8761ef3eb4921498580caf14cAutomatic Updater * The button that was pushed. Same as button.
370c55dfcdc559b8761ef3eb4921498580caf14cAutomatic Updater * @property which
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein //////////////////////////////////////////////////////
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Node reference for the targeted element
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @propery target
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @type Node
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein this.target = resolve(e.target || e.srcElement);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Node reference for the element that the listener was attached to.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @propery currentTarget
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @type Node
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Node reference to the relatedTarget
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @propery relatedTarget
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @type Node
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Number representing the direction and velocity of the movement of the mousewheel.
77dccf2a5d9327d16b4374a135cdb99bdd48620eAutomatic Updater * Negative is down, the higher the number, the faster. Applies to the mousewheel event.
77dccf2a5d9327d16b4374a135cdb99bdd48620eAutomatic Updater * @property wheelDelta
77dccf2a5d9327d16b4374a135cdb99bdd48620eAutomatic Updater if (e.type == "mousewheel" || e.type == "DOMMouseScroll") {
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User this.wheelDelta = (e.detail) ? (e.detail * -1) : Math.round(e.wheelDelta / 80) || ((e.wheelDelta < 0) ? -1 : 1);
77dccf2a5d9327d16b4374a135cdb99bdd48620eAutomatic Updater //////////////////////////////////////////////////////
77dccf2a5d9327d16b4374a135cdb99bdd48620eAutomatic Updater * Stops the propagation to the next bubble target
77dccf2a5d9327d16b4374a135cdb99bdd48620eAutomatic Updater * @method stopPropagation
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein this.stopPropagation = function() {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Stops the propagation to the next bubble target and
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * prevents any additional listeners from being exectued
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * on the current target.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @method stopImmediatePropagation
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein this.stopImmediatePropagation = function() {
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater * Prevents the event's default behavior
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater * @method preventDefault
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater * @param returnValue {string} sets the returnValue of the event to this value
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater * (rather than the default false value). This can be used to add a customized
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater * confirmation query to the beforeunload event).
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater this.preventDefault = function(returnValue) {
9054d0bb0301aa04ea1ff700ebe4beaf0b573d24Tinderbox User * Stops the event propagation and prevents the default
9054d0bb0301aa04ea1ff700ebe4beaf0b573d24Tinderbox User * event behavior.
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater * @method halt
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater * @param immediate {boolean} if true additional listeners
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater * on the current target will not be executed
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein(function() {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * DOM event listener abstraction layer
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @module event
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @submodule event-base
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * The event utility provides functions to add and remove event listeners,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * event cleansing. It also tries to automatically remove listeners it
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * registers during the unload event.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @class Event
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinonLoad = function() {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinonUnload = function() {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinshouldIterate = function(o) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return (o && typeof o !== "string" && Y.Lang.isNumber(o.length) && !o.tagName && !o.alert);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein Y.log("collection check failure", "warn", "event");
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return false;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinEvent = function() {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * True after the onload event has fired
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @property _loadComplete
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @type boolean
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * The number of times to poll after window.onload. This number is
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * increased if additional late-bound handlers are requested after
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * the page load.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @property _retryCount
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * onAvailable listeners
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @property _avail
00124ad0406365d39f4b2d1011ef6a76706e9df0Mark Andrews * Custom event wrappers for DOM events. Key is
00124ad0406365d39f4b2d1011ef6a76706e9df0Mark Andrews * 'event:' + Element uid stamp + event type
00124ad0406365d39f4b2d1011ef6a76706e9df0Mark Andrews * @property _wrappers
77dccf2a5d9327d16b4374a135cdb99bdd48620eAutomatic Updater * @type Y.Event.Custom
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Custom event wrapper map DOM events. Key is
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User * Element uid stamp. Each item is a hash of custom event
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * wrappers as provided in the _wrappers collection. This
6c8a888822cfe45f0525e7496dcaa27d341b6a5eAutomatic Updater * provides the infrastructure for getListeners.
6c8a888822cfe45f0525e7496dcaa27d341b6a5eAutomatic Updater * @property _el_events
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * The number of times we should look for elements that are not
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * in the DOM at the time the event is requested after the document
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews * has been loaded. The default is 1000@amp;40 ms, so it will poll
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * for 40 seconds or until all outstanding handlers are bound
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * (whichever comes first).
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @property POLL_RETRYS
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * The poll interval in milliseconds
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @property POLL_INTERVAL
90153b6536f7a5078e1c157c980110dbcd7fe205Mark Andrews * addListener/removeListener can throw errors in unexpected scenarios.
90153b6536f7a5078e1c157c980110dbcd7fe205Mark Andrews * These errors are suppressed, the method returns false, and this property
90153b6536f7a5078e1c157c980110dbcd7fe205Mark Andrews * @property lastError
90153b6536f7a5078e1c157c980110dbcd7fe205Mark Andrews * @type Error
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * poll handle
90153b6536f7a5078e1c157c980110dbcd7fe205Mark Andrews * @property _interval
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * document readystate poll handle
8dc5d5e460da15b2481893687cad7e5b72d0314aAutomatic Updater * @property _dri
20489550151432d8d99c3f49629c7c718fdca6abMark Andrews * True when the document is initially usable
20489550151432d8d99c3f49629c7c718fdca6abMark Andrews * @property DOMReady
20489550151432d8d99c3f49629c7c718fdca6abMark Andrews * @type boolean
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User * @method startInterval
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinEvent._interval = setInterval(Y.bind(Event._poll, Event), Event.POLL_INTERVAL);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Executes the supplied callback when the item with the supplied
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * id is found. This is meant to be used to execute behavior as
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * soon as possible as the page loads. If you use this after the
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * initial page load it will poll for a fixed time for the element.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * The number of times it will poll and the frequency are
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * configurable. By default it will poll for 10 seconds.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * <p>The callback is executed with a single parameter:
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * the custom object parameter, if provided.</p>
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @method onAvailable
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @param {string||string[]} id the id of the element, or an array
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * of ids to look for.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @param {function} fn what to execute when the element is found.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @param {object} p_obj an optional object to be passed back as
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * a parameter to fn.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @param {boolean|object} p_override If set to true, fn will execute
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * in the context of p_obj, if set to an object it
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User * will execute in the context of that object
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @param checkContent {boolean} check child node readiness (onContentReady)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * @deprecated Use Y.on("available")
fb84f9014321c5f33c4682de5661b579fcde318fAndreas Gustafsson // @TODO fix arguments
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein onAvailable: function(id, fn, p_obj, p_override, checkContent, compat) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein // Y.log('onAvailable registered for: ' + id);
057cafaa3df7be7a6dcca71fbaf8fb498fd83518Mark Andrews // We want the first test to be immediate, but async
057cafaa3df7be7a6dcca71fbaf8fb498fd83518Mark Andrews _delete: function() {
3afd0ff6628df1e7e20161e4afa99469a1195a5bTinderbox User // set by the event system for lazy DOM listeners
665a24faf6b3711e4012ac02ae5f0981c093ac1eTinderbox User // otherwise try to remove the onAvailable listener(s)
var cewrapper,
if (false === facade) {
if (capture) {
if (!cewrapper) {
silent: true,
bubbles: false,
contextFn: function() {
if (compat) {
return cewrapper;
var compat,
compat = true;
handles=[];
if (compat) {
oEl = null;
if (oEl) {
return ret;
if (!el) {
if (overrides) {
fireNow = true;
if (compat) {
if (fireNow) {
return ret;
compat = true;
if (compat) {
el = null;
if (!el) {
ok = true;
return ok;
if (ce) {
if (!id) {
return id;
_load: function(e) {
if (!_loadComplete) {
_loadComplete = true;
if (Y.fire) {
_poll: function() {
if (this.locked) {
this.startInterval();
this.locked = true;
if (!tryAgain) {
notAvail = [];
if (ov === true) {
if (el) {
_avail[i] = null;
if (el) {
_avail[i] = null;
if (tryAgain) {
this.startInterval();
this._interval = null;
this.locked = false;
for (; i < len; ++i) {
if (child) {
if (lis) {
for (; i < len; ++i) {
if (!evts) {
if (key) {
_unload: function(e) {
v.detachAll();
delete _wrappers[k];
onLoad();
// Process onAvailable/onContentReady items when when the DOM is ready in IE
var toArray = Y.Array,
if (!handle) {
}, el);
return handle;
* Overrides the <code>_notify</code> method on the normal DOM subscription to inject the filtering logic and only proceed in the case of a match.
if (this.args) {
if (currentTarget) {
return ret;
return function (target, e) {
match = [];
return match;
toArray = Y.Array,
noop = function () {};
event = e || {};
if (this.emitFacade) {
if (!e || !e.preventDefault) {
if (delegate) {
function SyntheticEvent() {
capture : false,
notifiers : [],
detachAll : function () {
this.subscribers = {};
prototype: {
_init: function () {
var handles = [],
}, selector);
return handle;
if (node) {
if (delegate) {
eventDef : this,
return handle;
if (notifiers) {
if (node) {
if (handles) {
handles = [],
if (notifiers) {
if (!filter) {
if (first) {
return handle;
if (!config) {
config = {};
Impl = function () {
on: function () {
delegate: function () {
detach: function () {
return synth;
on: function() {
detach: function() {
var config = {
passed = true;
failed = true;
if (passed) {
}, id);
}, el]);
{ capture: true });
if (!notifiers) {
notifiers = {};
if (defer) {
if (!defer) {
this._notify(e);
nots = [],
if (notifiers) {
delete e.container;
if (useActivate) {
var detachHandle,
handler = function(e) {
if (timerHandle) {
if (!detachHandle) {