event-synthetic-min.js revision 773ea81b58454b01a90ed69d8a100ce5078404c1
YUI.add("event-synthetic",function(B){var H=B.Env.evt.dom_map,D=B.Array,G=B.Lang,J=G.isObject,C=G.isString,E=B.Selector.query,I=function(){};function F(L,K){this.handle=L;this.emitFacade=K;}F.prototype.fire=function(Q){var K=D(arguments,0,true),O=this.handle,P=O.evt,M=O.sub,R=M.context,L=M.filter,N=Q||{};if(this.emitFacade){if(!Q||!Q.preventDefault){N=P._getFacade();if(J(Q)&&!Q.preventDefault){B.mix(N,Q,true);K[0]=N;}else{K.unshift(N);}}N.type=P.type;N.details=K.slice();if(L){N.container=P.host;}}else{if(L&&J(Q)&&Q.currentTarget){K.shift();}}M.context=R||N.currentTarget||P.host;P.fire.apply(P,K);M.context=R;};function A(){this._init.apply(this,arguments);}B.mix(A,{Notifier:F,getRegistry:function(Q,P,N){var O=Q._node,M=B.stamp(O),L="event:"+M+P+"_synth",K=H[M]||(H[M]={});if(!K[L]&&N){K[L]={type:"_synth",fn:I,capture:false,el:O,key:L,domkey:M,notifiers:[],detachAll:function(){var R=this.notifiers,S=R.length;while(--S>=0){R[S].detach();}}};}return(K[L])?K[L].notifiers:null;},_deleteSub:function(L){if(L&&L.fn){var K=this.eventDef,M=(L.filter)?"detachDelegate":"detach";this.subscribers={};this.subCount=0;K[M](L.node,L,this.notifier,L.filter);K._unregisterSub(L);delete L.fn;delete L.node;delete L.context;}},prototype:{constructor:A,_init:function(){var K=this.publishConfig||(this.publishConfig={});this.emitFacade=("emitFacade" in K)?K.emitFacade:true;K.emitFacade=false;},processArgs:I,on:I,detach:I,delegate:I,detachDelegate:I,_on:function(M,O){var N=[],K=M[2],Q=O?"delegate":"on",L,P;L=(C(K))?E(K):D(K);if(!L.length&&C(K)){P=B.on("available",function(){B.mix(P,B[Q].apply(B,M),true);},K);return P;}B.each(L,function(T){var U=M.slice(),R,S;T=B.one(T);if(T){R=this.processArgs(U,O);if(O){S=U.splice(3,1)[0];}U.splice(0,4,U[1],U[3]);if(!this.preventDups||!this.getSubs(T,M,null,true)){P=this._getNotifier(T,U,R,S);this[Q](T,P.sub,P.notifier,S);N.push(P);}}},this);return(N.length===1)?N[0]:new B.EventHandle(N);},_getNotifier:function(N,Q,O,M){var S=new B.CustomEvent(this.type,this.publishConfig),P=S.on.apply(S,Q),R=new F(P,this.emitFacade),L=A.getRegistry(N,this.type,true),K=P.sub;P.notifier=R;K.node=N;K.filter=M;K._extra=O;B.mix(S,{eventDef:this,notifier:R,host:N,currentTarget:N,target:N,el:N._node,_delete:A._deleteSub},true);L.push(P);return P;},_unregisterSub:function(M){var K=A.getRegistry(M.node,this.type),L;if(K){for(L=K.length-1;L>=0;--L){if(K[L].sub===M){K.splice(L,1);break;}}}},_detach:function(M){var R=M[2],P=(C(R))?E(R):D(R),Q,O,K,N,L;M.splice(2,1);for(O=0,K=P.length;O<K;++O){Q=B.one(P[O]);if(Q){N=this.getSubs(Q,M);if(N){for(L=N.length-1;L>=0;--L){N[L].detach();}}}}},getSubs:function(L,Q,K,N){var R=A.getRegistry(L,this.type),S=[],M,P,O;if(R){if(!K){K=this.subMatch;}for(M=0,P=R.length;M<P;++M){O=R[M];if(K.call(this,O.sub,Q)){if(N){return O;}else{S.push(R[M]);}}}}return S.length&&S;},subMatch:function(L,K){return !K[1]||L.fn===K[1];}}},true);B.SyntheticEvent=A;B.Event.define=function(M,L,O){if(!L){L={};}var N=(J(M))?M:B.merge({type:M},L),P,K;if(O||!B.Node.DOM_EVENTS[N.type]){P=function(){A.apply(this,arguments);};B.extend(P,A,N);K=new P();M=K.type;B.Node.DOM_EVENTS[M]=B.Env.evt.plugins[M]={eventDef:K,on:function(){return K._on(D(arguments));},delegate:function(){return K._on(D(arguments),true);},detach:function(){return K._detach(D(arguments));}};}return K;};},"@VERSION@",{requires:["node-base","event-custom"]});