event-custom-base-min.js revision ad3e803b573f1ad93069380c0fa13ecac5ada5c5
YUI.add("event-custom-base",function(E){E.Env.evt={handles:{},plugins:{}};(function(){var F=0,G=1;E.Do={objs:{},before:function(I,K,L,M){var J=I,H;if(M){H=[I,M].concat(E.Array(arguments,4,true));J=E.rbind.apply(E,H);}return this._inject(F,J,K,L);},after:function(I,K,L,M){var J=I,H;if(M){H=[I,M].concat(E.Array(arguments,4,true));J=E.rbind.apply(E,H);}return this._inject(G,J,K,L);},_inject:function(H,J,K,M){var N=E.stamp(K),L,I;if(!this.objs[N]){this.objs[N]={};}L=this.objs[N];if(!L[M]){L[M]=new E.Do.Method(K,M);K[M]=function(){return L[M].exec.apply(L[M],arguments);};}I=N+E.stamp(J)+M;L[M].register(I,J,H);return new E.EventHandle(L[M],I);},detach:function(H){if(H.detach){H.detach();}},_unload:function(I,H){}};E.Do.Method=function(H,I){this.obj=H;this.methodName=I;this.method=H[I];this.before={};this.after={};};E.Do.Method.prototype.register=function(I,J,H){if(H){this.after[I]=J;}else{this.before[I]=J;}};E.Do.Method.prototype._delete=function(H){delete this.before[H];delete this.after[H];};E.Do.Method.prototype.exec=function(){var J=E.Array(arguments,0,true),K,I,N,L=this.before,H=this.after,M=false;for(K in L){if(L.hasOwnProperty(K)){I=L[K].apply(this.obj,J);if(I){switch(I.constructor){case E.Do.Halt:return I.retVal;case E.Do.AlterArgs:J=I.newArgs;break;case E.Do.Prevent:M=true;break;default:}}}}if(!M){I=this.method.apply(this.obj,J);}for(K in H){if(H.hasOwnProperty(K)){N=H[K].apply(this.obj,J);if(N&&N.constructor==E.Do.Halt){return N.retVal;}else{if(N&&N.constructor==E.Do.AlterReturn){I=N.newRetVal;}}}}return I;};E.Do.AlterArgs=function(I,H){this.msg=I;this.newArgs=H;};E.Do.AlterReturn=function(I,H){this.msg=I;this.newRetVal=H;};E.Do.Halt=function(I,H){this.msg=I;this.retVal=H;};E.Do.Prevent=function(H){this.msg=H;};E.Do.Error=E.Do.Halt;})();var D="after",B=["broadcast","monitored","bubbles","context","contextFn","currentTarget","defaultFn","defaultTargetOnly","details","emitFacade","fireOnce","async","host","preventable","preventedFn","queuable","silent","stoppedFn","target","type"],C=9,A="yui:log";E.EventHandle=function(F,G){this.evt=F;this.sub=G;};E.EventHandle.prototype={each:function(F){F(this);if(E.Lang.isArray(this.evt)){E.Array.each(this.evt,function(G){G.each(F);});}},detach:function(){var F=this.evt,H=0,G;if(F){if(E.Lang.isArray(F)){for(G=0;G<F.length;G++){H+=F[G].detach();}}else{F._delete(this.sub);H=1;}}return H;},monitor:function(F){return this.evt.monitor.apply(this.evt,arguments);}};E.CustomEvent=function(F,G){G=G||{};this.id=E.stamp(this);this.type=F;this.context=E;this.logSystem=(F==A);this.silent=this.logSystem;this.subscribers={};this.afters={};this.preventable=true;this.bubbles=true;this.signature=C;this.subCount=0;this.afterCount=0;this.applyConfig(G,true);};E.CustomEvent.prototype={hasSubs:function(F){var I=this.subCount,G=this.afterCount,H=this.sibling;if(H){I+=H.subCount;G+=H.afterCount;}if(F){return(F=="after")?G:I;}return(I+G);},monitor:function(H){this.monitored=true;var G=this.id+"|"+this.type+"_"+H,F=E.Array(arguments,0,true);F[0]=G;return this.host.on.apply(this.host,F);},getSubs:function(){var H=E.merge(this.subscribers),F=E.merge(this.afters),G=this.sibling;if(G){E.mix(H,G.subscribers);E.mix(F,G.afters);}return[H,F];},applyConfig:function(G,F){if(G){E.mix(this,G,F,B);}},_on:function(J,H,G,F){if(!J){this.log("Invalid callback for CE: "+this.type);}var I=new E.Subscriber(J,H,G,F);if(this.fireOnce&&this.fired){if(this.async){setTimeout(E.bind(this._notify,this,I,this.firedWith),0);}else{this._notify(I,this.firedWith);}}if(F==D){this.afters[I.id]=I;this.afterCount++;}else{this.subscribers[I.id]=I;this.subCount++;}return new E.EventHandle(this,I);},subscribe:function(H,G){var F=(arguments.length>2)?E.Array(arguments,2,true):null;return this._on(H,G,F,true);},on:function(H,G){var F=(arguments.length>2)?E.Array(arguments,2,true):null;if(this.host){this.host._monitor("attach",this.type,{args:arguments});}return this._on(H,G,F,true);},after:function(H,G){var F=(arguments.length>2)?E.Array(arguments,2,true):null;return this._on(H,G,F,D);},detach:function(J,H){if(J&&J.detach){return J.detach();}var K=0,G=this.subscribers,F,I;for(F in G){if(G.hasOwnProperty(F)){I=G[F];if(I&&(!J||J===I.fn)){this._delete(I);K++;}}}return K;},unsubscribe:function(){return this.detach.apply(this,arguments);},_notify:function(I,H,F){this.log(this.type+"->"+"sub: "+I.id);var G;G=I.notify(H,this);if(false===G||this.stopped>1){this.log(this.type+" cancelled by subscriber");return false;}return true;},log:function(G,F){if(!this.silent){}},fire:function(){if(this.fireOnce&&this.fired){this.log("fireOnce event: "+this.type+" already fired");return true;}else{var F=E.Array(arguments,0,true);this.fired=true;this.firedWith=F;if(this.emitFacade){return this.fireComplex(F);}else{return this.fireSimple(F);}}},fireSimple:function(F){this.stopped=0;this.prevented=0;if(this.hasSubs()){var G=this.getSubs();this._procSubs(G[0],F);this._procSubs(G[1],F);}this._broadcast(F);return this.stopped?false:true;},fireComplex:function(F){F[0]=F[0]||{};return this.fireSimple(F);},_procSubs:function(I,G,F){var J,H;for(H in I){if(I.hasOwnProperty(H)){J=I[H];if(J&&J.fn){if(false===this._notify(J,G,F)){this.stopped=2;}if(this.stopped==2){return false;}}}}return true;},_broadcast:function(G){if(!this.stopped&&this.broadcast){var F=E.Array(G);F.unshift(this.type);if(this.host!==E){E.fire.apply(E,F);}if(this.broadcast==2){E.Global.fire.apply(E.Global,F);}}},unsubscribeAll:function(){return this.detachAll.apply(this,arguments);},detachAll:function(){return this.detach();},_delete:function(F){if(F){if(this.subscribers[F.id]){delete this.subscribers[F.id];this.subCount--;}if(this.afters[F.id]){delete this.afters[F.id];this.afterCount--;}}if(this.host){this.host._monitor("detach",this.type,{ce:this,sub:F});}if(F){delete F.fn;delete F.context;}}};E.Subscriber=function(H,G,F){this.fn=H;this.context=G;this.id=E.stamp(this);this.args=F;};E.Subscriber.prototype={_notify:function(J,H,I){var F=this.args,G;switch(I.signature){case 0:G=this.fn.call(J,I.type,H,J);
break;case 1:G=this.fn.call(J,H[0]||null,J);break;default:if(F||H){H=H||[];F=(F)?H.concat(F):H;G=this.fn.apply(J,F);}else{G=this.fn.call(J);}}if(this.once){I._delete(this);}return G;},notify:function(G,I){var J=this.context,F=true;if(!J){J=(I.contextFn)?I.contextFn():I.context;}if(E.config.throwFail){F=this._notify(J,G,I);}else{try{F=this._notify(J,G,I);}catch(H){E.error(this+" failed: "+H.message,H);}}return F;},contains:function(G,F){if(F){return((this.fn==G)&&this.context==F);}else{return(this.fn==G);}}};(function(){var K=E.Lang,J=":",H="|",N="~AFTER~",M=E.Array,F=E.cached(function(L){return L.replace(/(.*)(:)(.*)/,"*$2$3");}),O=E.cached(function(L,P){if(!P||!K.isString(L)||L.indexOf(J)>-1){return L;}return P+J+L;}),I=E.cached(function(Q,S){var P=Q,R,T,L;if(!K.isString(P)){return P;}L=P.indexOf(N);if(L>-1){T=true;P=P.substr(N.length);}L=P.indexOf(H);if(L>-1){R=P.substr(0,(L));P=P.substr(L+1);if(P=="*"){P=null;}}return[R,(S)?O(P,S):P,T,P];}),G=function(L){var P=(K.isObject(L))?L:{};this._yuievt=this._yuievt||{id:E.guid(),events:{},targets:{},config:P,chain:("chain" in P)?P.chain:E.config.chain,bubbling:false,defaults:{context:P.context||this,host:this,emitFacade:P.emitFacade,fireOnce:P.fireOnce,queuable:P.queuable,monitored:P.monitored,broadcast:P.broadcast,defaultTargetOnly:P.defaultTargetOnly,bubbles:("bubbles" in P)?P.bubbles:true}};};G.prototype={once:function(){var L=this.on.apply(this,arguments);L.each(function(P){if(P.sub){P.sub.once=true;}});return L;},on:function(S,X,Q){var a=I(S,this._yuievt.config.prefix),d,e,P,i,Z,Y,g,U=E.Env.evt.handles,R,L,V,h=E.Node,b,W,T;this._monitor("attach",a[1],{args:arguments,category:a[0],after:a[2]});if(K.isObject(S)){if(K.isFunction(S)){return E.Do.before.apply(E.Do,arguments);}d=X;e=Q;P=M(arguments,0,true);i=[];if(K.isArray(S)){T=true;}R=S._after;delete S._after;E.each(S,function(j,f){if(K.isObject(j)){d=j.fn||((K.isFunction(j))?j:d);e=j.context||e;}var c=(R)?N:"";P[0]=c+((T)?j:f);P[1]=d;P[2]=e;i.push(this.on.apply(this,P));},this);return(this._yuievt.chain)?this:new E.EventHandle(i);}Y=a[0];R=a[2];V=a[3];if(h&&(this instanceof h)&&(V in h.DOM_EVENTS)){P=M(arguments,0,true);P.splice(2,0,h.getDOMNode(this));return E.on.apply(E,P);}S=a[1];if(this instanceof YUI){L=E.Env.evt.plugins[S];P=M(arguments,0,true);P[0]=V;if(h){b=P[2];if(b instanceof E.NodeList){b=E.NodeList.getDOMNodes(b);}else{if(b instanceof h){b=h.getDOMNode(b);}}W=(V in h.DOM_EVENTS);if(W){P[2]=b;}}if(L){g=L.on.apply(E,P);}else{if((!S)||W){g=E.Event._attach(P);}}}if(!g){Z=this._yuievt.events[S]||this.publish(S);g=Z._on(X,Q,(arguments.length>3)?M(arguments,3,true):null,(R)?"after":true);}if(Y){U[Y]=U[Y]||{};U[Y][S]=U[Y][S]||[];U[Y][S].push(g);}return(this._yuievt.chain)?this:g;},subscribe:function(){return this.on.apply(this,arguments);},detach:function(X,Z,L){var d=this._yuievt.events,S,U=E.Node,b=U&&(this instanceof U);if(!X&&(this!==E)){for(S in d){if(d.hasOwnProperty(S)){d[S].detach(Z,L);}}if(b){E.Event.purgeElement(U.getDOMNode(this));}return this;}var R=I(X,this._yuievt.config.prefix),W=K.isArray(R)?R[0]:null,e=(R)?R[3]:null,T,a=E.Env.evt.handles,c,Y,V,Q,P=function(k,h,j){var g=k[h],l,f;if(g){for(f=g.length-1;f>=0;--f){l=g[f].evt;if(l.host===j||l.el===j){g[f].detach();}}}};if(W){Y=a[W];X=R[1];c=(b)?E.Node.getDOMNode(this):this;if(Y){if(X){P(Y,X,c);}else{for(S in Y){if(Y.hasOwnProperty(S)){P(Y,S,c);}}}return this;}}else{if(K.isObject(X)&&X.detach){X.detach();return this;}else{if(b&&((!e)||(e in U.DOM_EVENTS))){V=M(arguments,0,true);V[2]=U.getDOMNode(this);E.detach.apply(E,V);return this;}}}T=E.Env.evt.plugins[e];if(this instanceof YUI){V=M(arguments,0,true);if(T&&T.detach){T.detach.apply(E,V);return this;}else{if(!X||(!T&&U&&(X in U.DOM_EVENTS))){V[0]=X;E.Event.detach.apply(E.Event,V);return this;}}}Q=d[R[1]];if(Q){Q.detach(Z,L);}return this;},unsubscribe:function(){return this.detach.apply(this,arguments);},detachAll:function(L){return this.detach(L);},unsubscribeAll:function(){return this.detachAll.apply(this,arguments);},publish:function(Q,R){var P,V,L,U,T=this._yuievt,S=T.config.prefix;Q=(S)?O(Q,S):Q;this._monitor("publish",Q,{args:arguments});if(K.isObject(Q)){L={};E.each(Q,function(X,W){L[W]=this.publish(W,X||R);},this);return L;}P=T.events;V=P[Q];if(V){if(R){V.applyConfig(R,true);}}else{U=T.defaults;V=new E.CustomEvent(Q,(R)?E.merge(U,R):U);P[Q]=V;}return P[Q];},_monitor:function(R,L,S){var P,Q=this.getEvent(L);if((this._yuievt.config.monitored&&(!Q||Q.monitored))||(Q&&Q.monitored)){P=L+"_"+R;S.monitored=R;this.fire.call(this,P,S);}},fire:function(R){var V=K.isString(R),Q=(V)?R:(R&&R.type),U,P,T=this._yuievt.config.prefix,S,L=(V)?M(arguments,1,true):arguments;Q=(T)?O(Q,T):Q;this._monitor("fire",Q,{args:L});U=this.getEvent(Q,true);S=this.getSibling(Q,U);if(S&&!U){U=this.publish(Q);}if(!U){if(this._yuievt.hasTargets){return this.bubble({type:Q},L,this);}P=true;}else{U.sibling=S;P=U.fire.apply(U,L);}return(this._yuievt.chain)?this:P;},getSibling:function(L,Q){var P;if(L.indexOf(J)>-1){L=F(L);P=this.getEvent(L,true);if(P){P.applyConfig(Q);P.bubbles=false;P.broadcast=0;}}return P;},getEvent:function(P,L){var R,Q;if(!L){R=this._yuievt.config.prefix;P=(R)?O(P,R):P;}Q=this._yuievt.events;return Q[P]||null;},after:function(Q,P){var L=M(arguments,0,true);switch(K.type(Q)){case"function":return E.Do.after.apply(E.Do,arguments);case"array":case"object":L[0]._after=true;break;default:L[0]=N+Q;}return this.on.apply(this,L);},before:function(){return this.on.apply(this,arguments);}};E.EventTarget=G;E.mix(E,G.prototype,false,false,{bubbles:false});G.call(E);YUI.Env.globalEvents=YUI.Env.globalEvents||new G();E.Global=YUI.Env.globalEvents;})();},"@VERSION@",{requires:["oop"]});