You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2009/04/09 15:31:55 UTC
svn commit: r763645 [5/8] - in
/wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui:
./ assets/skins/sam/ calendar/ calendar/assets/skins/sam/ dom/ event/
yahoo-dom-event/ yahoo/
Added: wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/event/event-min.js
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/event/event-min.js?rev=763645&view=auto
==============================================================================
--- wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/event/event-min.js (added)
+++ wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/event/event-min.js Thu Apr 9 13:31:54 2009
@@ -0,0 +1,11 @@
+/*
+Copyright (c) 2009, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.7.0
+*/
+YAHOO.util.CustomEvent=function(D,C,B,A){this.type=D;this.scope=C||window;this.silent=B;this.signature=A||YAHOO.util.CustomEvent.LIST;this.subscribers=[];if(!this.silent){}var E="_YUICEOnSubscribe";if(D!==E){this.subscribeEvent=new YAHOO.util.CustomEvent(E,this,true);}this.lastError=null;};YAHOO.util.CustomEvent.LIST=0;YAHOO.util.CustomEvent.FLAT=1;YAHOO.util.CustomEvent.prototype={subscribe:function(A,B,C){if(!A){throw new Error("Invalid callback for subscriber to '"+this.type+"'");}if(this.subscribeEvent){this.subscribeEvent.fire(A,B,C);}this.subscribers.push(new YAHOO.util.Subscriber(A,B,C));},unsubscribe:function(D,F){if(!D){return this.unsubscribeAll();}var E=false;for(var B=0,A=this.subscribers.length;B<A;++B){var C=this.subscribers[B];if(C&&C.contains(D,F)){this._delete(B);E=true;}}return E;},fire:function(){this.lastError=null;var K=[],E=this.subscribers.length;if(!E&&this.silent){return true;}var I=[].slice.call(arguments,0),G=true,D,J=false;if(!this.silent){}var C=
this.subscribers.slice(),A=YAHOO.util.Event.throwErrors;for(D=0;D<E;++D){var M=C[D];if(!M){J=true;}else{if(!this.silent){}var L=M.getScope(this.scope);if(this.signature==YAHOO.util.CustomEvent.FLAT){var B=null;if(I.length>0){B=I[0];}try{G=M.fn.call(L,B,M.obj);}catch(F){this.lastError=F;if(A){throw F;}}}else{try{G=M.fn.call(L,this.type,I,M.obj);}catch(H){this.lastError=H;if(A){throw H;}}}if(false===G){if(!this.silent){}break;}}}return(G!==false);},unsubscribeAll:function(){var A=this.subscribers.length,B;for(B=A-1;B>-1;B--){this._delete(B);}this.subscribers=[];return A;},_delete:function(A){var B=this.subscribers[A];if(B){delete B.fn;delete B.obj;}this.subscribers.splice(A,1);},toString:function(){return"CustomEvent: "+"'"+this.type+"', "+"context: "+this.scope;}};YAHOO.util.Subscriber=function(A,B,C){this.fn=A;this.obj=YAHOO.lang.isUndefined(B)?null:B;this.overrideContext=C;};YAHOO.util.Subscriber.prototype.getScope=function(A){if(this.overrideContext){if(this.overrideContex
t===true){return this.obj;}else{return this.overrideContext;}}return A;};YAHOO.util.Subscriber.prototype.contains=function(A,B){if(B){return(this.fn==A&&this.obj==B);}else{return(this.fn==A);}};YAHOO.util.Subscriber.prototype.toString=function(){return"Subscriber { obj: "+this.obj+", overrideContext: "+(this.overrideContext||"no")+" }";};if(!YAHOO.util.Event){YAHOO.util.Event=function(){var H=false;var I=[];var J=[];var G=[];var E=[];var C=0;var F=[];var B=[];var A=0;var D={63232:38,63233:40,63234:37,63235:39,63276:33,63277:34,25:9};var K=YAHOO.env.ua.ie?"focusin":"focus";var L=YAHOO.env.ua.ie?"focusout":"blur";return{POLL_RETRYS:2000,POLL_INTERVAL:20,EL:0,TYPE:1,FN:2,WFN:3,UNLOAD_OBJ:3,ADJ_SCOPE:4,OBJ:5,OVERRIDE:6,lastError:null,isSafari:YAHOO.env.ua.webkit,webkit:YAHOO.env.ua.webkit,isIE:YAHOO.env.ua.ie,_interval:null,_dri:null,DOMReady:false,throwErrors:false,startInterval:function(){if(!this._interval){var M=this;var N=function(){M._tryPreloadAttach();};this._interval=se
tInterval(N,this.POLL_INTERVAL);}},onAvailable:function(S,O,Q,R,P){var M=(YAHOO.lang.isString(S))?[S]:S;for(var N=0;N<M.length;N=N+1){F.push({id:M[N],fn:O,obj:Q,overrideContext:R,checkReady:P});}C=this.POLL_RETRYS;this.startInterval();},onContentReady:function(P,M,N,O){this.onAvailable(P,M,N,O,true);},onDOMReady:function(M,N,O){if(this.DOMReady){setTimeout(function(){var P=window;if(O){if(O===true){P=N;}else{P=O;}}M.call(P,"DOMReady",[],N);},0);}else{this.DOMReadyEvent.subscribe(M,N,O);}},_addListener:function(O,M,Y,S,W,b){if(!Y||!Y.call){return false;}if(this._isValidCollection(O)){var Z=true;for(var T=0,V=O.length;T<V;++T){Z=this.on(O[T],M,Y,S,W)&&Z;}return Z;}else{if(YAHOO.lang.isString(O)){var R=this.getEl(O);if(R){O=R;}else{this.onAvailable(O,function(){YAHOO.util.Event.on(O,M,Y,S,W);});return true;}}}if(!O){return false;}if("unload"==M&&S!==this){J[J.length]=[O,M,Y,S,W];return true;}var N=O;if(W){if(W===true){N=S;}else{N=W;}}var P=function(c){return Y.call(N,YAHOO.util
.Event.getEvent(c,O),S);};var a=[O,M,Y,P,N,S,W];var U=I.length;I[U]=a;if(this.useLegacyEvent(O,M)){var Q=this.getLegacyIndex(O,M);if(Q==-1||O!=G[Q][0]){Q=G.length;B[O.id+M]=Q;G[Q]=[O,M,O["on"+M]];E[Q]=[];O["on"+M]=function(c){YAHOO.util.Event.fireLegacyEvent(YAHOO.util.Event.getEvent(c),Q);};}E[Q].push(a);}else{try{this._simpleAdd(O,M,P,b);}catch(X){this.lastError=X;this.removeListener(O,M,Y);return false;}}return true;},addListener:function(N,Q,M,O,P){return this._addListener(N,Q,M,O,P,false);},addFocusListener:function(N,M,O,P){return this._addListener(N,K,M,O,P,true);},removeFocusListener:function(N,M){return this.removeListener(N,K,M);},addBlurListener:function(N,M,O,P){return this._addListener(N,L,M,O,P,true);},removeBlurListener:function(N,M){return this.removeListener(N,L,M);},fireLegacyEvent:function(R,P){var T=true,M,V,U,N,S;V=E[P].slice();for(var O=0,Q=V.length;O<Q;++O){U=V[O];if(U&&U[this.WFN]){N=U[this.ADJ_SCOPE];S=U[this.WFN].call(N,R);T=(T&&S);}}M=G[P];if(M&&M[
2]){M[2](R);}return T;},getLegacyIndex:function(N,O){var M=this.generateId(N)+O;if(typeof B[M]=="undefined"){return -1;}else{return B[M];}},useLegacyEvent:function(M,N){return(this.webkit&&this.webkit<419&&("click"==N||"dblclick"==N));},removeListener:function(N,M,V){var Q,T,X;if(typeof N=="string"){N=this.getEl(N);}else{if(this._isValidCollection(N)){var W=true;for(Q=N.length-1;Q>-1;Q--){W=(this.removeListener(N[Q],M,V)&&W);}return W;}}if(!V||!V.call){return this.purgeElement(N,false,M);}if("unload"==M){for(Q=J.length-1;Q>-1;Q--){X=J[Q];if(X&&X[0]==N&&X[1]==M&&X[2]==V){J.splice(Q,1);return true;}}return false;}var R=null;var S=arguments[3];if("undefined"===typeof S){S=this._getCacheIndex(N,M,V);}if(S>=0){R=I[S];}if(!N||!R){return false;}if(this.useLegacyEvent(N,M)){var P=this.getLegacyIndex(N,M);var O=E[P];if(O){for(Q=0,T=O.length;Q<T;++Q){X=O[Q];if(X&&X[this.EL]==N&&X[this.TYPE]==M&&X[this.FN]==V){O.splice(Q,1);break;}}}}else{try{this._simpleRemove(N,M,R[this.WFN],false);}
catch(U){this.lastError=U;return false;}}delete I[S][this.WFN];delete I[S][this.FN];
+I.splice(S,1);return true;},getTarget:function(O,N){var M=O.target||O.srcElement;return this.resolveTextNode(M);},resolveTextNode:function(N){try{if(N&&3==N.nodeType){return N.parentNode;}}catch(M){}return N;},getPageX:function(N){var M=N.pageX;if(!M&&0!==M){M=N.clientX||0;if(this.isIE){M+=this._getScrollLeft();}}return M;},getPageY:function(M){var N=M.pageY;if(!N&&0!==N){N=M.clientY||0;if(this.isIE){N+=this._getScrollTop();}}return N;},getXY:function(M){return[this.getPageX(M),this.getPageY(M)];},getRelatedTarget:function(N){var M=N.relatedTarget;if(!M){if(N.type=="mouseout"){M=N.toElement;}else{if(N.type=="mouseover"){M=N.fromElement;}}}return this.resolveTextNode(M);},getTime:function(O){if(!O.time){var N=new Date().getTime();try{O.time=N;}catch(M){this.lastError=M;return N;}}return O.time;},stopEvent:function(M){this.stopPropagation(M);this.preventDefault(M);},stopPropagation:function(M){if(M.stopPropagation){M.stopPropagation();}else{M.cancelBubble=true;}},preventDefaul
t:function(M){if(M.preventDefault){M.preventDefault();}else{M.returnValue=false;}},getEvent:function(O,M){var N=O||window.event;if(!N){var P=this.getEvent.caller;while(P){N=P.arguments[0];if(N&&Event==N.constructor){break;}P=P.caller;}}return N;},getCharCode:function(N){var M=N.keyCode||N.charCode||0;if(YAHOO.env.ua.webkit&&(M in D)){M=D[M];}return M;},_getCacheIndex:function(Q,R,P){for(var O=0,N=I.length;O<N;O=O+1){var M=I[O];if(M&&M[this.FN]==P&&M[this.EL]==Q&&M[this.TYPE]==R){return O;}}return -1;},generateId:function(M){var N=M.id;if(!N){N="yuievtautoid-"+A;++A;M.id=N;}return N;},_isValidCollection:function(N){try{return(N&&typeof N!=="string"&&N.length&&!N.tagName&&!N.alert&&typeof N[0]!=="undefined");}catch(M){return false;}},elCache:{},getEl:function(M){return(typeof M==="string")?document.getElementById(M):M;},clearCache:function(){},DOMReadyEvent:new YAHOO.util.CustomEvent("DOMReady",this),_load:function(N){if(!H){H=true;var M=YAHOO.util.Event;M._ready();M._tryPrelo
adAttach();}},_ready:function(N){var M=YAHOO.util.Event;if(!M.DOMReady){M.DOMReady=true;M.DOMReadyEvent.fire();M._simpleRemove(document,"DOMContentLoaded",M._ready);}},_tryPreloadAttach:function(){if(F.length===0){C=0;if(this._interval){clearInterval(this._interval);this._interval=null;}return;}if(this.locked){return;}if(this.isIE){if(!this.DOMReady){this.startInterval();return;}}this.locked=true;var S=!H;if(!S){S=(C>0&&F.length>0);}var R=[];var T=function(V,W){var U=V;if(W.overrideContext){if(W.overrideContext===true){U=W.obj;}else{U=W.overrideContext;}}W.fn.call(U,W.obj);};var N,M,Q,P,O=[];for(N=0,M=F.length;N<M;N=N+1){Q=F[N];if(Q){P=this.getEl(Q.id);if(P){if(Q.checkReady){if(H||P.nextSibling||!S){O.push(Q);F[N]=null;}}else{T(P,Q);F[N]=null;}}else{R.push(Q);}}}for(N=0,M=O.length;N<M;N=N+1){Q=O[N];T(this.getEl(Q.id),Q);}C--;if(S){for(N=F.length-1;N>-1;N--){Q=F[N];if(!Q||!Q.id){F.splice(N,1);}}this.startInterval();}else{if(this._interval){clearInterval(this._interval);this._
interval=null;}}this.locked=false;},purgeElement:function(Q,R,T){var O=(YAHOO.lang.isString(Q))?this.getEl(Q):Q;var S=this.getListeners(O,T),P,M;if(S){for(P=S.length-1;P>-1;P--){var N=S[P];this.removeListener(O,N.type,N.fn);}}if(R&&O&&O.childNodes){for(P=0,M=O.childNodes.length;P<M;++P){this.purgeElement(O.childNodes[P],R,T);}}},getListeners:function(O,M){var R=[],N;if(!M){N=[I,J];}else{if(M==="unload"){N=[J];}else{N=[I];}}var T=(YAHOO.lang.isString(O))?this.getEl(O):O;for(var Q=0;Q<N.length;Q=Q+1){var V=N[Q];if(V){for(var S=0,U=V.length;S<U;++S){var P=V[S];if(P&&P[this.EL]===T&&(!M||M===P[this.TYPE])){R.push({type:P[this.TYPE],fn:P[this.FN],obj:P[this.OBJ],adjust:P[this.OVERRIDE],scope:P[this.ADJ_SCOPE],index:S});}}}}return(R.length)?R:null;},_unload:function(T){var N=YAHOO.util.Event,Q,P,O,S,R,U=J.slice(),M;for(Q=0,S=J.length;Q<S;++Q){O=U[Q];if(O){M=window;if(O[N.ADJ_SCOPE]){if(O[N.ADJ_SCOPE]===true){M=O[N.UNLOAD_OBJ];}else{M=O[N.ADJ_SCOPE];}}O[N.FN].call(M,N.getEvent(T,O[
N.EL]),O[N.UNLOAD_OBJ]);U[Q]=null;}}O=null;M=null;J=null;if(I){for(P=I.length-1;P>-1;P--){O=I[P];if(O){N.removeListener(O[N.EL],O[N.TYPE],O[N.FN],P);}}O=null;}G=null;N._simpleRemove(window,"unload",N._unload);},_getScrollLeft:function(){return this._getScroll()[1];},_getScrollTop:function(){return this._getScroll()[0];},_getScroll:function(){var M=document.documentElement,N=document.body;if(M&&(M.scrollTop||M.scrollLeft)){return[M.scrollTop,M.scrollLeft];}else{if(N){return[N.scrollTop,N.scrollLeft];}else{return[0,0];}}},regCE:function(){},_simpleAdd:function(){if(window.addEventListener){return function(O,P,N,M){O.addEventListener(P,N,(M));};}else{if(window.attachEvent){return function(O,P,N,M){O.attachEvent("on"+P,N);};}else{return function(){};}}}(),_simpleRemove:function(){if(window.removeEventListener){return function(O,P,N,M){O.removeEventListener(P,N,(M));};}else{if(window.detachEvent){return function(N,O,M){N.detachEvent("on"+O,M);};}else{return function(){};}}}()};}(
);(function(){var EU=YAHOO.util.Event;EU.on=EU.addListener;EU.onFocus=EU.addFocusListener;EU.onBlur=EU.addBlurListener;
+/* DOMReady: based on work by: Dean Edwards/John Resig/Matthias Miller */
+if(EU.isIE){YAHOO.util.Event.onDOMReady(YAHOO.util.Event._tryPreloadAttach,YAHOO.util.Event,true);var n=document.createElement("p");EU._dri=setInterval(function(){try{n.doScroll("left");clearInterval(EU._dri);EU._dri=null;EU._ready();n=null;}catch(ex){}},EU.POLL_INTERVAL);}else{if(EU.webkit&&EU.webkit<525){EU._dri=setInterval(function(){var rs=document.readyState;if("loaded"==rs||"complete"==rs){clearInterval(EU._dri);EU._dri=null;EU._ready();}},EU.POLL_INTERVAL);}else{EU._simpleAdd(document,"DOMContentLoaded",EU._ready);}}EU._simpleAdd(window,"load",EU._load);EU._simpleAdd(window,"unload",EU._unload);EU._tryPreloadAttach();})();}YAHOO.util.EventProvider=function(){};YAHOO.util.EventProvider.prototype={__yui_events:null,__yui_subscribers:null,subscribe:function(A,C,F,E){this.__yui_events=this.__yui_events||{};var D=this.__yui_events[A];if(D){D.subscribe(C,F,E);
+}else{this.__yui_subscribers=this.__yui_subscribers||{};var B=this.__yui_subscribers;if(!B[A]){B[A]=[];}B[A].push({fn:C,obj:F,overrideContext:E});}},unsubscribe:function(C,E,G){this.__yui_events=this.__yui_events||{};var A=this.__yui_events;if(C){var F=A[C];if(F){return F.unsubscribe(E,G);}}else{var B=true;for(var D in A){if(YAHOO.lang.hasOwnProperty(A,D)){B=B&&A[D].unsubscribe(E,G);}}return B;}return false;},unsubscribeAll:function(A){return this.unsubscribe(A);},createEvent:function(G,D){this.__yui_events=this.__yui_events||{};var A=D||{};var I=this.__yui_events;if(I[G]){}else{var H=A.scope||this;var E=(A.silent);var B=new YAHOO.util.CustomEvent(G,H,E,YAHOO.util.CustomEvent.FLAT);I[G]=B;if(A.onSubscribeCallback){B.subscribeEvent.subscribe(A.onSubscribeCallback);}this.__yui_subscribers=this.__yui_subscribers||{};var F=this.__yui_subscribers[G];if(F){for(var C=0;C<F.length;++C){B.subscribe(F[C].fn,F[C].obj,F[C].overrideContext);}}}return I[G];},fireEvent:function(E,D,A,C){th
is.__yui_events=this.__yui_events||{};var G=this.__yui_events[E];if(!G){return null;}var B=[];for(var F=1;F<arguments.length;++F){B.push(arguments[F]);}return G.fire.apply(G,B);},hasEvent:function(A){if(this.__yui_events){if(this.__yui_events[A]){return true;}}return false;}};(function(){var A=YAHOO.util.Event,C=YAHOO.lang;YAHOO.util.KeyListener=function(D,I,E,F){if(!D){}else{if(!I){}else{if(!E){}}}if(!F){F=YAHOO.util.KeyListener.KEYDOWN;}var G=new YAHOO.util.CustomEvent("keyPressed");this.enabledEvent=new YAHOO.util.CustomEvent("enabled");this.disabledEvent=new YAHOO.util.CustomEvent("disabled");if(C.isString(D)){D=document.getElementById(D);}if(C.isFunction(E)){G.subscribe(E);}else{G.subscribe(E.fn,E.scope,E.correctScope);}function H(O,N){if(!I.shift){I.shift=false;}if(!I.alt){I.alt=false;}if(!I.ctrl){I.ctrl=false;}if(O.shiftKey==I.shift&&O.altKey==I.alt&&O.ctrlKey==I.ctrl){var J,M=I.keys,L;if(YAHOO.lang.isArray(M)){for(var K=0;K<M.length;K++){J=M[K];L=A.getCharCode(O);if(
J==L){G.fire(L,O);break;}}}else{L=A.getCharCode(O);if(M==L){G.fire(L,O);}}}}this.enable=function(){if(!this.enabled){A.on(D,F,H);this.enabledEvent.fire(I);}this.enabled=true;};this.disable=function(){if(this.enabled){A.removeListener(D,F,H);this.disabledEvent.fire(I);}this.enabled=false;};this.toString=function(){return"KeyListener ["+I.keys+"] "+D.tagName+(D.id?"["+D.id+"]":"");};};var B=YAHOO.util.KeyListener;B.KEYDOWN="keydown";B.KEYUP="keyup";B.KEY={ALT:18,BACK_SPACE:8,CAPS_LOCK:20,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,LEFT:37,META:224,NUM_LOCK:144,PAGE_DOWN:34,PAGE_UP:33,PAUSE:19,PRINTSCREEN:44,RIGHT:39,SCROLL_LOCK:145,SHIFT:16,SPACE:32,TAB:9,UP:38};})();YAHOO.register("event",YAHOO.util.Event,{version:"2.7.0",build:"1799"});
\ No newline at end of file
Modified: wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/event/event.js
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/event/event.js?rev=763645&r1=763644&r2=763645&view=diff
==============================================================================
--- wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/event/event.js (original)
+++ wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/event/event.js Thu Apr 9 13:31:54 2009
@@ -1,8 +1,8 @@
/*
-Copyright (c) 2007, Yahoo! Inc. All rights reserved.
+Copyright (c) 2009, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
-version: 2.4.1
+version: 2.7.0
*/
/**
@@ -11,7 +11,7 @@
*
* @param {String} type The type of event, which is passed to the callback
* when the event fires
- * @param {Object} oScope The context the event will fire from. "this" will
+ * @param {Object} context The context the event will fire from. "this" will
* refer to this object in the callback. Default value:
* the window object. The listener can override this.
* @param {boolean} silent pass true to prevent the event from writing to
@@ -24,7 +24,7 @@
* @class CustomEvent
* @constructor
*/
-YAHOO.util.CustomEvent = function(type, oScope, silent, signature) {
+YAHOO.util.CustomEvent = function(type, context, silent, signature) {
/**
* The type of event, returned to subscribers when the event fires
@@ -34,12 +34,12 @@
this.type = type;
/**
- * The scope the the event will fire from by default. Defaults to the window
+ * The context the the event will fire from by default. Defaults to the window
* obj
* @property scope
* @type object
*/
- this.scope = oScope || window;
+ this.scope = context || window;
/**
* By default all custom events are logged in the debug build, set silent
@@ -99,11 +99,12 @@
* @type YAHOO.util.CustomEvent
* @param {Function} fn The function to execute
* @param {Object} obj An object to be passed along when the event
- * fires
+ * fires defaults to the custom event
* @param {boolean|Object} override If true, the obj passed in becomes
- * the execution scope of the listener.
+ * the execution context of the listener.
* if an object, that object becomes the
- * the execution scope.
+ * the execution context. defaults to
+ * the custom event
*/
this.subscribeEvent =
new YAHOO.util.CustomEvent(onsubscribeType, this, true);
@@ -149,22 +150,22 @@
* @param {Function} fn The function to execute
* @param {Object} obj An object to be passed along when the event
* fires
- * @param {boolean|Object} override If true, the obj passed in becomes
- * the execution scope of the listener.
+ * @param {boolean|Object} overrideContext If true, the obj passed in becomes
+ * the execution context of the listener.
* if an object, that object becomes the
- * the execution scope.
+ * the execution context.
*/
- subscribe: function(fn, obj, override) {
+ subscribe: function(fn, obj, overrideContext) {
if (!fn) {
throw new Error("Invalid callback for subscriber to '" + this.type + "'");
}
if (this.subscribeEvent) {
- this.subscribeEvent.fire(fn, obj, override);
+ this.subscribeEvent.fire(fn, obj, overrideContext);
}
- this.subscribers.push( new YAHOO.util.Subscriber(fn, obj, override) );
+ this.subscribers.push( new YAHOO.util.Subscriber(fn, obj, overrideContext) );
},
/**
@@ -199,7 +200,7 @@
/**
* Notifies the subscribers. The callback functions will be executed
- * from the scope specified when the event was created, and with the
+ * from the context specified when the event was created, and with the
* following parameters:
* <ul>
* <li>The type of event</li>
@@ -214,22 +215,27 @@
* true otherwise
*/
fire: function() {
- var len=this.subscribers.length;
+
+ this.lastError = null;
+
+ var errors = [],
+ len=this.subscribers.length;
+
if (!len && this.silent) {
return true;
}
- var args=[], ret=true, i, rebuild=false;
-
- for (i=0; i<arguments.length; ++i) {
- args.push(arguments[i]);
- }
+ var args=[].slice.call(arguments, 0), ret=true, i, rebuild=false;
if (!this.silent) {
}
+ // make a copy of the subscribers so that there are
+ // no index problems if one subscriber removes another.
+ var subs = this.subscribers.slice(), throwErrors = YAHOO.util.Event.throwErrors;
+
for (i=0; i<len; ++i) {
- var s = this.subscribers[i];
+ var s = subs[i];
if (!s) {
rebuild=true;
} else {
@@ -248,34 +254,33 @@
ret = s.fn.call(scope, param, s.obj);
} catch(e) {
this.lastError = e;
+ // errors.push(e);
+ if (throwErrors) {
+ throw e;
+ }
}
} else {
try {
ret = s.fn.call(scope, this.type, args, s.obj);
} catch(ex) {
this.lastError = ex;
+ if (throwErrors) {
+ throw ex;
+ }
}
}
+
if (false === ret) {
if (!this.silent) {
}
- //break;
- return false;
+ break;
+ // return false;
}
}
}
- if (rebuild) {
- var newlist=[],subs=this.subscribers;
- for (i=0,len=subs.length; i<len; i=i+1) {
- newlist.push(subs[i]);
- }
-
- this.subscribers=newlist;
- }
-
- return true;
+ return (ret !== false);
},
/**
@@ -284,13 +289,14 @@
* @return {int} The number of listeners unsubscribed
*/
unsubscribeAll: function() {
- for (var i=0, len=this.subscribers.length; i<len; ++i) {
- this._delete(len - 1 - i);
+ var l = this.subscribers.length, i;
+ for (i=l-1; i>-1; i--) {
+ this._delete(i);
}
this.subscribers=[];
- return i;
+ return l;
},
/**
@@ -304,7 +310,8 @@
delete s.obj;
}
- this.subscribers[index]=null;
+ // this.subscribers[index]=null;
+ this.subscribers.splice(index, 1);
},
/**
@@ -312,7 +319,7 @@
*/
toString: function() {
return "CustomEvent: " + "'" + this.type + "', " +
- "scope: " + this.scope;
+ "context: " + this.scope;
}
};
@@ -323,12 +330,12 @@
* Stores the subscriber information to be used when the event fires.
* @param {Function} fn The function to execute
* @param {Object} obj An object to be passed along when the event fires
- * @param {boolean} override If true, the obj passed in becomes the execution
- * scope of the listener
+ * @param {boolean} overrideContext If true, the obj passed in becomes the execution
+ * context of the listener
* @class Subscriber
* @constructor
*/
-YAHOO.util.Subscriber = function(fn, obj, override) {
+YAHOO.util.Subscriber = function(fn, obj, overrideContext) {
/**
* The callback that will be execute when the event fires
@@ -346,32 +353,32 @@
this.obj = YAHOO.lang.isUndefined(obj) ? null : obj;
/**
- * The default execution scope for the event listener is defined when the
+ * The default execution context for the event listener is defined when the
* event is created (usually the object which contains the event).
- * By setting override to true, the execution scope becomes the custom
- * object passed in by the subscriber. If override is an object, that
- * object becomes the scope.
- * @property override
+ * By setting overrideContext to true, the execution context becomes the custom
+ * object passed in by the subscriber. If overrideContext is an object, that
+ * object becomes the context.
+ * @property overrideContext
* @type boolean|object
*/
- this.override = override;
+ this.overrideContext = overrideContext;
};
/**
- * Returns the execution scope for this listener. If override was set to true
- * the custom obj will be the scope. If override is an object, that is the
- * scope, otherwise the default scope will be used.
+ * Returns the execution context for this listener. If overrideContext was set to true
+ * the custom obj will be the context. If overrideContext is an object, that is the
+ * context, otherwise the default context will be used.
* @method getScope
- * @param {Object} defaultScope the scope to use if this listener does not
+ * @param {Object} defaultScope the context to use if this listener does not
* override it.
*/
YAHOO.util.Subscriber.prototype.getScope = function(defaultScope) {
- if (this.override) {
- if (this.override === true) {
+ if (this.overrideContext) {
+ if (this.overrideContext === true) {
return this.obj;
} else {
- return this.override;
+ return this.overrideContext;
}
}
return defaultScope;
@@ -400,7 +407,7 @@
*/
YAHOO.util.Subscriber.prototype.toString = function() {
return "Subscriber { obj: " + this.obj +
- ", override: " + (this.override || "no") + " }";
+ ", overrideContext: " + (this.overrideContext || "no") + " }";
};
/**
@@ -526,13 +533,17 @@
25: 9 // SHIFT-TAB (Safari provides a different key code in
// this case, even though the shiftKey modifier is set)
};
+
+ // String constants used by the addFocusListener and removeFocusListener methods
+ var _FOCUS = YAHOO.env.ua.ie ? "focusin" : "focus";
+ var _BLUR = YAHOO.env.ua.ie ? "focusout" : "blur";
return {
/**
* The number of times we should look for elements that are not
* in the DOM at the time the event is requested after the document
- * has been loaded. The default is 4000@amp;10 ms, so it will poll
+ * has been loaded. The default is 2000@amp;20 ms, so it will poll
* for 40 seconds or until all outstanding handlers are bound
* (whichever comes first).
* @property POLL_RETRYS
@@ -540,7 +551,7 @@
* @static
* @final
*/
- POLL_RETRYS: 4000,
+ POLL_RETRYS: 2000,
/**
* The poll interval in milliseconds
@@ -549,7 +560,7 @@
* @static
* @final
*/
- POLL_INTERVAL: 10,
+ POLL_INTERVAL: 20,
/**
* Element to bind, int constant
@@ -579,7 +590,7 @@
FN: 2,
/**
- * Function wrapped for scope correction and cleanup, int constant
+ * Function wrapped for context correction and cleanup, int constant
* @property WFN
* @type int
* @static
@@ -599,7 +610,7 @@
UNLOAD_OBJ: 3,
/**
- * Adjusted scope, either the element we are registering the event
+ * Adjusted context, either the element we are registering the event
* on or the custom object passed in by the listener, int constant
* @property ADJ_SCOPE
* @type int
@@ -618,7 +629,7 @@
OBJ: 5,
/**
- * The original scope parameter passed into addListener
+ * The original context parameter passed into addListener
* @property OVERRIDE
* @type int
* @static
@@ -689,6 +700,17 @@
DOMReady: false,
/**
+ * Errors thrown by subscribers of custom events are caught
+ * and the error message is written to the debug console. If
+ * this property is set to true, it will also re-throw the
+ * error.
+ * @property throwErrors
+ * @type boolean
+ * @default false
+ */
+ throwErrors: false,
+
+ /**
* @method startInterval
* @static
* @private
@@ -714,29 +736,31 @@
*
* @method onAvailable
*
- * @param {string||string[]} p_id the id of the element, or an array
+ * @param {string||string[]} id the id of the element, or an array
* of ids to look for.
- * @param {function} p_fn what to execute when the element is found.
- * @param {object} p_obj an optional object to be passed back as
- * a parameter to p_fn.
- * @param {boolean|object} p_override If set to true, p_fn will execute
- * in the scope of p_obj, if set to an object it
- * will execute in the scope of that object
+ * @param {function} fn what to execute when the element is found.
+ * @param {object} obj an optional object to be passed back as
+ * a parameter to fn.
+ * @param {boolean|object} overrideContext If set to true, fn will execute
+ * in the context of obj, if set to an object it
+ * will execute in the context of that object
* @param checkContent {boolean} check child node readiness (onContentReady)
* @static
*/
- onAvailable: function(p_id, p_fn, p_obj, p_override, checkContent) {
+ onAvailable: function(id, fn, obj, overrideContext, checkContent) {
- var a = (YAHOO.lang.isString(p_id)) ? [p_id] : p_id;
+ var a = (YAHOO.lang.isString(id)) ? [id] : id;
for (var i=0; i<a.length; i=i+1) {
onAvailStack.push({id: a[i],
- fn: p_fn,
- obj: p_obj,
- override: p_override,
+ fn: fn,
+ obj: obj,
+ overrideContext: overrideContext,
checkReady: checkContent });
}
+
retryCount = this.POLL_RETRYS;
+
this.startInterval();
},
@@ -750,18 +774,18 @@
*
* @method onContentReady
*
- * @param {string} p_id the id of the element to look for.
- * @param {function} p_fn what to execute when the element is ready.
- * @param {object} p_obj an optional object to be passed back as
- * a parameter to p_fn.
- * @param {boolean|object} p_override If set to true, p_fn will execute
- * in the scope of p_obj. If an object, p_fn will
- * exectute in the scope of that object
+ * @param {string} id the id of the element to look for.
+ * @param {function} fn what to execute when the element is ready.
+ * @param {object} obj an optional object to be passed back as
+ * a parameter to fn.
+ * @param {boolean|object} overrideContext If set to true, fn will execute
+ * in the context of obj. If an object, fn will
+ * exectute in the context of that object
*
* @static
*/
- onContentReady: function(p_id, p_fn, p_obj, p_override) {
- this.onAvailable(p_id, p_fn, p_obj, p_override, true);
+ onContentReady: function(id, fn, obj, overrideContext) {
+ this.onAvailable(id, fn, obj, overrideContext, true);
},
/**
@@ -787,37 +811,38 @@
*
* @method onDOMReady
*
- * @param {function} p_fn what to execute when the element is found.
- * @param {object} p_obj an optional object to be passed back as
- * a parameter to p_fn.
- * @param {boolean|object} p_scope If set to true, p_fn will execute
- * in the scope of p_obj, if set to an object it
- * will execute in the scope of that object
+ * @param {function} fn what to execute when the element is found.
+ * @param {object} obj an optional object to be passed back as
+ * a parameter to fn.
+ * @param {boolean|object} overrideContext If set to true, fn will execute
+ * in the context of obj, if set to an object it
+ * will execute in the context of that object
*
* @static
*/
- onDOMReady: function(p_fn, p_obj, p_override) {
+ onDOMReady: function(fn, obj, overrideContext) {
if (this.DOMReady) {
setTimeout(function() {
var s = window;
- if (p_override) {
- if (p_override === true) {
- s = p_obj;
+ if (overrideContext) {
+ if (overrideContext === true) {
+ s = obj;
} else {
- s = p_override;
+ s = overrideContext;
}
}
- p_fn.call(s, "DOMReady", [], p_obj);
+ fn.call(s, "DOMReady", [], obj);
}, 0);
} else {
- this.DOMReadyEvent.subscribe(p_fn, p_obj, p_override);
+ this.DOMReadyEvent.subscribe(fn, obj, overrideContext);
}
},
+
/**
* Appends an event handler
*
- * @method addListener
+ * @method _addListener
*
* @param {String|HTMLElement|Array|NodeList} el An id, an element
* reference, or a collection of ids and/or elements to assign the
@@ -826,20 +851,21 @@
* @param {Function} fn The method the event invokes
* @param {Object} obj An arbitrary object that will be
* passed as a parameter to the handler
- * @param {Boolean|object} override If true, the obj passed in becomes
- * the execution scope of the listener. If an
+ * @param {Boolean|object} overrideContext If true, the obj passed in becomes
+ * the execution context of the listener. If an
* object, this object becomes the execution
- * scope.
+ * context.
+ * @param {boolen} capture capture or bubble phase
* @return {Boolean} True if the action was successful or defered,
* false if one or more of the elements
* could not have the listener attached,
* or if the operation throws an exception.
+ * @private
* @static
*/
- addListener: function(el, sType, fn, obj, override) {
+ _addListener: function(el, sType, fn, obj, overrideContext, bCapture) {
if (!fn || !fn.call) {
-// throw new TypeError(sType + " addListener call failed, callback undefined");
return false;
}
@@ -851,7 +877,7 @@
sType,
fn,
obj,
- override) && ok;
+ overrideContext) && ok;
}
return ok;
@@ -869,7 +895,7 @@
} else {
// defer adding the event until the element is available
this.onAvailable(el, function() {
- YAHOO.util.Event.on(el, sType, fn, obj, override);
+ YAHOO.util.Event.on(el, sType, fn, obj, overrideContext);
});
return true;
@@ -888,31 +914,31 @@
// handles explicitly during our one unload event.
if ("unload" == sType && obj !== this) {
unloadListeners[unloadListeners.length] =
- [el, sType, fn, obj, override];
+ [el, sType, fn, obj, overrideContext];
return true;
}
- // if the user chooses to override the scope, we use the custom
- // object passed in, otherwise the executing scope will be the
+ // if the user chooses to override the context, we use the custom
+ // object passed in, otherwise the executing context will be the
// HTML element that the event is registered on
- var scope = el;
- if (override) {
- if (override === true) {
- scope = obj;
+ var context = el;
+ if (overrideContext) {
+ if (overrideContext === true) {
+ context = obj;
} else {
- scope = override;
+ context = overrideContext;
}
}
// wrap the function so we can return the obj object when
// the event fires;
var wrappedFn = function(e) {
- return fn.call(scope, YAHOO.util.Event.getEvent(e, el),
+ return fn.call(context, YAHOO.util.Event.getEvent(e, el),
obj);
};
- var li = [el, sType, fn, wrappedFn, scope, obj, override];
+ var li = [el, sType, fn, wrappedFn, context, obj, overrideContext];
var index = listeners.length;
// cache the listener so we can try to automatically unload
listeners[index] = li;
@@ -948,7 +974,7 @@
} else {
try {
- this._simpleAdd(el, sType, wrappedFn, false);
+ this._simpleAdd(el, sType, wrappedFn, bCapture);
} catch(ex) {
// handle an error trying to attach an event. If it fails
// we need to clean up the cache
@@ -962,6 +988,126 @@
},
+
+ /**
+ * Appends an event handler
+ *
+ * @method addListener
+ *
+ * @param {String|HTMLElement|Array|NodeList} el An id, an element
+ * reference, or a collection of ids and/or elements to assign the
+ * listener to.
+ * @param {String} sType The type of event to append
+ * @param {Function} fn The method the event invokes
+ * @param {Object} obj An arbitrary object that will be
+ * passed as a parameter to the handler
+ * @param {Boolean|object} overrideContext If true, the obj passed in becomes
+ * the execution context of the listener. If an
+ * object, this object becomes the execution
+ * context.
+ * @return {Boolean} True if the action was successful or defered,
+ * false if one or more of the elements
+ * could not have the listener attached,
+ * or if the operation throws an exception.
+ * @static
+ */
+ addListener: function (el, sType, fn, obj, overrideContext) {
+ return this._addListener(el, sType, fn, obj, overrideContext, false);
+ },
+
+ /**
+ * Appends a focus event handler. (The focusin event is used for Internet Explorer,
+ * the focus, capture-event for Opera, WebKit.)
+ *
+ * @method addFocusListener
+ *
+ * @param {String|HTMLElement|Array|NodeList} el An id, an element
+ * reference, or a collection of ids and/or elements to assign the
+ * listener to.
+ * @param {Function} fn The method the event invokes
+ * @param {Object} obj An arbitrary object that will be
+ * passed as a parameter to the handler
+ * @param {Boolean|object} overrideContext If true, the obj passed in becomes
+ * the execution context of the listener. If an
+ * object, this object becomes the execution
+ * context.
+ * @return {Boolean} True if the action was successful or defered,
+ * false if one or more of the elements
+ * could not have the listener attached,
+ * or if the operation throws an exception.
+ * @static
+ */
+ addFocusListener: function (el, fn, obj, overrideContext) {
+ return this._addListener(el, _FOCUS, fn, obj, overrideContext, true);
+ },
+
+
+ /**
+ * Removes a focus event listener
+ *
+ * @method removeListener
+ *
+ * @param {String|HTMLElement|Array|NodeList} el An id, an element
+ * reference, or a collection of ids and/or elements to remove
+ * the listener from.
+ * @param {Function} fn the method the event invokes. If fn is
+ * undefined, then all event handlers for the type of event are
+ * removed.
+ * @return {boolean} true if the unbind was successful, false
+ * otherwise.
+ * @static
+ */
+ removeFocusListener: function (el, fn) {
+ return this.removeListener(el, _FOCUS, fn);
+ },
+
+ /**
+ * Appends a blur event handler. (The focusout event is used for Internet Explorer,
+ * the focusout, capture-event for Opera, WebKit.)
+ *
+ * @method addBlurListener
+ *
+ * @param {String|HTMLElement|Array|NodeList} el An id, an element
+ * reference, or a collection of ids and/or elements to assign the
+ * listener to.
+ * @param {Function} fn The method the event invokes
+ * @param {Object} obj An arbitrary object that will be
+ * passed as a parameter to the handler
+ * @param {Boolean|object} overrideContext If true, the obj passed in becomes
+ * the execution context of the listener. If an
+ * object, this object becomes the execution
+ * context.
+ * @return {Boolean} True if the action was successful or defered,
+ * false if one or more of the elements
+ * could not have the listener attached,
+ * or if the operation throws an exception.
+ * @static
+ */
+ addBlurListener: function (el, fn, obj, overrideContext) {
+ return this._addListener(el, _BLUR, fn, obj, overrideContext, true);
+ },
+
+ /**
+ * Removes a blur event listener
+ *
+ * @method removeListener
+ *
+ * @param {String|HTMLElement|Array|NodeList} el An id, an element
+ * reference, or a collection of ids and/or elements to remove
+ * the listener from.
+ * @param {Function} fn the method the event invokes. If fn is
+ * undefined, then all event handlers for the type of event are
+ * removed.
+ * @return {boolean} true if the unbind was successful, false
+ * otherwise.
+ * @static
+ */
+ removeBlurListener: function (el, fn) {
+
+ return this.removeListener(el, _BLUR, fn);
+
+ },
+
/**
* When using legacy events, the handler is routed to this object
* so we can fire our custom listener stack.
@@ -970,14 +1116,15 @@
* @private
*/
fireLegacyEvent: function(e, legacyIndex) {
- var ok=true,le,lh,li,scope,ret;
+ var ok=true, le, lh, li, context, ret;
- lh = legacyHandlers[legacyIndex];
- for (var i=0,len=lh.length; i<len; ++i) {
+ lh = legacyHandlers[legacyIndex].slice();
+ for (var i=0, len=lh.length; i<len; ++i) {
+ // for (var i in lh.length) {
li = lh[i];
if ( li && li[this.WFN] ) {
- scope = li[this.ADJ_SCOPE];
- ret = li[this.WFN].call(scope, e);
+ context = li[this.ADJ_SCOPE];
+ ret = li[this.WFN].call(context, e);
ok = (ok && ret);
}
}
@@ -1019,13 +1166,7 @@
* @private
*/
useLegacyEvent: function(el, sType) {
- if (this.webkit && ("click"==sType || "dblclick"==sType)) {
- var v = parseInt(this.webkit, 10);
- if (!isNaN(v) && v<418) {
- return true;
- }
- }
- return false;
+return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType));
},
/**
@@ -1053,7 +1194,7 @@
// The el argument can be an array of elements or element ids.
} else if ( this._isValidCollection(el)) {
var ok = true;
- for (i=0,len=el.length; i<len; ++i) {
+ for (i=el.length-1; i>-1; i--) {
ok = ( this.removeListener(el[i], sType, fn) && ok );
}
return ok;
@@ -1066,14 +1207,14 @@
if ("unload" == sType) {
- for (i=0, len=unloadListeners.length; i<len; i++) {
+ for (i=unloadListeners.length-1; i>-1; i--) {
li = unloadListeners[i];
if (li &&
li[0] == el &&
li[1] == sType &&
li[2] == fn) {
- //unloadListeners.splice(i, 1);
- unloadListeners[i]=null;
+ unloadListeners.splice(i, 1);
+ // unloadListeners[i]=null;
return true;
}
}
@@ -1106,13 +1247,14 @@
var llist = legacyHandlers[legacyIndex];
if (llist) {
for (i=0, len=llist.length; i<len; ++i) {
+ // for (i in llist.length) {
li = llist[i];
if (li &&
li[this.EL] == el &&
li[this.TYPE] == sType &&
li[this.FN] == fn) {
- //llist.splice(i, 1);
- llist[i]=null;
+ llist.splice(i, 1);
+ // llist[i]=null;
break;
}
}
@@ -1130,8 +1272,8 @@
// removed the wrapped handler
delete listeners[index][this.WFN];
delete listeners[index][this.FN];
- //listeners.splice(index, 1);
- listeners[index]=null;
+ listeners.splice(index, 1);
+ // listeners[index]=null;
return true;
@@ -1164,12 +1306,14 @@
* @return {HTMLElement} the normized node
* @static
*/
- resolveTextNode: function(node) {
- if (node && 3 == node.nodeType) {
- return node.parentNode;
- } else {
- return node;
- }
+ resolveTextNode: function(n) {
+ try {
+ if (n && 3 == n.nodeType) {
+ return n.parentNode;
+ }
+ } catch(e) { }
+
+ return n;
},
/**
@@ -1331,30 +1475,6 @@
}
}
- // IE events that target non-browser objects (e.g., VML
- // canvas) will sometimes throw errors when you try to
- // inspect the properties of the event target. We try to
- // detect this condition, and provide a dummy target (the bound
- // element) to eliminate spurious errors.
-
- // the implementation caused unexpected results in some
- // implementations, so this has been rolled back for now
- /*
- if (ev && this.isIE) {
-
- try {
-
- var el = ev.srcElement;
-
- } catch(ex) {
-
-
- ev.target = boundEl;
- }
-
- }
- */
-
return ev;
},
@@ -1368,7 +1488,7 @@
getCharCode: function(ev) {
var code = ev.keyCode || ev.charCode || 0;
- // webkit normalization
+ // webkit key normalization
if (YAHOO.env.ua.webkit && (code in webkitKeymap)) {
code = webkitKeymap[code];
}
@@ -1383,7 +1503,7 @@
* @private
*/
_getCacheIndex: function(el, sType, fn) {
- for (var i=0,len=listeners.length; i<len; ++i) {
+ for (var i=0, l=listeners.length; i<l; i=i+1) {
var li = listeners[i];
if ( li &&
li[this.FN] == fn &&
@@ -1501,11 +1621,6 @@
// before the window load notification
EU._tryPreloadAttach();
- // Remove the listener to assist with the IE memory issue, but not
- // for other browsers because FF 1.0x does not like it.
- //if (this.isIE) {
- //EU._simpleRemove(window, "load", EU._load);
- //}
}
},
@@ -1539,18 +1654,26 @@
*/
_tryPreloadAttach: function() {
+ if (onAvailStack.length === 0) {
+ retryCount = 0;
+ if (this._interval) {
+ clearInterval(this._interval);
+ this._interval = null;
+ }
+ return;
+ }
+
if (this.locked) {
- return false;
+ return;
}
if (this.isIE) {
// Hold off if DOMReady has not fired and check current
// readyState to protect against the IE operation aborted
// issue.
- //if (!this.DOMReady || "complete" !== document.readyState) {
if (!this.DOMReady) {
this.startInterval();
- return false;
+ return;
}
}
@@ -1563,50 +1686,38 @@
// tested appropriately
var tryAgain = !loadComplete;
if (!tryAgain) {
- tryAgain = (retryCount > 0);
+ tryAgain = (retryCount > 0 && onAvailStack.length > 0);
}
// onAvailable
var notAvail = [];
var executeItem = function (el, item) {
- var scope = el;
- if (item.override) {
- if (item.override === true) {
- scope = item.obj;
+ var context = el;
+ if (item.overrideContext) {
+ if (item.overrideContext === true) {
+ context = item.obj;
} else {
- scope = item.override;
+ context = item.overrideContext;
}
}
- item.fn.call(scope, item.obj);
+ item.fn.call(context, item.obj);
};
- var i,len,item,el;
-
- // onAvailable
- for (i=0,len=onAvailStack.length; i<len; ++i) {
- item = onAvailStack[i];
- if (item && !item.checkReady) {
- el = this.getEl(item.id);
- if (el) {
- executeItem(el, item);
- onAvailStack[i] = null;
- } else {
- notAvail.push(item);
- }
- }
- }
+ var i, len, item, el, ready=[];
- // onContentReady
- for (i=0,len=onAvailStack.length; i<len; ++i) {
+ // onAvailable onContentReady
+ for (i=0, len=onAvailStack.length; i<len; i=i+1) {
item = onAvailStack[i];
- if (item && item.checkReady) {
+ if (item) {
el = this.getEl(item.id);
-
if (el) {
- // The element is available, but not necessarily ready
- // @todo should we test parentNode.nextSibling?
- if (loadComplete || el.nextSibling) {
+ if (item.checkReady) {
+ if (loadComplete || el.nextSibling || !tryAgain) {
+ ready.push(item);
+ onAvailStack[i] = null;
+ }
+ } else {
executeItem(el, item);
onAvailStack[i] = null;
}
@@ -1615,21 +1726,34 @@
}
}
}
+
+ // make sure onContentReady fires after onAvailable
+ for (i=0, len=ready.length; i<len; i=i+1) {
+ item = ready[i];
+ executeItem(this.getEl(item.id), item);
+ }
- retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
+
+ retryCount--;
if (tryAgain) {
- // we may need to strip the nulled out items here
+ for (i=onAvailStack.length-1; i>-1; i--) {
+ item = onAvailStack[i];
+ if (!item || !item.id) {
+ onAvailStack.splice(i, 1);
+ }
+ }
+
this.startInterval();
} else {
- clearInterval(this._interval);
- this._interval = null;
+ if (this._interval) {
+ clearInterval(this._interval);
+ this._interval = null;
+ }
}
this.locked = false;
- return true;
-
},
/**
@@ -1648,11 +1772,9 @@
var oEl = (YAHOO.lang.isString(el)) ? this.getEl(el) : el;
var elListeners = this.getListeners(oEl, sType), i, len;
if (elListeners) {
- for (i=0,len=elListeners.length; i<len ; ++i) {
+ for (i=elListeners.length-1; i>-1; i--) {
var l = elListeners[i];
- // can't use the index on the changing collection
- this.removeListener(oEl, l.type, l.fn, l.index);
- //this.removeListener(oEl, l.type, l.fn);
+ this.removeListener(oEl, l.type, l.fn);
}
}
@@ -1674,8 +1796,8 @@
* type: (string) the type of event
* fn: (function) the callback supplied to addListener
* obj: (object) the custom object supplied to addListener
- * adjust: (boolean|object) whether or not to adjust the default scope
- * scope: (boolean) the derived scope based on the adjust parameter
+ * adjust: (boolean|object) whether or not to adjust the default context
+ * scope: (boolean) the derived context based on the adjust parameter
* index: (int) its position in the Event util listener cache
* @static
*/
@@ -1693,7 +1815,7 @@
for (var j=0;j<searchLists.length; j=j+1) {
var searchList = searchLists[j];
- if (searchList && searchList.length > 0) {
+ if (searchList) {
for (var i=0,len=searchList.length; i<len ; ++i) {
var l = searchList[i];
if ( l && l[this.EL] === oEl &&
@@ -1723,76 +1845,46 @@
*/
_unload: function(e) {
- var EU = YAHOO.util.Event, i, j, l, len, index;
+ var EU = YAHOO.util.Event, i, j, l, len, index,
+ ul = unloadListeners.slice(), context;
// execute and clear stored unload listeners
- for (i=0,len=unloadListeners.length; i<len; ++i) {
- l = unloadListeners[i];
+ for (i=0, len=unloadListeners.length; i<len; ++i) {
+ l = ul[i];
if (l) {
- var scope = window;
+ context = window;
if (l[EU.ADJ_SCOPE]) {
if (l[EU.ADJ_SCOPE] === true) {
- scope = l[EU.UNLOAD_OBJ];
+ context = l[EU.UNLOAD_OBJ];
} else {
- scope = l[EU.ADJ_SCOPE];
+ context = l[EU.ADJ_SCOPE];
}
}
- l[EU.FN].call(scope, EU.getEvent(e, l[EU.EL]), l[EU.UNLOAD_OBJ] );
- unloadListeners[i] = null;
- l=null;
- scope=null;
+ l[EU.FN].call(context, EU.getEvent(e, l[EU.EL]), l[EU.UNLOAD_OBJ] );
+ ul[i] = null;
}
}
+ l = null;
+ context = null;
unloadListeners = null;
- // call clearAttributes or remove listeners to handle IE memory leaks
- if (YAHOO.env.ua.ie && listeners && listeners.length > 0) {
- j = listeners.length;
- while (j) {
- index = j-1;
- l = listeners[index];
- if (l) {
- //try {
- //l[EU.EL].clearAttributes(); // errors on window objects
- //} catch(ex) {
- EU.removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], index);
- //}
- }
- j--;
- }
- l=null;
- }
-
- /*
- // remove all listeners
- if (listeners && listeners.length > 0) {
- j = listeners.length;
- while (j) {
- index = j-1;
- l = listeners[index];
+ // Remove listeners to handle IE memory leaks
+ //if (YAHOO.env.ua.ie && listeners && listeners.length > 0) {
+
+ // 2.5.0 listeners are removed for all browsers again. FireFox preserves
+ // at least some listeners between page refreshes, potentially causing
+ // errors during page load (mouseover listeners firing before they
+ // should if the user moves the mouse at the correct moment).
+ if (listeners) {
+ for (j=listeners.length-1; j>-1; j--) {
+ l = listeners[j];
if (l) {
- EU.removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], index);
+ EU.removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], j);
}
- j = j - 1;
}
l=null;
}
- */
-
- /*
- // kill legacy events
- for (i=0,len=legacyEvents.length; i<len; ++i) {
- // dereference the element
- //delete legacyEvents[i][0];
- legacyEvents[i][0] = null;
-
- // delete the array item
- //delete legacyEvents[i];
- legacyEvents[i] = null;
- }
-
- */
legacyEvents = null;
@@ -1850,24 +1942,8 @@
// does nothing
},
-/*
- testIEReady: function (){
- var n = document.createElement('p'), ready = false;
- try {
- // throws an error until the doc is ready
- n.doScroll('left');
- ready = true;
- } catch(ex){
- // document is not ready
- }
-
- n = null;
- return ready;
- },
-*/
-
/**
- * Adds a DOM event directly without the caching, cleanup, scope adj, etc
+ * Adds a DOM event directly without the caching, cleanup, context adj, etc
*
* @method _simpleAdd
* @param {HTMLElement} el the element to bind the handler to
@@ -1930,9 +2006,24 @@
*/
EU.on = EU.addListener;
- /////////////////////////////////////////////////////////////
- // DOMReady
- // based on work by: Dean Edwards/John Resig/Matthias Miller
+ /**
+ * YAHOO.util.Event.onFocus is an alias for addFocusListener
+ * @method on
+ * @see addFocusListener
+ * @static
+ */
+ EU.onFocus = EU.addFocusListener;
+
+ /**
+ * YAHOO.util.Event.onBlur is an alias for addBlurListener
+ * @method onBlur
+ * @see addBlurListener
+ * @static
+ */
+ EU.onBlur = EU.addBlurListener;
+
+
+/*! DOMReady: based on work by: Dean Edwards/John Resig/Matthias Miller */
// Internet Explorer: use the readyState of a defered script.
// This isolates what appears to be a safe moment to manipulate
@@ -1940,67 +2031,15 @@
// it is safe to do so.
if (EU.isIE) {
- // Process onAvailable/onContentReady items when when the
+ // Process onAvailable/onContentReady items when the
// DOM is ready.
YAHOO.util.Event.onDOMReady(
YAHOO.util.Event._tryPreloadAttach,
YAHOO.util.Event, true);
-
- /*
-
-
- var el, d=document, b=d.body;
-
- // If the library is being injected after window.onload, it
- // is not safe to document.write the script tag. Detecting
- // this state doesn't appear possible, so we expect a flag
- // in YAHOO_config to be set if the library is being injected.
- if (("undefined" !== typeof YAHOO_config) && YAHOO_config.injecting) {
-
- el = document.createElement("script");
- var p=d.getElementsByTagName("head")[0] || b;
- p.insertBefore(el, p.firstChild);
-
- } else {
- d.write('<scr'+'ipt id="_yui_eu_dr" defer="true" src="//:"><'+'/script>');
- el=document.getElementById("_yui_eu_dr");
- }
-
- if (el) {
- el.onreadystatechange = function() {
- if ("complete" === this.readyState) {
- this.parentNode.removeChild(this);
- YAHOO.util.Event._ready();
- }
- };
- } else {
- // The library was likely injected into the page
- // rendering onDOMReady unreliable
- // YAHOO.util.Event._ready();
- }
-
- el=null;
-
- */
-
-/*
- (function (){
- var n = document.createElement('p');
- try {
- // throws an error if doc is not ready
- n.doScroll('left');
- n = null;
- YAHOO.util.Event._ready();
- } catch (ex){
- n = null;
-setTimeout(arguments.callee, YAHOO.util.Event.POLL_INTERVAL);
- }
- })();
-*/
+ var n = document.createElement('p');
EU._dri = setInterval(function() {
- var n = document.createElement('p');
try {
// throws an error if doc is not ready
n.doScroll('left');
@@ -2009,15 +2048,13 @@
EU._ready();
n = null;
} catch (ex) {
- n = null;
}
}, EU.POLL_INTERVAL);
- // Safari: The document's readyState in Safari currently will
+ // The document's readyState in Safari currently will
// change to loaded/complete before images are loaded.
- //} else if (EU.webkit) {
- } else if (EU.webkit) {
+ } else if (EU.webkit && EU.webkit < 525) {
EU._dri = setInterval(function() {
var rs=document.readyState;
@@ -2029,11 +2066,9 @@
}, EU.POLL_INTERVAL);
// FireFox and Opera: These browsers provide a event for this
- // moment.
+ // moment. The latest WebKit releases now support this event.
} else {
- // @todo will this fire when the library is injected?
-
EU._simpleAdd(document, "DOMContentLoaded", EU._ready);
}
@@ -2083,16 +2118,16 @@
* @param p_fn {function} the function to exectute when the event fires
* @param p_obj {Object} An object to be passed along when the event
* fires
- * @param p_override {boolean} If true, the obj passed in becomes the
+ * @param overrideContext {boolean} If true, the obj passed in becomes the
* execution scope of the listener
*/
- subscribe: function(p_type, p_fn, p_obj, p_override) {
+ subscribe: function(p_type, p_fn, p_obj, overrideContext) {
this.__yui_events = this.__yui_events || {};
var ce = this.__yui_events[p_type];
if (ce) {
- ce.subscribe(p_fn, p_obj, p_override);
+ ce.subscribe(p_fn, p_obj, overrideContext);
} else {
this.__yui_subscribers = this.__yui_subscribers || {};
var subs = this.__yui_subscribers;
@@ -2100,7 +2135,7 @@
subs[p_type] = [];
}
subs[p_type].push(
- { fn: p_fn, obj: p_obj, override: p_override } );
+ { fn: p_fn, obj: p_obj, overrideContext: overrideContext } );
}
},
@@ -2206,7 +2241,7 @@
if (qs) {
for (var i=0; i<qs.length; ++i) {
- ce.subscribe(qs[i].fn, qs[i].obj, qs[i].override);
+ ce.subscribe(qs[i].fn, qs[i].obj, qs[i].overrideContext);
}
}
}
@@ -2224,8 +2259,6 @@
* <li>The custom object (if any) that was passed into the subscribe()
* method</li>
* </ul>
- * If the custom event has not been explicitly created, it will be
- * created now with the default config, scoped to the host object
* @method fireEvent
* @param p_type {string} the type, or name of the event
* @param arguments {Object*} an arbitrary set of parameters to pass to
@@ -2266,6 +2299,10 @@
};
+(function() {
+
+ var Event = YAHOO.util.Event, Lang = YAHOO.lang;
+
/**
* KeyListener is a utility that provides an easy interface for listening for
* keydown/keyup events fired against DOM elements.
@@ -2339,11 +2376,11 @@
*/
this.disabledEvent = new YAHOO.util.CustomEvent("disabled");
- if (typeof attachTo == 'string') {
- attachTo = document.getElementById(attachTo);
+ if (Lang.isString(attachTo)) {
+ attachTo = document.getElementById(attachTo); // No Dom util
}
- if (typeof handler == 'function') {
+ if (Lang.isFunction(handler)) {
keyEvent.subscribe(handler);
} else {
keyEvent.subscribe(handler.fn, handler.scope, handler.correctScope);
@@ -2372,26 +2409,22 @@
e.altKey == keyData.alt &&
e.ctrlKey == keyData.ctrl) { // if we pass this, all modifiers match
- var dataItem;
+ var dataItem, keys = keyData.keys, key;
- if (keyData.keys instanceof Array) {
- for (var i=0;i<keyData.keys.length;i++) {
- dataItem = keyData.keys[i];
+ if (YAHOO.lang.isArray(keys)) {
+ for (var i=0;i<keys.length;i++) {
+ dataItem = keys[i];
+ key = Event.getCharCode(e);
- if (dataItem == e.charCode ) {
- keyEvent.fire(e.charCode, e);
- break;
- } else if (dataItem == e.keyCode) {
- keyEvent.fire(e.keyCode, e);
+ if (dataItem == key) {
+ keyEvent.fire(key, e);
break;
}
}
} else {
- dataItem = keyData.keys;
- if (dataItem == e.charCode ) {
- keyEvent.fire(e.charCode, e);
- } else if (dataItem == e.keyCode) {
- keyEvent.fire(e.keyCode, e);
+ key = Event.getCharCode(e);
+ if (keys == key ) {
+ keyEvent.fire(key, e);
}
}
}
@@ -2404,7 +2437,7 @@
*/
this.enable = function() {
if (! this.enabled) {
- YAHOO.util.Event.addListener(attachTo, event, handleKeyPress);
+ Event.on(attachTo, event, handleKeyPress);
this.enabledEvent.fire(keyData);
}
/**
@@ -2422,7 +2455,7 @@
*/
this.disable = function() {
if (this.enabled) {
- YAHOO.util.Event.removeListener(attachTo, event, handleKeyPress);
+ Event.removeListener(attachTo, event, handleKeyPress);
this.disabledEvent.fire(keyData);
}
this.enabled = false;
@@ -2440,23 +2473,25 @@
};
+var KeyListener = YAHOO.util.KeyListener;
+
/**
-* Constant representing the DOM "keydown" event.
-* @property YAHOO.util.KeyListener.KEYDOWN
-* @static
-* @final
-* @type String
-*/
-YAHOO.util.KeyListener.KEYDOWN = "keydown";
+ * Constant representing the DOM "keydown" event.
+ * @property YAHOO.util.KeyListener.KEYDOWN
+ * @static
+ * @final
+ * @type String
+ */
+KeyListener.KEYDOWN = "keydown";
/**
-* Constant representing the DOM "keyup" event.
-* @property YAHOO.util.KeyListener.KEYUP
-* @static
-* @final
-* @type String
-*/
-YAHOO.util.KeyListener.KEYUP = "keyup";
+ * Constant representing the DOM "keyup" event.
+ * @property YAHOO.util.KeyListener.KEYUP
+ * @static
+ * @final
+ * @type String
+ */
+KeyListener.KEYUP = "keyup";
/**
* keycode constants for a subset of the special keys
@@ -2464,7 +2499,7 @@
* @static
* @final
*/
-YAHOO.util.KeyListener.KEY = {
+KeyListener.KEY = {
ALT : 18,
BACK_SPACE : 8,
CAPS_LOCK : 20,
@@ -2489,4 +2524,6 @@
TAB : 9,
UP : 38
};
-YAHOO.register("event", YAHOO.util.Event, {version: "2.4.1", build: "742"});
+
+})();
+YAHOO.register("event", YAHOO.util.Event, {version: "2.7.0", build: "1799"});