(function(a,b){if(typeof define==="function"&&define.amd){define(b) }else{if(typeof exports!=="undefined"){module.exports=b() }else{a.atmosphere=b() }}}(this,function(){var a={},d,c=false,g=[],f=[],e=0,b=Object.prototype.hasOwnProperty; a={version:"2.3.6-javascript",onError:function(h){},onClose:function(h){},onOpen:function(h){},onReopen:function(h){},onMessage:function(h){},onReconnect:function(i,h){},onMessagePublished:function(h){},onTransportFailure:function(i,h){},onLocalMessage:function(h){},onFailureToReconnect:function(i,h){},onClientTimeout:function(h){},onOpenAfterResume:function(h){},WebsocketApiAdapter:function(i){var h,j; i.onMessage=function(k){j.onmessage({data:k.responseBody}) }; i.onMessagePublished=function(k){j.onmessage({data:k.responseBody}) }; i.onOpen=function(k){j.onopen(k) }; j={close:function(){h.close() },send:function(k){h.push(k) },onmessage:function(k){},onopen:function(k){},onclose:function(k){},onerror:function(k){}}; h=new a.subscribe(i); return j },AtmosphereRequest:function(ad){var p={timeout:300000,method:"GET",headers:{},contentType:"",callback:null,url:"",data:"",suspend:true,maxRequest:-1,reconnect:true,maxStreamingLength:10000000,lastIndex:0,logLevel:"info",requestCount:0,fallbackMethod:"GET",fallbackTransport:"streaming",transport:"long-polling",webSocketImpl:null,webSocketBinaryType:null,dispatchUrl:null,webSocketPathDelimiter:"@@",enableXDR:false,rewriteURL:false,attachHeadersAsQueryString:true,executeCallbackBeforeReconnect:false,readyState:0,withCredentials:false,trackMessageLength:false,messageDelimiter:"|",connectTimeout:-1,reconnectInterval:0,dropHeaders:true,uuid:0,async:true,shared:false,readResponsesHeaders:false,maxReconnectOnClose:5,enableProtocol:true,disableDisconnect:false,pollingInterval:0,heartbeat:{client:null,server:null},ackInterval:0,closeAsync:false,reconnectOnServerError:true,handleOnlineOffline:true,maxWebsocketErrorRetries:1,curWebsocketErrorRetries:0,onError:function(aI){},onClose:function(aI){},onOpen:function(aI){},onMessage:function(aI){},onReopen:function(aJ,aI){},onReconnect:function(aJ,aI){},onMessagePublished:function(aI){},onTransportFailure:function(aJ,aI){},onLocalMessage:function(aI){},onFailureToReconnect:function(aJ,aI){},onClientTimeout:function(aI){},onOpenAfterResume:function(aI){}}; var ar={status:200,reasonPhrase:"OK",responseBody:"",messages:[],headers:[],state:"messageReceived",transport:"polling",error:null,request:null,partialMessage:"",errorHandled:false,closedByClientTimeout:false,ffTryingReconnect:false}; var aw=null; var ag=null; var z=null; var n=null; var X=null; var u=true; var ay=0; var J=0; var ak="X"; var aG=false; var Q=null; var h; var ax=null; var R=a.util.now(); var y; var aF; var Y=false; ao(ad); function aj(){u=true; aG=false; ay=0; aw=null; ag=null; z=null; n=null }function U(){l(); aj() }function w(aI){if(aI=="debug"){return p.logLevel==="debug" }else{if(aI=="info"){return p.logLevel==="info"||p.logLevel==="debug" }else{if(aI=="warn"){return p.logLevel==="warn"||p.logLevel==="info"||p.logLevel==="debug" }else{if(aI=="error"){return p.logLevel==="error"||p.logLevel==="warn"||p.logLevel==="info"||p.logLevel==="debug" }else{return false }}}}}function aH(aI){if(w("debug")){a.util.debug(new Date()+" Atmosphere: "+aI) }}function I(aJ,aI){if(ar.partialMessage===""&&(aI.transport==="streaming")&&(aJ.responseText.length>aI.maxStreamingLength)){return true }return false }function D(){if(p.enableProtocol&&!p.disableDisconnect&&!p.firstMessage){var aK="X-Atmosphere-Transport=close&X-Atmosphere-tracking-id="+p.uuid; a.util.each(p.headers,function(aM,aO){var aN=a.util.isFunction(aO)?aO.call(this,p,p,ar):aO; if(aN!=null){aK+="&"+encodeURIComponent(aM)+"="+encodeURIComponent(aN) }}); var aI=p.url.replace(/([?&])_=[^&]*/,aK); aI=aI+(aI===p.url?(/\?/.test(p.url)?"&":"?")+aK:""); var aJ={connected:false}; var aL=new a.AtmosphereRequest(aJ); aL.connectTimeout=p.connectTimeout; aL.attachHeadersAsQueryString=false; aL.dropHeaders=true; aL.url=aI; aL.contentType="text/plain"; aL.transport="polling"; aL.method="GET"; aL.data=""; aL.heartbeat=null; if(p.enableXDR){aL.enableXDR=p.enableXDR }aL.async=p.closeAsync; am("",aL) }}function H(){aH("Closing (AtmosphereRequest._close() called)"); aG=true; if(p.reconnectId){clearTimeout(p.reconnectId); delete p.reconnectId }if(p.heartbeatTimer){clearTimeout(p.heartbeatTimer) }p.reconnect=false; ar.request=p; ar.state="unsubscribe"; ar.responseBody=""; ar.status=408; ar.partialMessage=""; p.curWebsocketErrorRetries=0; ai(); D(); l() }function l(){ar.partialMessage=""; if(p.id){clearTimeout(p.id) }if(p.heartbeatTimer){clearTimeout(p.heartbeatTimer) }if(p.reconnectId){clearTimeout(p.reconnectId); delete p.reconnectId }if(n!=null){n.close(); n=null }if(X!=null){X.abort(); X=null }if(z!=null){z.abort(); z=null }if(aw!=null){if(aw.canSendMessage){aH("invoking .close() on WebSocket object"); aw.close() }aw=null }if(ag!=null){ag.close(); ag=null }ah() }function ah(){if(h!=null){clearInterval(y); document.cookie=aF+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"; h.signal("close",{reason:"",heir:!aG?R:(h.get("children")||[])[0]}); h.close() }if(ax!=null){ax.close() }}function ao(aI){U(); p=a.util.extend(p,aI); p.mrequest=p.reconnect; if(!p.reconnect){p.reconnect=true }}function au(){return p.webSocketImpl!=null||window.WebSocket||window.MozWebSocket }function at(){var aJ=a.util.getAbsoluteURL(p.url.toLowerCase()); var aK=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/.exec(aJ); var aI=!!(aK&&(aK[1]!=window.location.protocol||aK[2]!=window.location.hostname||(aK[3]||(aK[1]==="http:"?80:443))!=(window.location.port||(window.location.protocol==="http:"?80:443)))); return window.EventSource&&(!aI||!a.util.browser.safari||a.util.browser.vmajor>=7) }function aa(){if(p.shared){ax=aD(p); if(ax!=null){if(w("debug")){a.util.debug("Storage service available. All communication will be local") }if(ax.open(p)){return }}if(w("debug")){a.util.debug("No Storage service available.") }ax=null }p.firstMessage=e==0?true:false; p.isOpen=false; p.ctime=a.util.now(); if(p.uuid===0){p.uuid=e }ar.closedByClientTimeout=false; if(p.transport!=="websocket"&&p.transport!=="sse"){L(p) }else{if(p.transport==="websocket"){if(!au()){az("Websocket is not supported, using request.fallbackTransport ("+p.fallbackTransport+")") }else{af(false) }}else{if(p.transport==="sse"){if(!at()){az("Server Side Events(SSE) is not supported, using request.fallbackTransport ("+p.fallbackTransport+")") }else{C(false) }}}}}function aD(aM){var aN,aL,aQ,aI="atmosphere-"+aM.url,aJ={storage:function(){function aR(aV){if(aV.key===aI&&aV.newValue){aK(aV.newValue) }}if(!a.util.storage){return }var aU=window.localStorage,aS=function(aV){var aW=aU.getItem(aI+"-"+aV); return aW===null?[]:JSON.parse(aW) },aT=function(aV,aW){aU.setItem(aI+"-"+aV,JSON.stringify(aW)) }; return{init:function(){aT("children",aS("children").concat([R])); a.util.on(window,"storage",aR); return aS("opened") },signal:function(aV,aW){aU.setItem(aI,JSON.stringify({target:"p",type:aV,data:aW})) },close:function(){var aV=aS("children"); a.util.off(window,"storage",aR); if(aV){if(aO(aV,aM.id)){aT("children",aV) }}}} },windowref:function(){var aR=window.open("",aI.replace(/\W/g,"")); if(!aR||aR.closed||!aR.callbacks){return }return{init:function(){aR.callbacks.push(aK); aR.children.push(R); return aR.opened },signal:function(aS,aT){if(!aR.closed&&aR.fire){aR.fire(JSON.stringify({target:"p",type:aS,data:aT})) }},close:function(){if(!aQ){aO(aR.callbacks,aK); aO(aR.children,R) }}} }}; function aO(aU,aT){var aR,aS=aU.length; for(aR=0; aR1000){return }aL=aJ.storage()||aJ.windowref(); if(!aL){return }return{open:function(){var aR; y=setInterval(function(){var aS=aN; aN=aP(); if(!aN||aS.ts===aN.ts){aK(JSON.stringify({target:"c",type:"close",data:{reason:"error",heir:aS.heir}})) }},1000); aR=aL.init(); if(aR){setTimeout(function(){V("opening","local",aM) },50) }return aR },send:function(aR){aL.signal("send",aR) },localSend:function(aR){aL.signal("localSend",JSON.stringify({id:R,event:aR})) },close:function(){if(!aG){clearInterval(y); aL.signal("close"); aL.close() }}} }function aE(){var aJ,aI="atmosphere-"+p.url,aN={storage:function(){function aO(aQ){if(aQ.key===aI&&aQ.newValue){aK(aQ.newValue) }}if(!a.util.storage){return }var aP=window.localStorage; return{init:function(){a.util.on(window,"storage",aO) },signal:function(aQ,aR){aP.setItem(aI,JSON.stringify({target:"c",type:aQ,data:aR})) },get:function(aQ){return JSON.parse(aP.getItem(aI+"-"+aQ)) },set:function(aQ,aR){aP.setItem(aI+"-"+aQ,JSON.stringify(aR)) },close:function(){a.util.off(window,"storage",aO); aP.removeItem(aI); aP.removeItem(aI+"-opened"); aP.removeItem(aI+"-children") }} },windowref:function(){var aP=aI.replace(/\W/g,""),aO=document.getElementById(aP),aQ; if(!aO){aO=document.createElement("div"); aO.id=aP; aO.style.display="none"; aO.innerHTML='