event-base-debug.js revision c8b2e9f045b5805162fe7488edfd8de133a341ba
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp/*
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * DOM event listener abstraction layer
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * @module event
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * @submodule event-base
0fdefaa9ca017edfb76b736c825b34186f33045aTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp(function() {
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp// Unlike most of the library, this code has to be executed as soon as it is
4ef2f7e4cb7c7d255be077c47d542199f7bf8607Tripp// introduced into the page -- and it should only be executed one time
a89ad754cce3cfc8aee71760e10217b54020360dTripp// regardless of the number of instances that use it.
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippvar GLOBAL_ENV = YUI.Env,
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp C = YUI.config,
a89ad754cce3cfc8aee71760e10217b54020360dTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp D = C.doc,
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp POLL_INTERVAL = C.pollInterval || 40,
c093c1aed867e18aa4778708592e1ceb45d18cffTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp _ready = function(e) {
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp GLOBAL_ENV._ready();
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (!GLOBAL_ENV._ready) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp GLOBAL_ENV._ready = function() {
c093c1aed867e18aa4778708592e1ceb45d18cffTripp if (!GLOBAL_ENV.DOMReady) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp GLOBAL_ENV.DOMReady=true;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Remove the DOMContentLoaded (FF/Opera/Safari)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (D.removeEventListener) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp D.removeEventListener("DOMContentLoaded", _ready, false);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // create custom event
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp/*! DOMReady: based on work by: Dean Edwards/John Resig/Matthias Miller/Diego Perini */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Internet Explorer: use the readyState of a defered script.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // This isolates what appears to be a safe moment to manipulate
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // the DOM prior to when the document's readyState suggests
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // it is safe to do so.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (navigator.userAgent.match(/MSIE/)) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (self !== self.top) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp document.onreadystatechange = function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (document.readyState == 'complete') {
c093c1aed867e18aa4778708592e1ceb45d18cffTripp document.onreadystatechange = null;
a89ad754cce3cfc8aee71760e10217b54020360dTripp _ready();
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
a89ad754cce3cfc8aee71760e10217b54020360dTripp } else {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp GLOBAL_ENV._dri = setInterval(function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp try {
a89ad754cce3cfc8aee71760e10217b54020360dTripp // throws an error if doc is not ready
a89ad754cce3cfc8aee71760e10217b54020360dTripp document.documentElement.doScroll('left');
a89ad754cce3cfc8aee71760e10217b54020360dTripp clearInterval(GLOBAL_ENV._dri);
a89ad754cce3cfc8aee71760e10217b54020360dTripp GLOBAL_ENV._dri = null;
a89ad754cce3cfc8aee71760e10217b54020360dTripp _ready();
a89ad754cce3cfc8aee71760e10217b54020360dTripp } catch (ex) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp }, POLL_INTERVAL);
c093c1aed867e18aa4778708592e1ceb45d18cffTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp // FireFox, Opera, Safari 3+: These browsers provide a event for this
a89ad754cce3cfc8aee71760e10217b54020360dTripp // moment.
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp } else {
a89ad754cce3cfc8aee71760e10217b54020360dTripp D.addEventListener("DOMContentLoaded", _ready, false);
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /////////////////////////////////////////////////////////////
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp})();
a89ad754cce3cfc8aee71760e10217b54020360dTrippYUI.add('event-base', function(Y) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp(function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp/*
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * DOM event listener abstraction layer
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @module event
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @submodule event-base
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippvar GLOBAL_ENV = YUI.Env,
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp yready = function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp Y.fire('domready');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippY.publish('domready', {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp fireOnce: true
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp});
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTrippif (GLOBAL_ENV.DOMReady) {
c093c1aed867e18aa4778708592e1ceb45d18cffTripp // console.log('DOMReady already fired', 'info', 'event');
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp yready();
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp} else {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp // console.log('setting up before listener', 'info', 'event');
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp // console.log('env: ' + YUI.Env.windowLoaded, 'info', 'event');
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp Y.before(yready, GLOBAL_ENV, "_ready");
527cf651dc5df871799abd06cf589bca3f3a665fTripp}
527cf651dc5df871799abd06cf589bca3f3a665fTripp
527cf651dc5df871799abd06cf589bca3f3a665fTripp})();
527cf651dc5df871799abd06cf589bca3f3a665fTripp(function() {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp/**
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * Custom event engine, DOM event listener abstraction layer, synthetic DOM
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * events.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @module event
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @submodule event-base
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
c093c1aed867e18aa4778708592e1ceb45d18cffTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp/**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Wraps a DOM event, properties requiring browser abstraction are
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * fixed here. Provids a security layer when required.
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * @class DOMEventFacade
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * @param ev {Event} the DOM event
527cf651dc5df871799abd06cf589bca3f3a665fTripp * @param currentTarget {HTMLElement} the element the listener was attached to
527cf651dc5df871799abd06cf589bca3f3a665fTripp * @param wrapper {Event.Custom} the custom event wrapper for this DOM event
527cf651dc5df871799abd06cf589bca3f3a665fTripp */
527cf651dc5df871799abd06cf589bca3f3a665fTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp/*
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @TODO constants? LEFTBUTTON, MIDDLEBUTTON, RIGHTBUTTON, keys
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp/*
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTrippvar whitelist = {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp altKey : 1,
c093c1aed867e18aa4778708592e1ceb45d18cffTripp // "button" : 1, // we supply
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "bubbles" : 1, // needed?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "cancelable" : 1, // needed?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "charCode" : 1, // we supply
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp cancelBubble : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "currentTarget" : 1, // we supply
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp ctrlKey : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp clientX : 1, // needed?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp clientY : 1, // needed?
bf801d6851ecf7ed14742ef3639a077daecb5cf8Tripp detail : 1, // not fully implemented
a4d2446149b07f9e5c32947091dcbcf4d2eee765Tripp // "fromElement" : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp keyCode : 1,
c093c1aed867e18aa4778708592e1ceb45d18cffTripp // "height" : 1, // needed?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "initEvent" : 1, // need the init events?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "initMouseEvent" : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "initUIEvent" : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "layerX" : 1, // needed?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "layerY" : 1, // needed?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp metaKey : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "modifiers" : 1, // needed?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "offsetX" : 1, // needed?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "offsetY" : 1, // needed?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "preventDefault" : 1, // we supply
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "reason" : 1, // IE proprietary
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "relatedTarget" : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "returnValue" : 1, // needed?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp shiftKey : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "srcUrn" : 1, // IE proprietary
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "srcElement" : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "srcFilter" : 1, IE proprietary
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "stopPropagation" : 1, // we supply
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "target" : 1,
c093c1aed867e18aa4778708592e1ceb45d18cffTripp // "timeStamp" : 1, // needed?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "toElement" : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp type : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "view" : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "which" : 1, // we supply
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // "width" : 1, // needed?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp x : 1,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp y : 1
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp},
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp*/
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var ua = Y.UA,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * webkit key remapping required for Safari < 3.1
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property webkitKeymap
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp webkitKeymap = {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp 63232: 38, // up
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp 63233: 40, // down
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp 63234: 37, // left
c093c1aed867e18aa4778708592e1ceb45d18cffTripp 63235: 39, // right
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp 63276: 33, // page up
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp 63277: 34, // page down
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp 25: 9, // SHIFT-TAB (Safari provides a different key code in
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // this case, even though the shiftKey modifier is set)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp 63272: 46, // delete
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp 63273: 36, // home
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp 63275: 35 // end
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Returns a wrapped node. Intended to be used on event targets,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * so it will return the node's parent if the target is a text
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * node.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * If accessing a property of the node throws an error, this is
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * probably the anonymous div wrapper Gecko adds inside text
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * nodes. This likely will only occur when attempting to access
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * the relatedTarget. In this case, we now return null because
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * the anonymous div is completely useless and we do not know
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * what the related target was because we can't even get to
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * the element's parent node.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method resolve
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp resolve = function(n) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp try {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (n && 3 == n.nodeType) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp n = n.parentNode;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } catch(e) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return null;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp return Y.one(n);
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp };
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp// provide a single event with browser abstractions resolved
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp//
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp// include all properties for both browers?
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp// include only DOM2 spec properties?
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp// provide browser-specific facade?
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp
a75ebc38c1de401b679953a9b87bd323f0f48d02TrippY.DOMEventFacade = function(ev, currentTarget, wrapper) {
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp wrapper = wrapper || {};
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp var e = ev, ot = currentTarget, d = Y.config.doc, b = d.body,
a89ad754cce3cfc8aee71760e10217b54020360dTripp x = e.pageX, y = e.pageY, c, t;
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.altKey = e.altKey;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.ctrlKey = e.ctrlKey;
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.metaKey = e.metaKey;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.shiftKey = e.shiftKey;
cec703a844d9691646231634fe709f4ea41d278aTripp this.type = e.type;
cec703a844d9691646231634fe709f4ea41d278aTripp this.clientX = e.clientX;
cec703a844d9691646231634fe709f4ea41d278aTripp this.clientY = e.clientY;
cec703a844d9691646231634fe709f4ea41d278aTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp //////////////////////////////////////////////////////
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (!x && 0 !== x) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp x = e.clientX || 0;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp y = e.clientY || 0;
cec703a844d9691646231634fe709f4ea41d278aTripp
cec703a844d9691646231634fe709f4ea41d278aTripp if (ua.ie) {
cec703a844d9691646231634fe709f4ea41d278aTripp x += Math.max(d.documentElement.scrollLeft, b.scrollLeft);
cec703a844d9691646231634fe709f4ea41d278aTripp y += Math.max(d.documentElement.scrollTop, b.scrollTop);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._yuifacade = true;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * The native event
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property _event
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._event = e;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The X location of the event on the page (including scroll)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property pageX
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type int
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.pageX = x;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * The Y location of the event on the page (including scroll)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property pageY
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type int
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.pageY = y;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //////////////////////////////////////////////////////
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp c = e.keyCode || e.charCode || 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (ua.webkit && (c in webkitKeymap)) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp c = webkitKeymap[c];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The keyCode for key events. Uses charCode if keyCode is not available
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @property keyCode
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type int
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.keyCode = c;
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The charCode for key events. Same as keyCode
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @property charCode
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type int
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.charCode = c;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp //////////////////////////////////////////////////////
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The button that was pushed.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @property button
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type int
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.button = e.which || e.button;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * The button that was pushed. Same as button.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property which
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type int
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.which = this.button;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //////////////////////////////////////////////////////
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Node reference for the targeted element
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @propery target
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Node
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.target = resolve(e.target || e.srcElement);
a89ad754cce3cfc8aee71760e10217b54020360dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Node reference for the element that the listener was attached to.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @propery currentTarget
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Node
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.currentTarget = resolve(ot);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp t = e.relatedTarget;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (!t) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (e.type == "mouseout") {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp t = e.toElement;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else if (e.type == "mouseover") {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp t = e.fromElement;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Node reference to the relatedTarget
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @propery relatedTarget
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Node
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp this.relatedTarget = resolve(t);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Number representing the direction and velocity of the movement of the mousewheel.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Negative is down, the higher the number, the faster. Applies to the mousewheel event.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property wheelDelta
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type int
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp */
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp if (e.type == "mousewheel" || e.type == "DOMMouseScroll") {
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp this.wheelDelta = (e.detail) ? (e.detail * -1) : Math.round(e.wheelDelta / 80) || ((e.wheelDelta < 0) ? -1 : 1);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //////////////////////////////////////////////////////
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // methods
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Stops the propagation to the next bubble target
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method stopPropagation
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.stopPropagation = function() {
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp if (e.stopPropagation) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp e.stopPropagation();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp } else {
a89ad754cce3cfc8aee71760e10217b54020360dTripp e.cancelBubble = true;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp wrapper.stopped = 1;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Stops the propagation to the next bubble target and
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * prevents any additional listeners from being exectued
a89ad754cce3cfc8aee71760e10217b54020360dTripp * on the current target.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method stopImmediatePropagation
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.stopImmediatePropagation = function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (e.stopImmediatePropagation) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp e.stopImmediatePropagation();
a89ad754cce3cfc8aee71760e10217b54020360dTripp } else {
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp this.stopPropagation();
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp wrapper.stopped = 2;
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Prevents the event's default behavior
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method preventDefault
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param returnValue {string} sets the returnValue of the event to this value
a89ad754cce3cfc8aee71760e10217b54020360dTripp * (rather than the default false value). This can be used to add a customized
a89ad754cce3cfc8aee71760e10217b54020360dTripp * confirmation query to the beforeunload event).
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.preventDefault = function(returnValue) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (e.preventDefault) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp e.preventDefault();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp e.returnValue = returnValue || false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp wrapper.prevented = 1;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Stops the event propagation and prevents the default
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * event behavior.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method halt
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param immediate {boolean} if true additional listeners
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * on the current target will not be executed
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.halt = function(immediate) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (immediate) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.stopImmediatePropagation();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.stopPropagation();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.preventDefault();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp})();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp(function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp/**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * DOM event listener abstraction layer
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @module event
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @submodule event-base
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp/**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The event utility provides functions to add and remove event listeners,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * event cleansing. It also tries to automatically remove listeners it
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * registers during the unload event.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @class Event
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @static
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTrippY.Env.evt.dom_wrappers = {};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTrippY.Env.evt.dom_map = {};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTrippvar _eventenv = Y.Env.evt,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTrippadd = YUI.Env.add,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippremove = YUI.Env.remove,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripponLoad = function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp YUI.Env.windowLoaded = true;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.Event._load();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp remove(window, "load", onLoad);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp},
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripponUnload = function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.Event._unload();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp remove(window, "unload", onUnload);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp},
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTrippEVENT_READY = 'domready',
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTrippCOMPAT_ARG = '~yui|2|compat~',
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTrippshouldIterate = function(o) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp try {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return (o && typeof o !== "string" && Y.Lang.isNumber(o.length) && !o.tagName && !o.alert);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } catch(ex) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.log("collection check failure", "warn", "event");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return false;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp},
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTrippEvent = function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * True after the onload event has fired
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property _loadComplete
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type boolean
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @static
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var _loadComplete = false,
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * The number of times to poll after window.onload. This number is
cec703a844d9691646231634fe709f4ea41d278aTripp * increased if additional late-bound handlers are requested after
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * the page load.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @property _retryCount
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * @static
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * @private
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp */
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp _retryCount = 0,
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp /**
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * onAvailable listeners
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * @property _avail
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * @static
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * @private
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp */
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp _avail = [],
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Custom event wrappers for DOM events. Key is
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * 'event:' + Element uid stamp + event type
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @property _wrappers
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Y.Event.Custom
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @static
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _wrappers = _eventenv.dom_wrappers,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp _windowLoadKey = null,
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Custom event wrapper map DOM events. Key is
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Element uid stamp. Each item is a hash of custom event
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * wrappers as provided in the _wrappers collection. This
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * provides the infrastructure for getListeners.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property _el_events
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @static
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _el_events = _eventenv.dom_map;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * The number of times we should look for elements that are not
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * in the DOM at the time the event is requested after the document
9eaaa502227248d304ac9170902697d02158c1d9Tripp * has been loaded. The default is 1000@amp;40 ms, so it will poll
9eaaa502227248d304ac9170902697d02158c1d9Tripp * for 40 seconds or until all outstanding handlers are bound
9eaaa502227248d304ac9170902697d02158c1d9Tripp * (whichever comes first).
9eaaa502227248d304ac9170902697d02158c1d9Tripp * @property POLL_RETRYS
9eaaa502227248d304ac9170902697d02158c1d9Tripp * @type int
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @static
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @final
4ef2f7e4cb7c7d255be077c47d542199f7bf8607Tripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp POLL_RETRYS: 1000,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The poll interval in milliseconds
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property POLL_INTERVAL
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type int
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @static
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @final
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp POLL_INTERVAL: 40,
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * addListener/removeListener can throw errors in unexpected scenarios.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * These errors are suppressed, the method returns false, and this property
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * is set
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property lastError
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @static
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp * @type Error
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp lastError: null,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * poll handle
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @property _interval
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @static
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @private
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _interval: null,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * document readystate poll handle
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property _dri
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @static
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _dri: null,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * True when the document is initially usable
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property DOMReady
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type boolean
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @static
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp DOMReady: false,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method startInterval
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @static
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
0fdefaa9ca017edfb76b736c825b34186f33045aTripp startInterval: function() {
0fdefaa9ca017edfb76b736c825b34186f33045aTripp var E = Y.Event;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (!E._interval) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTrippE._interval = setInterval(Y.bind(E._poll, E), E.POLL_INTERVAL);
0fdefaa9ca017edfb76b736c825b34186f33045aTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Executes the supplied callback when the item with the supplied
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * id is found. This is meant to be used to execute behavior as
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * soon as possible as the page loads. If you use this after the
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * initial page load it will poll for a fixed time for the element.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The number of times it will poll and the frequency are
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * configurable. By default it will poll for 10 seconds.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <p>The callback is executed with a single parameter:
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * the custom object parameter, if provided.</p>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method onAvailable
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {string||string[]} id the id of the element, or an array
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * of ids to look for.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {function} fn what to execute when the element is found.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {object} p_obj an optional object to be passed back as
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * a parameter to fn.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {boolean|object} p_override If set to true, fn will execute
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * in the context of p_obj, if set to an object it
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * will execute in the context of that object
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param checkContent {boolean} check child node readiness (onContentReady)
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @static
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @deprecated Use Y.on("available")
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp // @TODO fix arguments
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp onAvailable: function(id, fn, p_obj, p_override, checkContent, compat) {
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp var a = Y.Array(id), i, availHandle;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Y.log('onAvailable registered for: ' + id);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (i=0; i<a.length; i=i+1) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _avail.push({
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp id: a[i],
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp fn: fn,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp obj: p_obj,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp override: p_override,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp checkReady: checkContent,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp compat: compat
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp });
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _retryCount = this.POLL_RETRYS;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // We want the first test to be immediate, but async
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp setTimeout(Y.bind(Y.Event._poll, Y.Event), 0);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp availHandle = new Y.EventHandle({
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _delete: function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // set by the event system for lazy DOM listeners
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (availHandle.handle) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp availHandle.handle.detach();
a89ad754cce3cfc8aee71760e10217b54020360dTripp return;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var i, j;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // otherwise try to remove the onAvailable listener(s)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (i = 0; i < a.length; i++) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp for (j = 0; j < _avail.length; j++) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (a[i] === _avail[j].id) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _avail.splice(j, 1);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp });
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return availHandle;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Works the same way as onAvailable, but additionally checks the
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * state of sibling elements to determine if the content of the
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * available element is safe to modify.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <p>The callback is executed with a single parameter:
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * the custom object parameter, if provided.</p>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method onContentReady
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {string} id the id of the element to look for.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {function} fn what to execute when the element is ready.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {object} p_obj an optional object to be passed back as
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * a parameter to fn.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {boolean|object} p_override If set to true, fn will execute
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp * in the context of p_obj. If an object, fn will
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * exectute in the context of that object
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @static
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @deprecated Use Y.on("contentready")
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @TODO fix arguments
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp onContentReady: function(id, fn, p_obj, p_override, compat) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this.onAvailable(id, fn, p_obj, p_override, true, compat);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Adds an event listener
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @method attach
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * @param {String} type The type of event to append
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Function} fn The method the event invokes
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String|HTMLElement|Array|NodeList} el An id, an element
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * reference, or a collection of ids and/or elements to assign the
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * listener to.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Object} context optional context object
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Boolean|object} args 0..n arguments to pass to the callback
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return {EventHandle} an object to that can be used to detach the listener
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @static
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp attach: function(type, fn, el, context) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return Y.Event._attach(Y.Array(arguments, 0, true));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _createWrapper: function (el, type, capture, compat, facade) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var ek = Y.stamp(el),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp key = 'event:' + ek + type,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cewrapper;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (false === facade) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp key += 'native';
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (capture) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp key += 'capture';
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp cewrapper = _wrappers[key];
a89ad754cce3cfc8aee71760e10217b54020360dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (!cewrapper) {
// create CE wrapper
cewrapper = Y.publish(key, {
silent: true,
bubbles: false,
contextFn: function() {
if (compat) {
return cewrapper.el;
} else {
cewrapper.nodeRef = cewrapper.nodeRef || Y.one(cewrapper.el);
return cewrapper.nodeRef;
}
}
});
// for later removeListener calls
cewrapper.el = el;
cewrapper.key = key;
cewrapper.domkey = ek;
cewrapper.type = type;
cewrapper.fn = function(e) {
cewrapper.fire(Y.Event.getEvent(e, el, (compat || (false === facade))));
};
cewrapper.capture = capture;
if (el == Y.config.win && type == "load") {
// window load happens once
cewrapper.fireOnce = true;
_windowLoadKey = key;
}
_wrappers[key] = cewrapper;
_el_events[ek] = _el_events[ek] || {};
_el_events[ek][key] = cewrapper;
add(el, type, cewrapper.fn, capture);
}
return cewrapper;
},
_attach: function(args, config) {
var compat, E=Y.Event,
handles, oEl, cewrapper, context,
fireNow = false, ret,
type = args[0],
fn = args[1],
el = args[2] || Y.config.win,
facade = config && config.facade,
capture = config && config.capture;
if (args[args.length-1] === COMPAT_ARG) {
compat = true;
// trimmedArgs.pop();
}
if (!fn || !fn.call) {
// throw new TypeError(type + " attach call failed, callback undefined");
Y.log(type + " attach call failed, invalid callback", "error", "event");
return false;
}
// The el argument can be an array of elements or element ids.
if (shouldIterate(el)) {
handles=[];
Y.each(el, function(v, k) {
args[2] = v;
handles.push(E._attach(args, config));
});
// return (handles.length === 1) ? handles[0] : handles;
return new Y.EventHandle(handles);
// If the el argument is a string, we assume it is
// actually the id of the element. If the page is loaded
// we convert el to the actual element, otherwise we
// defer attaching the event until the element is
// ready
} else if (Y.Lang.isString(el)) {
// oEl = (compat) ? Y.DOM.byId(el) : Y.Selector.query(el);
if (compat) {
oEl = Y.DOM.byId(el);
} else {
oEl = Y.Selector.query(el);
switch (oEl.length) {
case 0:
oEl = null;
break;
case 1:
oEl = oEl[0];
break;
default:
args[2] = oEl;
return E._attach(args, config);
}
}
if (oEl) {
el = oEl;
// Not found = defer adding the event until the element is available
} else {
// Y.log(el + ' not found');
ret = this.onAvailable(el, function() {
// Y.log('lazy attach: ' + args);
ret.handle = E._attach(args, config);
}, E, true, false, compat);
return ret;
}
}
// Element should be an html element or node
if (!el) {
Y.log("unable to attach event " + type, "warn", "event");
return false;
}
if (Y.Node && el instanceof Y.Node) {
el = Y.Node.getDOMNode(el);
}
cewrapper = this._createWrapper(el, type, capture, compat, facade);
if (el == Y.config.win && type == "load") {
// if the load is complete, fire immediately.
// all subscribers, including the current one
// will be notified.
if (YUI.Env.windowLoaded) {
fireNow = true;
}
}
if (compat) {
args.pop();
}
context = args[3];
// set context to the Node if not specified
// ret = cewrapper.on.apply(cewrapper, trimmedArgs);
ret = cewrapper._on(fn, context, (args.length > 4) ? args.slice(4) : null);
if (fireNow) {
cewrapper.fire();
}
return ret;
},
/**
* Removes an event listener. Supports the signature the event was bound
* with, but the preferred way to remove listeners is using the handle
* that is returned when using Y.on
*
* @method detach
*
* @param {String} type the type of event to remove.
* @param {Function} fn the method the event invokes. If fn is
* undefined, then all event handlers for the type of event are
* removed.
* @param {String|HTMLElement|Array|NodeList|EventHandle} el An
* event handle, an id, an element reference, or a collection
* of ids and/or elements to remove the listener from.
* @return {boolean} true if the unbind was successful, false otherwise.
* @static
*/
detach: function(type, fn, el, obj) {
var args=Y.Array(arguments, 0, true), compat, i, l, ok,
id, ce;
if (args[args.length-1] === COMPAT_ARG) {
compat = true;
// args.pop();
}
if (type && type.detach) {
return type.detach();
}
// The el argument can be a string
if (typeof el == "string") {
// el = (compat) ? Y.DOM.byId(el) : Y.all(el);
if (compat) {
el = Y.DOM.byId(el);
} else {
el = Y.Selector.query(el);
l = el.length;
if (l < 1) {
el = null;
} else if (l == 1) {
el = el[0];
}
}
// return Y.Event.detach.apply(Y.Event, args);
// The el argument can be an array of elements or element ids.
}
if (!el) {
return false;
}
if (shouldIterate(el)) {
ok = true;
for (i=0, l=el.length; i<l; ++i) {
args[2] = el[i];
ok = ( Y.Event.detach.apply(Y.Event, args) && ok );
}
return ok;
}
if (!type || !fn || !fn.call) {
return this.purgeElement(el, false, type);
}
id = 'event:' + Y.stamp(el) + type;
ce = _wrappers[id];
if (ce) {
return ce.detach(fn);
} else {
return false;
}
},
/**
* Finds the event in the window object, the caller's arguments, or
* in the arguments of another method in the callstack. This is
* executed automatically for events registered through the event
* manager, so the implementer should not normally need to execute
* this function at all.
* @method getEvent
* @param {Event} e the event parameter from the handler
* @param {HTMLElement} el the element the listener was attached to
* @return {Event} the event
* @static
*/
getEvent: function(e, el, noFacade) {
var ev = e || window.event;
return (noFacade) ? ev :
new Y.DOMEventFacade(ev, el, _wrappers['event:' + Y.stamp(el) + e.type]);
},
/**
* Generates an unique ID for the element if it does not already
* have one.
* @method generateId
* @param el the element to create the id for
* @return {string} the resulting id of the element
* @static
*/
generateId: function(el) {
var id = el.id;
if (!id) {
id = Y.stamp(el);
el.id = id;
}
return id;
},
/**
* We want to be able to use getElementsByTagName as a collection
* to attach a group of events to. Unfortunately, different
* browsers return different types of collections. This function
* tests to determine if the object is array-like. It will also
* fail if the object is an array, but is empty.
* @method _isValidCollection
* @param o the object to test
* @return {boolean} true if the object is array-like and populated
* @deprecated was not meant to be used directly
* @static
* @private
*/
_isValidCollection: shouldIterate,
/**
* hook up any deferred listeners
* @method _load
* @static
* @private
*/
_load: function(e) {
if (!_loadComplete) {
// Y.log('Load Complete', 'info', 'event');
_loadComplete = true;
// Just in case DOMReady did not go off for some reason
// E._ready();
if (Y.fire) {
Y.fire(EVENT_READY);
}
// Available elements may not have been detected before the
// window load event fires. Try to find them now so that the
// the user is more likely to get the onAvailable notifications
// before the window load notification
Y.Event._poll();
}
},
/**
* Polling function that runs before the onload event fires,
* attempting to attach to DOM Nodes as soon as they are
* available
* @method _poll
* @static
* @private
*/
_poll: function() {
if (this.locked) {
return;
}
if (Y.UA.ie && !YUI.Env.DOMReady) {
// Hold off if DOMReady has not fired and check current
// readyState to protect against the IE operation aborted
// issue.
this.startInterval();
return;
}
this.locked = true;
// Y.log.debug("poll");
// keep trying until after the page is loaded. We need to
// check the page load state prior to trying to bind the
// elements so that we can be certain all elements have been
// tested appropriately
var tryAgain = !_loadComplete, notAvail, executeItem,
i, len, item, el;
if (!tryAgain) {
tryAgain = (_retryCount > 0);
}
// onAvailable
notAvail = [];
executeItem = function (el, item) {
var context, ov = item.override;
if (item.compat) {
if (item.override) {
if (ov === true) {
context = item.obj;
} else {
context = ov;
}
} else {
context = el;
}
item.fn.call(context, item.obj);
} else {
context = item.obj || Y.one(el);
item.fn.apply(context, (Y.Lang.isArray(ov)) ? ov : []);
}
};
// onAvailable
for (i=0,len=_avail.length; i<len; ++i) {
item = _avail[i];
if (item && !item.checkReady) {
// el = (item.compat) ? Y.DOM.byId(item.id) : Y.one(item.id);
el = (item.compat) ? Y.DOM.byId(item.id) : Y.Selector.query(item.id, null, true);
if (el) {
// Y.log('avail: ' + el);
executeItem(el, item);
_avail[i] = null;
} else {
// Y.log('NOT avail: ' + el);
notAvail.push(item);
}
}
}
// onContentReady
for (i=0,len=_avail.length; i<len; ++i) {
item = _avail[i];
if (item && item.checkReady) {
// el = (item.compat) ? Y.DOM.byId(item.id) : Y.one(item.id);
el = (item.compat) ? Y.DOM.byId(item.id) : Y.Selector.query(item.id, null, true);
if (el) {
// The element is available, but not necessarily ready
// @todo should we test parentNode.nextSibling?
if (_loadComplete || (el.get && el.get('nextSibling')) || el.nextSibling) {
executeItem(el, item);
_avail[i] = null;
}
} else {
notAvail.push(item);
}
}
}
_retryCount = (notAvail.length === 0) ? 0 : _retryCount - 1;
if (tryAgain) {
// we may need to strip the nulled out items here
this.startInterval();
} else {
clearInterval(this._interval);
this._interval = null;
}
this.locked = false;
return;
},
/**
* Removes all listeners attached to the given element via addListener.
* Optionally, the node's children can also be purged.
* Optionally, you can specify a specific type of event to remove.
* @method purgeElement
* @param {HTMLElement} el the element to purge
* @param {boolean} recurse recursively purge this element's children
* as well. Use with caution.
* @param {string} type optional type of listener to purge. If
* left out, all listeners will be removed
* @static
*/
purgeElement: function(el, recurse, type) {
// var oEl = (Y.Lang.isString(el)) ? Y.one(el) : el,
var oEl = (Y.Lang.isString(el)) ? Y.Selector.query(el, null, true) : el,
lis = this.getListeners(oEl, type), i, len, props;
if (lis) {
for (i=0,len=lis.length; i<len ; ++i) {
props = lis[i];
props.detachAll();
remove(props.el, props.type, props.fn, props.capture);
delete _wrappers[props.key];
delete _el_events[props.domkey][props.key];
}
}
if (recurse && oEl && oEl.childNodes) {
for (i=0,len=oEl.childNodes.length; i<len ; ++i) {
this.purgeElement(oEl.childNodes[i], recurse, type);
}
}
},
/**
* Returns all listeners attached to the given element via addListener.
* Optionally, you can specify a specific type of event to return.
* @method getListeners
* @param el {HTMLElement|string} the element or element id to inspect
* @param type {string} optional type of listener to return. If
* left out, all listeners will be returned
* @return {Y.Custom.Event} the custom event wrapper for the DOM event(s)
* @static
*/
getListeners: function(el, type) {
var ek = Y.stamp(el, true), evts = _el_events[ek],
results=[] , key = (type) ? 'event:' + ek + type : null;
if (!evts) {
return null;
}
if (key) {
if (evts[key]) {
results.push(evts[key]);
}
// get native events as well
key += 'native';
if (evts[key]) {
results.push(evts[key]);
}
} else {
Y.each(evts, function(v, k) {
results.push(v);
});
}
return (results.length) ? results : null;
},
/**
* Removes all listeners registered by pe.event. Called
* automatically during the unload event.
* @method _unload
* @static
* @private
*/
_unload: function(e) {
Y.each(_wrappers, function(v, k) {
v.detachAll();
remove(v.el, v.type, v.fn, v.capture);
delete _wrappers[k];
delete _el_events[v.domkey][k];
});
},
/**
* Adds a DOM event directly without the caching, cleanup, context adj, etc
*
* @method nativeAdd
* @param {HTMLElement} el the element to bind the handler to
* @param {string} type the type of event handler
* @param {function} fn the callback to invoke
* @param {boolen} capture capture or bubble phase
* @static
* @private
*/
nativeAdd: add,
/**
* Basic remove listener
*
* @method nativeRemove
* @param {HTMLElement} el the element to bind the handler to
* @param {string} type the type of event handler
* @param {function} fn the callback to invoke
* @param {boolen} capture capture or bubble phase
* @static
* @private
*/
nativeRemove: remove
};
}();
Y.Event = Event;
if (Y.config.injected || YUI.Env.windowLoaded) {
onLoad();
} else {
add(window, "load", onLoad);
}
// Process onAvailable/onContentReady items when when the DOM is ready in IE
if (Y.UA.ie) {
Y.on(EVENT_READY, Event._poll, Event, true);
}
Y.on("unload", onUnload);
Event.Custom = Y.CustomEvent;
Event.Subscriber = Y.Subscriber;
Event.Target = Y.EventTarget;
Event.Handle = Y.EventHandle;
Event.Facade = Y.EventFacade;
Event._poll();
})();
/**
* DOM event listener abstraction layer
* @module event
* @submodule event-base
*/
/**
* Executes the callback as soon as the specified element
* is detected in the DOM.
* @event available
* @param type {string} 'available'
* @param fn {function} the callback function to execute.
* @param el {string|HTMLElement|collection} the element(s) to attach
* @param context optional argument that specifies what 'this' refers to.
* @param args* 0..n additional arguments to pass on to the callback function.
* These arguments will be added after the event object.
* @return {EventHandle} the detach handle
* @for YUI
*/
Y.Env.evt.plugins.available = {
on: function(type, fn, id, o) {
var a = arguments.length > 4 ? Y.Array(arguments, 4, true) : [];
return Y.Event.onAvailable.call(Y.Event, id, fn, o, a);
}
};
/**
* Executes the callback as soon as the specified element
* is detected in the DOM with a nextSibling property
* (indicating that the element's children are available)
* @event contentready
* @param type {string} 'contentready'
* @param fn {function} the callback function to execute.
* @param el {string|HTMLElement|collection} the element(s) to attach
* @param context optional argument that specifies what 'this' refers to.
* @param args* 0..n additional arguments to pass on to the callback function.
* These arguments will be added after the event object.
* @return {EventHandle} the detach handle
* @for YUI
*/
Y.Env.evt.plugins.contentready = {
on: function(type, fn, id, o) {
var a = arguments.length > 4 ? Y.Array(arguments, 4, true) : [];
return Y.Event.onContentReady.call(Y.Event, id, fn, o, a);
}
};
}, '@VERSION@' ,{requires:['event-custom-base']});