event-base-debug.js revision 111837fe5c14f516f4a15878f9bbaf7bb0091364
03831d35f7499c87d51205817c93e9a8d42c4baestevel * DOM event listener abstraction layer
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @module event
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @submodule event-base
03831d35f7499c87d51205817c93e9a8d42c4baestevel(function() {
03831d35f7499c87d51205817c93e9a8d42c4baestevel// Unlike most of the library, this code has to be executed as soon as it is
03831d35f7499c87d51205817c93e9a8d42c4baestevel// introduced into the page -- and it should only be executed one time
03831d35f7499c87d51205817c93e9a8d42c4baestevel// regardless of the number of instances that use it.
03831d35f7499c87d51205817c93e9a8d42c4baestevel targetEvent = (doScrollCap) ? 'onreadystatechange' : 'DOMContentLoaded',
03831d35f7499c87d51205817c93e9a8d42c4baestevel _ready = function(e) {
03831d35f7499c87d51205817c93e9a8d42c4baestevel remove(doc, targetEvent, _ready); // remove DOMContentLoaded listener
03831d35f7499c87d51205817c93e9a8d42c4baestevel/*! DOMReady: based on work by: Dean Edwards/John Resig/Matthias Miller/Diego Perini */
03831d35f7499c87d51205817c93e9a8d42c4baestevel// Internet Explorer: use the doScroll() method on the root element. This isolates what
03831d35f7499c87d51205817c93e9a8d42c4baestevel// appears to be a safe moment to manipulate the DOM prior to when the document's readyState
03831d35f7499c87d51205817c93e9a8d42c4baestevel// suggests it is safe to do so.
03831d35f7499c87d51205817c93e9a8d42c4baestevel remove(doc, targetEvent, stateChangeListener); // remove onreadystatechange listener
03831d35f7499c87d51205817c93e9a8d42c4baestevel add(doc, targetEvent, stateChangeListener); // add onreadystatechange listener
03831d35f7499c87d51205817c93e9a8d42c4baestevel } catch (domNotReady) { }
03831d35f7499c87d51205817c93e9a8d42c4baestevel } else { // FireFox, Opera, Safari 3+ provide an event for this moment.
03831d35f7499c87d51205817c93e9a8d42c4baestevel add(doc, targetEvent, _ready); // add DOMContentLoaded listener
03831d35f7499c87d51205817c93e9a8d42c4baestevel(function() {
03831d35f7499c87d51205817c93e9a8d42c4baestevel * DOM event listener abstraction layer
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @module event
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @submodule event-base
03831d35f7499c87d51205817c93e9a8d42c4baestevel yready = function() {
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The domready event fires at the moment the browser's DOM is
03831d35f7499c87d51205817c93e9a8d42c4baestevel * usable. In most cases, this is before images are fully
03831d35f7499c87d51205817c93e9a8d42c4baestevel * downloaded, allowing you to provide a more responsive user
03831d35f7499c87d51205817c93e9a8d42c4baestevel * interface.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * In YUI 3, domready subscribers will be notified immediately if
03831d35f7499c87d51205817c93e9a8d42c4baestevel * that moment has already passed when the subscription is created.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * One exception is if the yui.js file is dynamically injected into
03831d35f7499c87d51205817c93e9a8d42c4baestevel * the page. If this is done, you must tell the YUI instance that
03831d35f7499c87d51205817c93e9a8d42c4baestevel * you did this in order for DOMReady (and window load events) to
03831d35f7499c87d51205817c93e9a8d42c4baestevel * fire normally. That configuration option is 'injected' -- set
03831d35f7499c87d51205817c93e9a8d42c4baestevel * it to true if the yui.js script is not included inline.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * This method is part of the 'event-ready' module, which is a
03831d35f7499c87d51205817c93e9a8d42c4baestevel * submodule of 'event'.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @event domready
03831d35f7499c87d51205817c93e9a8d42c4baestevel // console.log('DOMReady already fired', 'info', 'event');
03831d35f7499c87d51205817c93e9a8d42c4baestevel // console.log('setting up before listener', 'info', 'event');
03831d35f7499c87d51205817c93e9a8d42c4baestevel // console.log('env: ' + YUI.Env.windowLoaded, 'info', 'event');
03831d35f7499c87d51205817c93e9a8d42c4baestevel(function() {
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Custom event engine, DOM event listener abstraction layer, synthetic DOM
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @module event
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @submodule event-base
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Wraps a DOM event, properties requiring browser abstraction are
03831d35f7499c87d51205817c93e9a8d42c4baestevel * fixed here. Provids a security layer when required.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @class DOMEventFacade
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @param ev {Event} the DOM event
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @param currentTarget {HTMLElement} the element the listener was attached to
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @param wrapper {Event.Custom} the custom event wrapper for this DOM event
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @TODO constants? LEFTBUTTON, MIDDLEBUTTON, RIGHTBUTTON, keys
03831d35f7499c87d51205817c93e9a8d42c4baestevelvar whitelist = {
03831d35f7499c87d51205817c93e9a8d42c4baestevel altKey : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "button" : 1, // we supply
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "bubbles" : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "cancelable" : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "charCode" : 1, // we supply
03831d35f7499c87d51205817c93e9a8d42c4baestevel cancelBubble : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "currentTarget" : 1, // we supply
03831d35f7499c87d51205817c93e9a8d42c4baestevel ctrlKey : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel clientX : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel clientY : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel detail : 1, // not fully implemented
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "fromElement" : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel keyCode : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "height" : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "initEvent" : 1, // need the init events?
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "initMouseEvent" : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "initUIEvent" : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "layerX" : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "layerY" : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel metaKey : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "modifiers" : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "offsetX" : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "offsetY" : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "preventDefault" : 1, // we supply
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "reason" : 1, // IE proprietary
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "relatedTarget" : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "returnValue" : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel shiftKey : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "srcUrn" : 1, // IE proprietary
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "srcElement" : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "srcFilter" : 1, IE proprietary
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "stopPropagation" : 1, // we supply
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "target" : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "timeStamp" : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "toElement" : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "view" : 1,
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "which" : 1, // we supply
03831d35f7499c87d51205817c93e9a8d42c4baestevel // "width" : 1, // needed?
03831d35f7499c87d51205817c93e9a8d42c4baestevel * webkit key remapping required for Safari < 3.1
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @property webkitKeymap
03831d35f7499c87d51205817c93e9a8d42c4baestevel 25: 9, // SHIFT-TAB (Safari provides a different key code in
03831d35f7499c87d51205817c93e9a8d42c4baestevel // this case, even though the shiftKey modifier is set)
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Returns a wrapped node. Intended to be used on event targets,
03831d35f7499c87d51205817c93e9a8d42c4baestevel * so it will return the node's parent if the target is a text
03831d35f7499c87d51205817c93e9a8d42c4baestevel * If accessing a property of the node throws an error, this is
03831d35f7499c87d51205817c93e9a8d42c4baestevel * probably the anonymous div wrapper Gecko adds inside text
03831d35f7499c87d51205817c93e9a8d42c4baestevel * nodes. This likely will only occur when attempting to access
03831d35f7499c87d51205817c93e9a8d42c4baestevel * the relatedTarget. In this case, we now return null because
03831d35f7499c87d51205817c93e9a8d42c4baestevel * the anonymous div is completely useless and we do not know
03831d35f7499c87d51205817c93e9a8d42c4baestevel * what the related target was because we can't even get to
03831d35f7499c87d51205817c93e9a8d42c4baestevel * the element's parent node.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @method resolve
03831d35f7499c87d51205817c93e9a8d42c4baestevel resolve = function(n) {
03831d35f7499c87d51205817c93e9a8d42c4baestevel } catch(e) {
03831d35f7499c87d51205817c93e9a8d42c4baestevel return null;
03831d35f7499c87d51205817c93e9a8d42c4baestevel return Y.one(n);
03831d35f7499c87d51205817c93e9a8d42c4baestevel// provide a single event with browser abstractions resolved
03831d35f7499c87d51205817c93e9a8d42c4baestevel// include all properties for both browers?
03831d35f7499c87d51205817c93e9a8d42c4baestevel// include only DOM2 spec properties?
03831d35f7499c87d51205817c93e9a8d42c4baestevel// provide browser-specific facade?
03831d35f7499c87d51205817c93e9a8d42c4baestevelY.DOMEventFacade = function(ev, currentTarget, wrapper) {
03831d35f7499c87d51205817c93e9a8d42c4baestevel var e = ev, ot = currentTarget, d = Y.config.doc, b = d.body,
03831d35f7499c87d51205817c93e9a8d42c4baestevel //////////////////////////////////////////////////////
03831d35f7499c87d51205817c93e9a8d42c4baestevel if (!x && 0 !== x) {
03831d35f7499c87d51205817c93e9a8d42c4baestevel x += Math.max(d.documentElement.scrollLeft, b.scrollLeft);
03831d35f7499c87d51205817c93e9a8d42c4baestevel y += Math.max(d.documentElement.scrollTop, b.scrollTop);
03831d35f7499c87d51205817c93e9a8d42c4baestevel this._yuifacade = true;
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The native event
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @property _event
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The X location of the event on the page (including scroll)
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @property pageX
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @type int
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The Y location of the event on the page (including scroll)
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @property pageY
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @type int
03831d35f7499c87d51205817c93e9a8d42c4baestevel //////////////////////////////////////////////////////
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The keyCode for key events. Uses charCode if keyCode is not available
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @property keyCode
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @type int
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The charCode for key events. Same as keyCode
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @property charCode
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @type int
03831d35f7499c87d51205817c93e9a8d42c4baestevel //////////////////////////////////////////////////////
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The button that was pushed.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @property button
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @type int
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The button that was pushed. Same as button.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @property which
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @type int
03831d35f7499c87d51205817c93e9a8d42c4baestevel //////////////////////////////////////////////////////
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Node reference for the targeted element
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @propery target
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @type Node
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Node reference for the element that the listener was attached to.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @propery currentTarget
03831d35f7499c87d51205817c93e9a8d42c4baestevel * @type Node
t = e.relatedTarget;
t = e.toElement;
t = e.fromElement;
this.wheelDelta = (e.detail) ? (e.detail * -1) : Math.round(e.wheelDelta / 80) || ((e.wheelDelta < 0) ? -1 : 1);
this.stopPropagation = function() {
if (e.stopPropagation) {
e.stopPropagation();
e.cancelBubble = true;
this.stopImmediatePropagation = function() {
if (e.stopImmediatePropagation) {
this.stopPropagation();
if (e.preventDefault) {
e.preventDefault();
if (immediate) {
this.stopImmediatePropagation();
this.stopPropagation();
this.preventDefault();
onLoad = function() {
onUnload = function() {
shouldIterate = function(o) {
} catch(ex) {
Event = function() {
var _loadComplete = false,
_avail = [],
_windowLoadKey = null,
* addListener/removeListener can throw errors in unexpected scenarios.
lastError: null,
_interval: null,
_dri: null,
DOMReady: false,
startInterval: function() {
id: a[i],
_delete: function() {
return availHandle;
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) {
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