Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
jQuery.atmosphere=function(){jQuery(window).bind("unload.atmosphere",function(){jQuery.atmosphere.unsubscribe()
});
jQuery(window).keypress(function(B){if(B.keyCode==27){B.preventDefault()
}});
var A=function(C){var B,E=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,D={};
while(B=E.exec(C)){D[B[1]]=B[2]
}return D
};
return{version:"1.0.1",requests:[],callbacks:[],onError:function(B){},onClose:function(B){},onOpen:function(B){},onMessage:function(B){},onReconnect:function(C,B){},onMessagePublished:function(B){},onTransportFailure:function(B){},onLocalMessage:function(B){},AtmosphereRequest:function(a){var c={timeout:300000,method:"GET",headers:{},contentType:"",callback:null,url:"",data:"",suspend:true,maxRequest:60,reconnect:true,maxStreamingLength:10000000,lastIndex:0,logLevel:"info",requestCount:0,fallbackMethod:"GET",fallbackTransport:"streaming",transport:"long-polling",webSocketImpl:null,webSocketUrl:null,webSocketPathDelimiter:"@@",enableXDR:false,rewriteURL:false,attachHeadersAsQueryString:true,executeCallbackBeforeReconnect:false,readyState:0,lastTimestamp:0,withCredentials:false,trackMessageLength:false,messageDelimiter:"|",connectTimeout:-1,reconnectInterval:0,dropAtmosphereHeaders:true,uuid:0,shared:false,readResponsesHeaders:true,onError:function(AK){},onClose:function(AK){},onOpen:function(AK){},onMessage:function(AK){},onReconnect:function(AL,AK){},onMessagePublished:function(AK){},onTransportFailure:function(AL,AK){},onLocalMessage:function(AK){}};
var k={status:200,responseBody:"",headers:[],state:"messageReceived",transport:"polling",error:null,request:null,partialMessage:"",id:0};
var n=null;
var H=null;
var M=null;
var T=null;
var V=null;
var w=true;
var F=0;
var AH=false;
var o=null;
var AC;
var J=null;
var Y=jQuery.now();
var Z;
AJ(a);
function AD(){w=true;
AH=false;
F=0;
n=null;
H=null;
M=null;
T=null
}function Q(){y();
AD()
}function AJ(AK){Q();
c=jQuery.extend(c,AK)
}function I(){return c.webSocketImpl!=null||window.WebSocket||window.MozWebSocket
}function g(){return window.EventSource
}function L(){if(c.shared){J=v(c);
if(J!=null){if(c.logLevel=="debug"){jQuery.atmosphere.debug("Storage service available. All communication will be local")
}if(J.open(c)){return 
}}if(c.logLevel=="debug"){jQuery.atmosphere.debug("No Storage service available.")
}J=null
}if(c.transport!="websocket"&&c.transport!="sse"){b("opening",c.transport,c);
K()
}else{if(c.transport=="websocket"){if(!I()){e("Websocket is not supported, using request.fallbackTransport ("+c.fallbackTransport+")")
}else{x(false)
}}else{if(c.transport=="sse"){if(!g()){e("Server Side Events(SSE) is not supported, using request.fallbackTransport ("+c.fallbackTransport+")")
}else{X(false)
}}}}}function v(AO){var AR,AL,AN,AM="atmosphere-"+AO.url,AK={storage:function(){if(!jQuery.atmosphere.supportStorage()){return 
}var AU=window.localStorage,AS=function(AV){return jQuery.parseJSON(AU.getItem(AM+"-"+AV))
},AT=function(AV,AW){AU.setItem(AM+"-"+AV,jQuery.stringifyJSON(AW))
};
return{init:function(){AT("children",AS("children").concat([Y]));
jQuery(window).on("storage.socket",function(AV){AV=AV.originalEvent;
if(AV.key===AM&&AV.newValue){AQ(AV.newValue)
}});
return AS("opened")
},signal:function(AV,AW){AU.setItem(AM,jQuery.stringifyJSON({target:"p",type:AV,data:AW}))
},close:function(){var AV,AW=AS("children");
jQuery(window).off("storage.socket");
if(AW){AV=jQuery.inArray(AO.id,AW);
if(AV>-1){AW.splice(AV,1);
AT("children",AW)
}}}}
},windowref:function(){var AS=window.open("",AM.replace(/\W/g,""));
if(!AS||AS.closed||!AS.callbacks){return 
}return{init:function(){AS.callbacks.push(AQ);
AS.children.push(Y);
return AS.opened
},signal:function(AT,AU){if(!AS.closed&&AS.fire){AS.fire(jQuery.stringifyJSON({target:"p",type:AT,data:AU}))
}},close:function(){function AT(AW,AV){var AU=jQuery.inArray(AV,AW);
if(AU>-1){AW.splice(AU,1)
}}if(!AN){AT(AS.callbacks,AQ);
AT(AS.children,Y)
}}}
}};
function AQ(AS){var AU=jQuery.parseJSON(AS),AT=AU.data;
if(AU.target==="c"){switch(AU.type){case"open":b("opening","local",c);
break;
case"close":if(!AN){AN=true;
if(AT.reason==="aborted"){AA()
}else{if(AT.heir===Y){L()
}else{setTimeout(function(){U("","closed",200,c.transport);
AA()
},100)
}}}break;
case"message":U(AT,"messageReceived",200,AO.transport);
break;
case"localMessage":r(AT);
break
}}}function AP(){var AS=new RegExp("(?:^|; )("+encodeURIComponent(AM)+")=([^;]*)").exec(document.cookie);
if(AS){return jQuery.parseJSON(decodeURIComponent(AS[2]))
}}AR=AP();
if(!AR||jQuery.now()-AR.ts>1000){return 
}AL=AK.storage()||AK.windowref();
if(!AL){return 
}return{open:function(){var AS;
Z=setInterval(function(){var AT=AR;
AR=AP();
if(!AR||AT.ts===AR.ts){AQ(jQuery.stringifyJSON({target:"c",type:"close",data:{reason:"error",heir:AT.heir}}))
}},1000);
AS=AL.init();
if(AS){setTimeout(function(){b("opening","local",AO)
},50)
}return AS
},send:function(AS){AL.signal("send",AS)
},localSend:function(AS){AL.signal("localSend",jQuery.stringifyJSON({id:Y,event:AS}))
},close:function(){if(!AH){clearInterval(Z);
AL.signal("close");
AL.close()
}}}
}function s(){var AL,AK="atmosphere-"+c.url,AP={storage:function(){if(!jQuery.atmosphere.supportStorage()){return 
}var AQ=window.localStorage;
return{init:function(){jQuery(window).on("storage.socket",function(AR){AR=AR.originalEvent;
if(AR.key===AK&&AR.newValue){AM(AR.newValue)
}})
},signal:function(AR,AS){AQ.setItem(AK,jQuery.stringifyJSON({target:"c",type:AR,data:AS}))
},get:function(AR){return jQuery.parseJSON(AQ.getItem(AK+"-"+AR))
},set:function(AR,AS){AQ.setItem(AK+"-"+AR,jQuery.stringifyJSON(AS))
},close:function(){jQuery(window).off("storage.socket");
AQ.removeItem(AK);
AQ.removeItem(AK+"-opened");
AQ.removeItem(AK+"-children")
}}
},windowref:function(){var AQ=AK.replace(/\W/g,""),AR=(jQuery('iframe[name="'+AQ+'"]')[0]||jQuery('<iframe name="'+AQ+'" />').hide().appendTo("body")[0]).contentWindow;
return{init:function(){AR.callbacks=[AM];
AR.fire=function(AS){var AT;
for(AT=0;
AT<AR.callbacks.length;
AT++){AR.callbacks[AT](AS)
}}
},signal:function(AS,AT){if(!AR.closed&&AR.fire){AR.fire(jQuery.stringifyJSON({target:"c",type:AS,data:AT}))
}},get:function(AS){return !AR.closed?AR[AS]:null
},set:function(AS,AT){if(!AR.closed){AR[AS]=AT
}},close:function(){}}
}};
function AM(AQ){var AS=jQuery.parseJSON(AQ),AR=AS.data;
if(AS.target==="p"){switch(AS.type){case"send":z(AR);
break;
case"localSend":r(AR);
break;
case"close":AA();
break
}}}o=function AO(AQ){AL.signal("message",AQ)
};
function AN(){document.cookie=encodeURIComponent(AK)+"="+encodeURIComponent(jQuery.stringifyJSON({ts:jQuery.now()+1,heir:(AL.get("children")||[])[0]}))
}AL=AP.storage()||AP.windowref();
AL.init();
if(c.logLevel=="debug"){jQuery.atmosphere.debug("Installed StorageService "+AL)
}AL.set("children",[]);
if(AL.get("opened")!=null&&!AL.get("opened")){AL.set("opened",false)
}AN();
Z=setInterval(AN,1000);
AC=AL
}function b(AM,AP,AL){if(c.shared&&AP!="local"){s()
}if(AC!=null){AC.set("opened",true)
}AL.close=function(){AA();
AL.reconnect=false
};
k.request=AL;
var AN=k.state;
k.state=AM;
k.status=200;
var AK=k.transport;
k.transport=AP;
var AO=k.responseBody;
S();
k.responseBody=AO;
k.state=AN;
k.transport=AK
}function P(AM){AM.transport="jsonp";
var AL=c;
if((AM!=null)&&(typeof (AM)!="undefined")){AL=AM
}var AK=AL.url;
var AN=AL.data;
if(AL.attachHeadersAsQueryString){AK=l(AL);
if(AN!=""){AK+="&X-Atmosphere-Post-Body="+encodeURIComponent(AN)
}AN=""
}V=jQuery.ajax({url:AK,type:AL.method,dataType:"jsonp",error:function(AO,AQ,AP){if(AO.status<300&&AL.requestCount++<AL.maxRequest){f(V,AL)
}else{U(AQ,"error",AO.status,AL.transport)
}},jsonp:"jsonpTransport",success:function(AO){if(AL.requestCount++<AL.maxRequest){u(V,AL);
if(!AL.executeCallbackBeforeReconnect){f(V,AL)
}var AQ=AO.message;
if(AQ!=null&&typeof AQ!="string"){try{AQ=jQuery.stringifyJSON(AQ)
}catch(AP){}}U(AQ,"messageReceived",200,AL.transport);
if(AL.executeCallbackBeforeReconnect){f(V,AL)
}}else{jQuery.atmosphere.log(c.logLevel,["JSONP reconnect maximum try reached "+c.requestCount]);
t()
}},data:AL.data,beforeSend:function(AO){B(AO,AL,false)
}})
}function p(AM){var AL=c;
if((AM!=null)&&(typeof (AM)!="undefined")){AL=AM
}var AK=AL.url;
var AN=AL.data;
if(AL.attachHeadersAsQueryString){AK=l(AL);
if(AN!=""){AK+="&X-Atmosphere-Post-Body="+encodeURIComponent(AN)
}AN=""
}V=jQuery.ajax({url:AK,type:AL.method,error:function(AO,AQ,AP){if(AO.status<300&&AL.requestCount++<AL.maxRequest){f(V,AL)
}else{U(AQ,"error",AO.status,AL.transport)
}},success:function(AP,AQ,AO){if(AL.requestCount++<AL.maxRequest){if(!AL.executeCallbackBeforeReconnect){f(V,AL)
}U(AP,"messageReceived",200,AL.transport);
if(AL.executeCallbackBeforeReconnect){f(V,AL)
}}else{jQuery.atmosphere.log(c.logLevel,["AJAX reconnect maximum try reached "+c.requestCount]);
t()
}},data:AL.data,beforeSend:function(AO){B(AO,AL,false)
}})
}function D(AK){if(c.webSocketImpl!=null){return c.webSocketImpl
}else{if(window.WebSocket){return new WebSocket(AK)
}else{return new MozWebSocket(AK)
}}}function E(){var AK=l(c);
return decodeURI(jQuery('<a href="'+AK+'"/>')[0].href.replace(/^http/,"ws"))
}function AI(){var AK=l(c);
return AK
}function X(AL){k.transport="sse";
var AK=AI(c.url);
if(c.logLevel=="debug"){jQuery.atmosphere.debug("Invoking executeSSE");
jQuery.atmosphere.debug("Using URL: "+AK)
}if(AL){b("re-opening","sse",c)
}if(!c.reconnect){if(H!=null){H.close()
}return 
}H=new EventSource(AK,{withCredentials:c.withCredentials});
if(c.connectTimeout>0){c.id=setTimeout(function(){if(!AL){H.close()
}},c.connectTimeout)
}H.onopen=function(AM){if(c.logLevel=="debug"){jQuery.atmosphere.debug("SSE successfully opened")
}if(!AL){b("opening","sse",c)
}AL=true;
if(c.method=="POST"){k.state="messageReceived";
H.send(c.data)
}};
H.onmessage=function(AN){if(AN.origin!="http://"+window.location.host){jQuery.atmosphere.log(c.logLevel,["Origin was not http://"+window.location.host]);
return 
}k.state="messageReceived";
k.status=200;
var AN=AN.data;
var AM=O(AN,c,k);
if(jQuery.trim(AN).length==0){AM=true
}if(!AM){S();
k.responseBody=""
}};
H.onerror=function(AM){clearTimeout(c.id);
k.state="closed";
k.responseBody="";
k.status=!AL?501:200;
S();
H.close();
if(AH){jQuery.atmosphere.log(c.logLevel,["SSE closed normally"])
}else{if(!AL){e("SSE failed. Downgrading to fallback transport and resending")
}else{if(c.reconnect&&(k.transport=="sse")){c.requestCount=F;
if(F++<c.maxRequest){c.id=setTimeout(function(){X(true)
},c.reconnectInterval);
k.responseBody=""
}else{jQuery.atmosphere.log(c.logLevel,["SSE reconnect maximum try reached "+c.requestCount]);
t()
}}}}}
}function x(AL){k.transport="websocket";
var AK=E(c.url);
var AM=false;
if(c.logLevel=="debug"){jQuery.atmosphere.debug("Invoking executeWebSocket");
jQuery.atmosphere.debug("Using URL: "+AK)
}if(AL){b("re-opening","websocket",c)
}if(!c.reconnect){if(n!=null){n.close()
}return 
}n=D(AK);
if(c.connectTimeout>0){c.id=setTimeout(function(){if(!AL){var AN={code:1002,reason:"",wasClean:false};
n.onclose(AN);
try{n.close()
}catch(AO){}}},c.connectTimeout)
}n.onopen=function(AN){if(c.logLevel=="debug"){jQuery.atmosphere.debug("Websocket successfully opened")
}if(!AL){b("opening","websocket",c)
}AL=true;
if(c.method=="POST"){k.state="messageReceived";
n.send(c.data)
}};
n.onmessage=function(AO){if(AO.data.indexOf("parent.callback")!=-1){jQuery.atmosphere.log(c.logLevel,["parent.callback no longer supported with 0.8 version and up. Please upgrade"])
}k.state="messageReceived";
k.status=200;
var AO=AO.data;
var AN=O(AO,c,k);
if(!AN){S();
k.responseBody=""
}};
n.onerror=function(AN){clearTimeout(c.id)
};
n.onclose=function(AN){if(AM){return 
}var AO=AN.reason;
if(AO===""){switch(AN.code){case 1000:AO="Normal closure; the connection successfully completed whatever purpose for which it was created.";
break;
case 1001:AO="The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection.";
break;
case 1002:AO="The endpoint is terminating the connection due to a protocol error.";
break;
case 1003:AO="The connection is being terminated because the endpoint received data of a type it cannot accept (for example, a text-only endpoint received binary data).";
break;
case 1004:AO="The endpoint is terminating the connection because a data frame was received that is too large.";
break;
case 1005:AO="Unknown: no status code was provided even though one was expected.";
break;
case 1006:AO="Connection was closed abnormally (that is, with no close frame being sent).";
break
}}jQuery.atmosphere.warn("Websocket closed, reason: "+AO);
jQuery.atmosphere.warn("Websocket closed, wasClean: "+AN.wasClean);
k.state="closed";
k.responseBody="";
k.status=!AL?501:200;
S();
clearTimeout(c.id);
AM=true;
if(AH){jQuery.atmosphere.log(c.logLevel,["Websocket closed normally"])
}else{if(!AL){e("Websocket failed. Downgrading to Comet and resending")
}else{if(c.reconnect&&k.transport=="websocket"){if(c.reconnect&&F++<c.maxRequest){c.requestCount=F;
k.responseBody="";
x(true)
}else{jQuery.atmosphere.log(c.logLevel,["Websocket reconnect maximum try reached "+c.requestCount]);
jQuery.atmosphere.warn("Websocket error, reason: "+AN.reason);
t()
}}}}}
}function t(){k.state="error";
k.responseBody="";
k.status=500;
S()
}function O(AO,AN,AK){if(AN.trackMessageLength){if(AK.partialMessage.length!=0){AO=AK.partialMessage+AO
}var AM=[];
var AP=0;
var AL=AO.indexOf(AN.messageDelimiter);
while(AL!=-1){AP=AO.substring(AP,AL);
AO=AO.substring(AL+AN.messageDelimiter.length,AO.length);
if(AO.length==0||AO.length<AP){break
}AL=AO.indexOf(AN.messageDelimiter);
AM.push(AO.substring(0,AP))
}if(AM.length==0||(AL!=-1&&AO.length!=0&&AP!=AO.length)){AK.partialMessage=AP+AN.messageDelimiter+AO
}else{AK.partialMessage=""
}if(AM.length!=0){AK.responseBody=AM.join(AN.messageDelimiter);
return false
}else{return true
}}else{AK.responseBody=AO
}return false
}function e(AK){jQuery.atmosphere.log(c.logLevel,[AK]);
if(typeof (c.onTransportFailure)!="undefined"){c.onTransportFailure(AK,c)
}else{if(typeof (jQuery.atmosphere.onTransportFailure)!="undefined"){jQuery.atmosphere.onTransportFailure(AK,c)
}}c.transport=c.fallbackTransport;
if(c.reconnect&&c.transport!="none"||c.transport==null){c.method=c.fallbackMethod;
k.transport=c.fallbackTransport;
c.id=setTimeout(function(){L()
},c.reconnectInterval)
}}function l(AM){var AL=c;
if((AM!=null)&&(typeof (AM)!="undefined")){AL=AM
}var AK=AL.url;
if(!AL.attachHeadersAsQueryString){return AK
}if(AK.indexOf("X-Atmosphere-Framework")!=-1){return AK
}AK+=(AK.indexOf("?")!=-1)?"&":"?";
AK+="X-Atmosphere-tracking-id="+AL.uuid;
AK+="&X-Atmosphere-Framework="+jQuery.atmosphere.version;
AK+="&X-Atmosphere-Transport="+AL.transport;
if(AL.trackMessageLength){AK+="&X-Atmosphere-TrackMessageSize=true"
}if(AL.lastTimestamp!=undefined){AK+="&X-Cache-Date="+AL.lastTimestamp
}else{AK+="&X-Cache-Date="+0
}if(AL.contentType!=""){AK+="&Content-Type="+AL.contentType
}jQuery.each(AL.headers,function(AN,AP){var AO=jQuery.isFunction(AP)?AP.call(this,AL,AM,k):AP;
if(AO!=null){AK+="&"+encodeURIComponent(AN)+"="+encodeURIComponent(AO)
}});
return AK
}function AE(){var AM;
if(jQuery.browser.msie){var AK=["Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
for(var AL=0;
AL<AK.length;
AL++){try{AM=new ActiveXObject(AK[AL])
}catch(AN){}}}else{if(window.XMLHttpRequest){AM=new XMLHttpRequest()
}}return AM
}function K(AN){var AL=c;
if((AN!=null)||(typeof (AN)!="undefined")){AL=AN
}if((AL.transport=="jsonp")||((AL.enableXDR)&&(jQuery.atmosphere.checkCORSSupport()))){P(AL);
return 
}if(AL.transport=="ajax"){p(AN);
return 
}if((AL.transport=="streaming")&&(jQuery.browser.msie)){AL.enableXDR&&window.XDomainRequest?d(AL):AG(AL);
return 
}if((AL.enableXDR)&&(window.XDomainRequest)){d(AL);
return 
}if(AL.reconnect&&AL.requestCount++<AL.maxRequest){var AM=AE();
B(AM,AL,true);
if(AL.suspend){M=AM
}if(AL.transport!="polling"){k.transport=AL.transport
}var AK=false;
if(!jQuery.browser.msie){AM.onerror=function(){AK=true;
try{k.status=XMLHttpRequest.status
}catch(AO){k.status=404
}k.state="error";
f(AM,AL,true)
}
}AM.onreadystatechange=function(){if(AH){return 
}var AQ=false;
var AP=false;
if(AL.transport=="streaming"&&(AL.readyState>2&&AM.readyState==4)){AL.readyState=0;
AL.lastIndex=0;
f(AM,AL,true);
return 
}AL.readyState=AM.readyState;
if(AM.readyState==4){if(jQuery.browser.msie){AP=true
}else{if(AL.transport=="streaming"){AP=true
}else{if(AL.transport=="long-polling"){AP=true;
clearTimeout(AL.id)
}}}}else{if(!jQuery.browser.msie&&AM.readyState==3&&AM.status==200&&AL.transport!="long-polling"){AP=true
}else{clearTimeout(AL.id)
}}if(AP){var AS=AM.responseText;
u(AM,c);
if(AL.transport=="streaming"){var AV=AS.substring(AL.lastIndex,AS.length);
k.isJunkEnded=true;
if(!k.junkFull&&(AV.indexOf("<!-- Welcome to the Atmosphere Framework.")==-1||AV.indexOf("<!-- EOD -->")==-1)){return 
}k.junkFull=true;
if(AL.lastIndex==0&&AV.indexOf("<!-- Welcome to the Atmosphere Framework.")!=-1&&AV.indexOf("<!-- EOD -->")!=-1){k.isJunkEnded=false
}if(!k.isJunkEnded){var AU="<!-- EOD -->";
var AT=AU.length;
var AO=AV.indexOf(AU)+AT;
if(AO>AT&&AO!=AV.length){k.responseBody=AV.substring(AO);
AQ=O(k.responseBody,AL,k)
}else{AQ=true
}}else{var AW=AS.substring(AL.lastIndex,AS.length);
AQ=O(AW,AL,k)
}AL.lastIndex=AS.length;
if(jQuery.browser.opera){jQuery.atmosphere.iterate(function(){if(AM.responseText.length>AL.lastIndex){try{k.status=AM.status;
k.headers=A(AM.getAllResponseHeaders());
u(AM,c)
}catch(AX){k.status=404
}k.state="messageReceived";
k.responseBody=AM.responseText.substring(AL.lastIndex);
AL.lastIndex=AM.responseText.length;
S();
if((AL.transport=="streaming")&&(AM.responseText.length>AL.maxStreamingLength)){AM.abort();
B(AM,AL,true)
}}},0)
}if(AQ){return 
}}else{AQ=O(AS,AL,k);
AL.lastIndex=AS.length
}try{k.status=AM.status;
k.headers=A(AM.getAllResponseHeaders());
u(AM,AL)
}catch(AR){k.status=404
}if(AL.suspend){k.state=k.status==0?"closed":"messageReceived"
}else{k.state="messagePublished"
}if(!AL.executeCallbackBeforeReconnect){f(AM,AL,false)
}if(k.responseBody.indexOf("parent.callback")!=-1){jQuery.atmosphere.log(AL.logLevel,["parent.callback no longer supported with 0.8 version and up. Please upgrade"])
}S();
if(AL.executeCallbackBeforeReconnect){f(AM,AL,false)
}if((AL.transport=="streaming")&&(AS.length>AL.maxStreamingLength)){AM.abort();
B(AM,AL,true)
}}};
AM.send(AL.data);
if(AL.suspend){AL.id=setTimeout(function(){if(w){AM.abort();
AJ(AL);
L()
}},AL.timeout)
}w=true
}else{if(AL.logLevel=="debug"){jQuery.atmosphere.log(AL.logLevel,["Max re-connection reached."])
}t()
}}function B(AM,AN,AL){var AK=l(AN);
AK=jQuery.atmosphere.prepareURL(AK);
if(AL){AM.open(AN.method,AK,true);
if(AN.connectTimeout>-1){AN.id=setTimeout(function(){if(AN.requestCount==0){AM.abort();
U("Connect timeout","closed",200,AN.transport)
}},AN.connectTimeout)
}}if(c.withCredentials){if("withCredentials" in AM){AM.withCredentials=true
}}if(!c.dropAtmosphereHeaders){AM.setRequestHeader("X-Atmosphere-Framework",jQuery.atmosphere.version);
AM.setRequestHeader("X-Atmosphere-Transport",AN.transport);
if(AN.lastTimestamp!=undefined){AM.setRequestHeader("X-Cache-Date",AN.lastTimestamp)
}else{AM.setRequestHeader("X-Cache-Date",0)
}if(AN.trackMessageLength){AM.setRequestHeader("X-Atmosphere-TrackMessageSize","true")
}if(AN.contentType!=""){AM.setRequestHeader("Content-Type",AN.contentType)
}AM.setRequestHeader("X-Atmosphere-tracking-id",AN.uuid)
}jQuery.each(AN.headers,function(AO,AQ){var AP=jQuery.isFunction(AQ)?AQ.call(this,AM,AN,AL,k):AQ;
if(AP!=null){AM.setRequestHeader(AO,AP)
}})
}function f(AK,AL,AM){if(AM||(AL.suspend&&AK.status==200&&AL.transport!="streaming"&&w)){if(AL.reconnect){b("re-opening",AL.transport,AL);
AL.id=setTimeout(function(){K()
},AL.reconnectInterval)
}}}function d(AK){T=j(AK);
T.open()
}function j(AM){var AL=c;
if((AM!=null)&&(typeof (AM)!="undefined")){AL=AM
}var AQ=AL.transport;
var AP=0;
var AO=function(AS){var AV=AS.responseText;
var AW=false;
if(AV.indexOf("<!-- Welcome to the Atmosphere Framework.")!=-1){AW=true
}if(AW){var AU="<!-- EOD -->";
var AR=AU.length;
var AT=AV.indexOf(AU);
if(AT!==-1){AV=AV.substring(AT+AR+AP);
AP+=AV.length
}}U(AV,"messageReceived",200,AQ)
};
var AK=new window.XDomainRequest();
var AN=AL.rewriteURL||function(AS){var AR=/(?:^|;\s*)(JSESSIONID|PHPSESSID)=([^;]*)/.exec(document.cookie);
switch(AR&&AR[1]){case"JSESSIONID":return AS.replace(/;jsessionid=[^\?]*|(\?)|$/,";jsessionid="+AR[2]+"$1");
case"PHPSESSID":return AS.replace(/\?PHPSESSID=[^&]*&?|\?|$/,"?PHPSESSID="+AR[2]+"&").replace(/&$/,"")
}return AS
};
AK.onprogress=function(){AO(AK);
AL.lastMessage=AK.responseText
};
AK.onerror=function(){if(AL.transport!="polling"){U(AK.responseText,"error",500,AQ)
}};
AK.onload=function(){if(AL.lastMessage==AK.responseText){return 
}if(AL.executeCallbackBeforeReconnect){AO(AK)
}if(AL.transport=="long-polling"&&AL.requestCount++<AL.maxRequest){AK.status=200;
f(AK,AL,false)
}if(!AL.executeCallbackBeforeReconnect){AO(AK)
}AL.lastMessage=AK.responseText
};
return{open:function(){if(AL.method=="POST"){AL.attachHeadersAsQueryString=true
}var AR=l(AL);
if(AL.method=="POST"){AR+="&X-Atmosphere-Post-Body="+encodeURIComponent(AL.data)
}AK.open(AL.method,AN(AR));
AK.send();
if(AL.connectTimeout>-1){AL.id=setTimeout(function(){if(AL.requestCount==0){AK.abort();
U("Connect timeout","closed",200,AL.transport)
}},AL.connectTimeout)
}},close:function(){AK.abort();
U(AK.responseText,"closed",200,AQ)
}}
}function AG(AK){T=N(AK);
T.open()
}function N(AN){var AM=c;
if((AN!=null)&&(typeof (AN)!="undefined")){AM=AN
}var AL;
var AO=new window.ActiveXObject("htmlfile");
AO.open();
AO.close();
var AK=AM.url;
if(AM.transport!="polling"){k.transport=AM.transport
}return{open:function(){var AP=AO.createElement("iframe");
AK=l(AM);
if(AM.data!=""){AK+="&X-Atmosphere-Post-Body="+encodeURIComponent(AM.data)
}AK=jQuery.atmosphere.prepareURL(AK);
AP.src=AK;
AO.body.appendChild(AP);
var AQ=AP.contentDocument||AP.contentWindow.document;
AL=jQuery.atmosphere.iterate(function(){try{if(!AQ.firstChild){return 
}if(AQ.readyState==="complete"){try{jQuery.noop(AQ.fileSize)
}catch(AW){U("Connection Failure","error",500,AM.transport);
return false
}}var AT=AQ.body?AQ.body.lastChild:AQ;
var AV=function(){var Ac=AT.cloneNode(true);
Ac.appendChild(AQ.createTextNode("."));
var Aa=Ac.innerText;
var Ab=true;
if(Aa.indexOf("<!-- Welcome to the Atmosphere Framework.")==-1){Ab=false
}if(Ab){var AZ="<!-- EOD -->";
var AX=AZ.length;
var AY=Aa.indexOf(AZ)+AX;
Aa=Aa.substring(AY)
}return Aa.substring(0,Aa.length-1)
};
if(!jQuery.nodeName(AT,"pre")){var AS=AQ.head||AQ.getElementsByTagName("head")[0]||AQ.documentElement||AQ;
var AR=AQ.createElement("script");
AR.text="document.write('<plaintext>')";
AS.insertBefore(AR,AS.firstChild);
AS.removeChild(AR);
AT=AQ.body.lastChild
}U(AV(),"opening",200,AM.transport);
AL=jQuery.atmosphere.iterate(function(){var AX=AV();
if(AX.length>AM.lastIndex){k.status=200;
AT.innerText="";
U(AX,"messageReceived",200,AM.transport);
AM.lastIndex=0
}if(AQ.readyState==="complete"){U("","re-opening",200,AM.transport);
AG(AM);
return false
}},null);
return false
}catch(AU){jQuery.atmosphere.error(AU)
}})
},close:function(){if(AL){AL()
}AO.execCommand("Stop");
U("","closed",200,AM.transport)
}}
}function z(AK){if(J!=null){G(AK)
}else{if(M!=null||H!=null){C(AK)
}else{if(T!=null){m(AK)
}else{if(V!=null){i(AK)
}else{if(n!=null){W(AK)
}}}}}}function G(AK){J.send(AK)
}function R(AL){if(AL.length==0){return 
}try{if(J){J.localSend(AL)
}else{AC.signal("localMessage",jQuery.stringifyJSON({id:Y,event:AL}))
}}catch(AK){jQuery.atmosphere.error(AK)
}}function C(AL){var AK=AB(AL);
K(AK)
}function m(AL){if(c.enableXDR&&jQuery.atmosphere.checkCORSSupport()){var AK=AB(AL);
AK.reconnect=false;
P(AK)
}else{C(AL)
}}function i(AK){C(AK)
}function h(AK){var AL=AK;
if(typeof (AL)=="object"){AL=AK.data
}return AL
}function AB(AL){var AM=h(AL);
var AK={connected:false,timeout:60000,method:"POST",url:c.url,contentType:c.contentType,headers:{},reconnect:true,callback:null,data:AM,suspend:false,maxRequest:60,logLevel:"info",requestCount:0,transport:"polling",attachHeadersAsQueryString:true,enableXDR:c.enableXDR,uuid:c.uuid};
if(typeof (AL)=="object"){AK=jQuery.extend(AK,AL)
}return AK
}function W(AK){var AN=h(AK);
var AL;
try{if(c.webSocketUrl!=null){AL=c.webSocketPathDelimiter+c.webSocketUrl+c.webSocketPathDelimiter+AN
}else{AL=AN
}n.send(AL)
}catch(AM){n.onclose=function(AO){};
n.close();
e("Websocket failed. Downgrading to Comet and resending "+AL);
C(AK)
}}function r(AL){var AK=jQuery.parseJSON(AL);
if(AK.id!=Y){if(typeof (c.onLocalMessage)!="undefined"){c.onLocalMessage(AK.event)
}else{if(typeof (jQuery.atmosphere.onLocalMessage)!="undefined"){jQuery.atmosphere.onLocalMessage(AK.event)
}}}}function U(AN,AK,AL,AM){if(AK=="messageReceived"){if(O(AN,c,k)){return 
}}k.transport=AM;
k.status=AL;
k.state=AK;
S()
}function u(AK,AM){if(!AM.readResponsesHeaders){return 
}try{var AL=AK.getResponseHeader("X-Cache-Date");
if(AL!=null||AL!=undefined){AM.lastTimestamp=AL.split(" ").pop()
}tempUUID=AK.getResponseHeader("X-Atmosphere-tracking-id");
if(tempUUID!=null||tempUUID!=undefined){AM.uuid=tempUUID.split(" ").pop()
}if(AM.headers){jQuery.each(c.headers,function(AP){var AO=AK.getResponseHeader(AP);
if(AO){k.headers[AP]=AO
}})
}}catch(AN){}}function q(AK){AF(AK,c);
AF(AK,jQuery.atmosphere)
}function AF(AK,AL){switch(AK.state){case"messageReceived":if(typeof (AL.onMessage)!="undefined"){AL.onMessage(AK)
}break;
case"error":if(typeof (AL.onError)!="undefined"){AL.onError(AK)
}break;
case"opening":if(typeof (AL.onOpen)!="undefined"){AL.onOpen(AK)
}break;
case"messagePublished":if(typeof (AL.onMessagePublished)!="undefined"){AL.onMessagePublished(AK)
}break;
case"re-opening":if(typeof (AL.onReconnect)!="undefined"){AL.onReconnect(c,AK)
}break;
case"unsubscribe":case"closed":if(typeof (AL.onClose)!="undefined"){AL.onClose(AK)
}break
}}function S(){var AN=function(AQ,AR){AR(k)
};
if(J==null&&o!=null){o(k.responseBody)
}var AO=typeof (k.responseBody)=="string"?k.responseBody.split(c.messageDelimiter):new Array(k.responseBody);
for(var AL=0;
AL<AO.length;
AL++){if(AO.length>1&&AO[AL].length==0){continue
}k.responseBody=jQuery.trim(AO[AL]);
if(k.responseBody.length==0&&k.transport=="streaming"&&k.state=="messageReceived"){var AK=navigator.userAgent.toLowerCase();
var AM=AK.indexOf("android")>-1;
if(AM){continue
}}q(k);
if(jQuery.atmosphere.callbacks.length>0){if(c.logLevel=="debug"){jQuery.atmosphere.debug("Invoking "+jQuery.atmosphere.callbacks.length+" global callbacks: "+k.state)
}try{jQuery.each(jQuery.atmosphere.callbacks,AN)
}catch(AP){jQuery.atmosphere.log(c.logLevel,["Callback exception"+AP])
}}if(typeof (c.callback)=="function"){if(c.logLevel=="debug"){jQuery.atmosphere.debug("Invoking request callbacks")
}try{c.callback(k)
}catch(AP){jQuery.atmosphere.log(c.logLevel,["Callback exception"+AP])
}}}}function AA(){c.reconnect=false;
k.request=c;
w=false;
AH=true;
k.state="unsubscribe";
k.responseBody="";
k.status=408;
S();
y();
if(AC!=null){clearInterval(Z);
document.cookie=encodeURIComponent("atmosphere-"+c.url)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
AC.signal("close",{reason:"",heir:!AH?Y:(AC.get("children")||[])[0]});
AC.close()
}if(J!=null){J.close()
}}function y(){if(T!=null){T.close();
T=null
}if(V!=null){V.abort();
V=null
}if(M!=null){M.abort();
M=null
}if(n!=null){n.close();
n=null
}if(H!=null){H.close();
H=null
}}this.subscribe=function(AK){AJ(AK);
L()
};
this.execute=function(){L()
};
this.invokeCallback=function(){S()
};
this.close=function(){AA()
};
this.getUrl=function(){return c.url
};
this.push=function(AK){z(AK)
};
this.pushLocal=function(AK){R(AK)
};
this.response=k
},subscribe:function(B,E,D){if(typeof (E)=="function"){jQuery.atmosphere.addCallback(E)
}if(typeof (B)!="string"){D=B
}else{D.url=B
}var C=new jQuery.atmosphere.AtmosphereRequest(D);
C.execute();
jQuery.atmosphere.requests[jQuery.atmosphere.requests.length]=C;
return C
},addCallback:function(B){if(jQuery.inArray(B,jQuery.atmosphere.callbacks)==-1){jQuery.atmosphere.callbacks.push(B)
}},removeCallback:function(C){var B=jQuery.inArray(C,jQuery.atmosphere.callbacks);
if(B!=-1){jQuery.atmosphere.callbacks.splice(B,1)
}},unsubscribe:function(){if(jQuery.atmosphere.requests.length>0){for(var B=0;
B<jQuery.atmosphere.requests.length;
B++){jQuery.atmosphere.requests[B].close();
clearTimeout(jQuery.atmosphere.requests[B].id)
}}jQuery.atmosphere.requests=[];
jQuery.atmosphere.callbacks=[]
},unsubscribeUrl:function(C){var B=-1;
if(jQuery.atmosphere.requests.length>0){for(var E=0;
E<jQuery.atmosphere.requests.length;
E++){var D=jQuery.atmosphere.requests[E];
if(D.getUrl()==C){D.close();
clearTimeout(D.id);
B=E;
break
}}}if(B>=0){jQuery.atmosphere.requests.splice(B,1)
}},publish:function(C){if(typeof (C.callback)=="function"){jQuery.atmosphere.addCallback(callback)
}C.transport="polling";
var B=new jQuery.atmosphere.AtmosphereRequest(C);
jQuery.atmosphere.requests[jQuery.atmosphere.requests.length]=B;
return B
},checkCORSSupport:function(){if(jQuery.browser.msie&&!window.XDomainRequest){return true
}else{if(jQuery.browser.opera&&jQuery.browser.version<12){return true
}}var B=navigator.userAgent.toLowerCase();
var C=B.indexOf("android")>-1;
if(C){return true
}return false
},S4:function(){return(((1+Math.random())*65536)|0).toString(16).substring(1)
},guid:function(){return(jQuery.atmosphere.S4()+jQuery.atmosphere.S4()+"-"+jQuery.atmosphere.S4()+"-"+jQuery.atmosphere.S4()+"-"+jQuery.atmosphere.S4()+"-"+jQuery.atmosphere.S4()+jQuery.atmosphere.S4()+jQuery.atmosphere.S4())
},prepareURL:function(C){var D=jQuery.now();
var B=C.replace(/([?&])_=[^&]*/,"$1_="+D);
return B+(B===C?(/\?/.test(C)?"&":"?")+"_="+D:"")
},param:function(B){return jQuery.param(B,jQuery.ajaxSettings.traditional)
},supportStorage:function(){var C=window.localStorage;
if(C){try{C.setItem("t","t");
C.removeItem("t");
return window.StorageEvent&&!jQuery.browser.msie&&!(jQuery.browser.mozilla&&jQuery.browser.version.split(".")[0]==="1")
}catch(B){}}return false
},iterate:function(D,C){var E;
C=C||0;
(function B(){E=setTimeout(function(){if(D()===false){return 
}B()
},C)
})();
return function(){clearTimeout(E)
}
},log:function(D,C){if(window.console){var B=window.console[D];
if(typeof B=="function"){B.apply(window.console,C)
}}},warn:function(){jQuery.atmosphere.log("warn",arguments)
},info:function(){jQuery.atmosphere.log("info",arguments)
},debug:function(){jQuery.atmosphere.log("debug",arguments)
},error:function(){jQuery.atmosphere.log("error",arguments)
}}
}();
(function(D){var F=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,C={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};
function A(G){return'"'+G.replace(F,function(H){var I=C[H];
return typeof I==="string"?I:"\\u"+("0000"+H.charCodeAt(0).toString(16)).slice(-4)
})+'"'
}function B(G){return G<10?"0"+G:G
}function E(L,K){var J,I,G,H,N=K[L],M=typeof N;
if(N&&typeof N==="object"&&typeof N.toJSON==="function"){N=N.toJSON(L);
M=typeof N
}switch(M){case"string":return A(N);
case"number":return isFinite(N)?String(N):"null";
case"boolean":return String(N);
case"object":if(!N){return"null"
}switch(Object.prototype.toString.call(N)){case"[object Date]":return isFinite(N.valueOf())?'"'+N.getUTCFullYear()+"-"+B(N.getUTCMonth()+1)+"-"+B(N.getUTCDate())+"T"+B(N.getUTCHours())+":"+B(N.getUTCMinutes())+":"+B(N.getUTCSeconds())+'Z"':"null";
case"[object Array]":G=N.length;
H=[];
for(J=0;
J<G;
J++){H.push(E(J,N)||"null")
}return"["+H.join(",")+"]";
default:H=[];
for(J in N){if(Object.prototype.hasOwnProperty.call(N,J)){I=E(J,N);
if(I){H.push(A(J)+":"+I)
}}}return"{"+H.join(",")+"}"
}}}D.stringifyJSON=function(G){if(window.JSON&&window.JSON.stringify){return window.JSON.stringify(G)
}return E("",{"":G})
}
}(jQuery));
New to GrepCode? Check out our FAQ X