io-base-min.js revision 3327eba7caef16e3d5b0496f979b07c9998e70b7
YUI.add("io-base",function(a){var h=a.Lang,k=["start","complete","end","success","failure"],g=["status","statusText","responseText","responseXML"],b="getAllResponseHeaders",d="getResponseHeader",i=a.config.win,j=i.XMLHttpRequest,e=i.XDomainRequest,f=0;function c(m){var l=this;l._uid="io:"+f++;l._init(m);a.io._map[l._uid]=l;}c.prototype={_id:0,_headers:{"X-Requested-With":"XMLHttpRequest"},_timeout:{},_init:function(n){var m=this,l;m.cfg=n||{};a.augment(m,a.EventTarget);for(l=0;l<5;l++){m.publish("io:"+k[l],a.merge({broadcast:1},n));m.publish("io-trn:"+k[l],n);}},_create:function(v,p){var s=this,r={id:h.isNumber(p)?p:s._id++,uid:s._uid},l=v.xdr,m=l?l.use:v.form&&v.form.upload?"iframe":"xhr",q=(l&&l.use==="native"&&e),n=s._transport;switch(m){case"native":case"xhr":r.c=q?new e():j?new j():new ActiveXObject("Microsoft.XMLHTTP");r.t=q?true:false;break;default:r.c=n?n[m]:{};r.t=true;}return r;},_destroy:function(l){if(i){if(j&&l.t===true){l.c.onreadystatechange=null;}else{if(a.UA.ie){l.c.abort();}}}l.c=null;l=null;},_evt:function(q,n,u){var t=this,l,x,v=u["arguments"],w=t.cfg.emitFacade,m="io:"+q,r="io-trn:"+q;if(n.e){n.c={status:0,statusText:n.e};}l=w?[{id:n.id,data:n.c,cfg:u,"arguments":v}]:[n.id];if(!w){if(q===k[0]||q===k[2]){if(v){l.push(v);}}else{x=v?l.push(n.c,v):l.push(n.c);}}l.unshift(m);t.fire.apply(t,l);if(u.on){l[0]=r;t.once(r,u.on[q],u.context||a);t.fire.apply(t,l);}},start:function(l,m){this._evt(k[0],l,m);},complete:function(l,m){this._evt(k[1],l,m);},end:function(l,m){this._evt(k[2],l,m);this._destroy(l);},success:function(l,m){this._evt(k[3],l,m);this.end(l,m);},failure:function(l,m){this._evt(k[4],l,m);this.end(l,m);},_retry:function(m,l,n){this._destroy(m);n.xdr.use="flash";return this.send(l,n,m.id);},_concat:function(l,m){l+=(l.indexOf("?")===-1?"?":"&")+m;return l;},setHeader:function(m,n){if(n){this._headers[m]=n;}else{delete this._headers[m];}},_setHeaders:function(m,l){l=a.merge(this._headers,l);a.Object.each(l,function(n,o){if(n!=="disable"){m.setRequestHeader(o,l[o]);}});},_startTimeout:function(m,l){var n=this;n._timeout[m.id]=i.setTimeout(function(){n._abort(m,"timeout");},l);},_clearTimeout:function(l){i.clearTimeout(this._timeout[l]);delete this._timeout[l];},_result:function(n,p){var l;try{l=n.c.status;}catch(m){l=0;}if(l>=200&&l<300||l===1223){this.success(n,p);}else{this.failure(n,p);}},_rS:function(l,n){var m=this;if(l.c.readyState===4){if(n.timeout){m._clearTimeout(l.id);}i.setTimeout(function(){m.complete(l,n);m._result(l,n);},0);}},_abort:function(m,l){if(m&&m.c){m.e=l;m.c.abort();}},send:function(p,y,t){var n,q,l,A,x,w=this,z=p;y=y?a.Object(y):{};n=w._create(y,t);q=y.method?y.method.toUpperCase():"GET";A=y.sync;x=y.data;if(h.isObject(x)){x=a.QueryString.stringify(x);}if(y.form){if(y.form.upload){return w.upload(n,p,y);}else{x=w._serialize(y.form,x);}}if(x){switch(q){case"GET":case"HEAD":case"DELETE":z=w._concat(z,x);x="";break;case"POST":case"PUT":y.headers=a.merge({"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},y.headers);break;}}if(n.t){return w.xdr(z,n,y);}if(!A){n.c.onreadystatechange=function(){w._rS(n,y);};}try{n.c.open(q,z,A?false:true,y.username||null,y.password||null);w._setHeaders(n.c,y.headers||{});w.start(n,y);if(y.xdr&&y.xdr.credentials){if(!a.UA.ie){n.c.withCredentials=true;}}n.c.send(x);if(A){l=a.mix({id:n.id,"arguments":y["arguments"]},n.c,false,g);l[b]=function(){return n.c[b]();};l[d]=function(m){return n.c[d](m);};w.complete(n,y);w._result(n,y);return l;}}catch(v){if(n.t){return w._retry(n,p,y);}else{w.complete(n,y);w._result(n,y);}}if(y.timeout){w._startTimeout(n,y.timeout);}return{id:n.id,abort:function(){return n.c?w._abort(n,"abort"):false;},isInProgress:function(){return n.c?n.c.readyState!==4&&n.c.readyState!==0:false;},io:w};}};a.io=function(l,n){var m=a.io._map["io:0"]||new c();return m.send.apply(m,[l,n]);};a.io.header=function(m,n){var p=a.io._map["io:0"]||new c();p.setHeader(m,n);};a.IO=c;a.io._map={};},"@VERSION@",{requires:["event-custom-base","querystring-stringify-simple"]});