-
Notifications
You must be signed in to change notification settings - Fork 34
/
portal.min.js
40 lines (40 loc) · 19.6 KB
/
portal.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* Portal v1.1.1 | http://flowersinthesand.github.io/portal/ | (c) 2011-2014, Donghwan Kim | http://www.apache.org/licenses/LICENSE-2.0 */
(function(l,w){"function"===typeof define&&define.amd?define(function(){return w(l)}):"object"===typeof exports?(module.exports=w(function(){var l=require("jsdom").jsdom().createWindow();l.WebSocket=require("ws");l.EventSource=require("eventsource");return l}()),module.exports.support.corsable=!0):l.portal=w(l)})(this,function(l){function w(a){var c,b,g,d,h,f,e=[],k=function(k,p){p=p||[];b=!a||[k,p];g=!0;f=d||0;d=0;for(h=e.length;f<h&&!c;f++)e[f].apply(k,p);g=!1};return{add:function(a){var f=e.length;
e.push(a);g?h=e.length:!c&&b&&!0!==b&&(d=f,k(b[0],b[1]))},remove:function(a){var b;for(b=0;b<e.length;b++)if(a===e[b]||a.guid&&a.guid===e[b].guid)g&&b<=h&&(h--,b<=f&&f--),e.splice(b--,1)},fire:function(e,f){c||g||a&&b||k(e,f)},lock:function(){c=!0},locked:function(){return!!c},unlock:function(){c=b=g=d=h=f=void 0}}}function G(a,c){var b,g,d,h,f,r,k={},x=0,p={},s=[],n={},y=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/.exec(a.toLowerCase()),m={option:function(a){return b[a]},data:function(a,b){if(void 0===
b)return n[a];n[a]=b;return this},state:function(){return d},on:function(a,b){var c;if("object"===typeof a){for(c in a)m.on(c,a[c]);return this}c=k[a];if(!c){if(k.message.locked())return this;c=k[a]=w();c.order=k.message.order}c.add(b);return this},off:function(a,b){var c=k[a];c&&c.remove(b);return this},one:function(a,b){function c(){m.off(a,c);b.apply(m,arguments)}b.guid=b.guid||z++;c.guid=b.guid;return m.on(a,c)},fire:function(a){var b=k[a];b&&b.fire(m,D.call(arguments,1));return this},open:function(){var a,
c,e=function(){var a,e;if(!c){c=!0;for(a=n.candidates=D.call(b.transports);!g&&a.length;)e=a.shift(),n.transport=e,n.url=m.buildURL("open"),g=u[e](m,b);r&&r++;g?(m.fire("connecting"),g.open()):m.fire("close","notransport")}},f=function(){c||(c=!0,m.fire("close","canceled"))};h&&clearTimeout(h);n={};for(a in k)k[a].unlock();g=void 0;d="preparing";b.sharing&&(n.transport="session",g=u.session(m,b));g?e():b.prepare.call(m,e,f,b);return this},send:function(a,c,f,k){var h;if("opened"!==d)return s.push(arguments),
this;h={id:++x,socket:b.id,type:a,data:c,reply:!(!f&&!k)};h.reply&&("session"===n.transport?(h.doneCallback=f,h.failCallback=k):p[x]={done:f,fail:k});g.send(e.isBinary(c)?c:b.outbound.call(m,h));return this},close:function(){var a,c;b.reconnect=!1;h&&clearTimeout(h);!A&&g&&g.feedback||(m.fire("close",A?"error":"aborted"),b.notifyAbort&&"session"!==n.transport&&(c=q.head||q.getElementsByTagName("head")[0]||q.documentElement,a=q.createElement("script"),a.async=!1,a.src=m.buildURL("abort"),a.onload=
a.onreadystatechange=function(){if(!a.readyState||/loaded|complete/.test(a.readyState))a.onload=a.onreadystatechange=null,a.parentNode&&a.parentNode.removeChild(a)},c.insertBefore(a,c.firstChild)));g&&g.close();return this},broadcast:function(a,b){var c=n.broadcastable;c&&c.broadcast({type:"fire",data:{type:a,data:b}});return this},_fire:function(a,c){var f;if(c){for(a=b.streamParser.call(m,a);a.length;)m._fire(a.shift());return this}e.isBinary(a)?f=[{type:"message",data:a}]:(f=b.inbound.call(m,a),
f=null==f?[]:e.isArray(f)?f:[f]);n.lastEventIds=[];e.each(f,function(a,c){var f,e=[c.type,c.data];b.lastEventId=c.id;n.lastEventIds.push(c.id);c.reply&&e.push(function(a){f||(f=!0,m.send("reply",{id:c.id,data:a}))});m.fire.apply(m,e).fire("_message",e)});return this},buildURL:function(c,f){var h="open"===c?{transport:n.transport,heartbeat:b.heartbeat,lastEventId:b.lastEventId}:"poll"===c?{transport:n.transport,lastEventIds:n.lastEventIds&&n.lastEventIds.join(","),lastEventId:b.lastEventId}:{};e.extend(h,
{id:b.id,_:z++},b.params&&b.params[c],f);return b.urlBuilder.call(m,a,h,c)}};b=e.extend({},E,c);c&&c.transports&&(b.transports=D.call(c.transports));b.url=a;b.id=b.idGenerator.call(m);b.crossDomain=!(!y||y[1]==C.protocol&&y[2]==C.hostname&&(y[3]||("http:"===y[1]?80:443))==(C.port||("http:"===C.protocol?80:443)));e.each(["connecting","open","message","close","waiting"],function(a,b){k[b]=w("message"!==b);k[b].order=a;var c=m[b],f=function(a){return m.on(b,a)};m[b]=c?function(a){return(e.isFunction(a)?
f:c).apply(this,arguments)}:f});m.on({connecting:function(){function c(){k=setTimeout(function(){g.close();m.fire("close","timeout")},b.timeout)}function f(){clearTimeout(k)}function h(){function c(a){a=e.parseJSON(a);var b=a.data;if(!a.target)"fire"===a.type&&m.fire(b.type,b.data);else if("p"===a.target)switch(a.type){case "send":m.send(b.type,b.data,b.doneCallback,b.failCallback);break;case "close":m.close()}}function f(a){d.broadcast({target:"c",type:"message",data:a})}function k(){q.cookie=encodeURIComponent(p)+
"="+encodeURIComponent(e.stringifyJSON({ts:e.now(),heir:(d.get("children")||[])[0]}))+"; path=/"}var g,d,p="socket-"+a,r={storage:function(){if(!e.browser.msie){var a=l.localStorage;return{init:function(){function b(a){a.key===p&&a.newValue&&c(a.newValue)}e.on(l,"storage",b);m.one("close",function(){e.off(l,"storage",b);m.one("close",function(){a.removeItem(p);a.removeItem(p+"-opened");a.removeItem(p+"-children")})})},broadcast:function(b){var f=e.stringifyJSON(b);a.setItem(p,f);setTimeout(function(){c(f)},
50)},get:function(b){return e.parseJSON(a.getItem(p+"-"+b))},set:function(b,c){a.setItem(p+"-"+b,e.stringifyJSON(c))}}}},windowref:function(){var a=p.replace(/\W/g,""),b=q.getElementById(a),f;b||(b=q.createElement("div"),b.id=a,b.style.display="none",b.innerHTML='<iframe name="'+a+'" />',q.body.appendChild(b));f=b.firstChild.contentWindow;return{init:function(){f.callbacks=[c];f.fire=function(a){var b;for(b=0;b<f.callbacks.length;b++)f.callbacks[b](a)}},broadcast:function(a){!f.closed&&f.fire&&f.fire(e.stringifyJSON(a))},
get:function(a){return f.closed?null:f[a]},set:function(a,b){f.closed||(f[a]=b)}}}};d=r.storage()||r.windowref();d.init();n.broadcastable=d;d.set("children",[]);d.set("opened",!1);k();g=setInterval(k,1E3);m.on("_message",f).one("open",function(){d.set("opened",!0);d.broadcast({target:"c",type:"open"})}).one("close",function(a){clearInterval(g);q.cookie=encodeURIComponent(p)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";d.broadcast({target:"c",type:"close",data:{reason:a,heir:A?(d.get("children")||
[])[0]:b.id}});m.off("_message",f)})}d="connecting";var k;0<b.timeout&&(c(),m.one("open",f).one("close",f));b.sharing&&"session"!==n.transport&&h()},open:function(){function a(){e=setTimeout(function(){m.send("heartbeat").one("heartbeat",function(){c();a()});e=setTimeout(function(){g.close();m.fire("close","error")},b._heartbeat)},b.heartbeat-b._heartbeat)}function c(){clearTimeout(e)}d="opened";var e;b.heartbeat>b._heartbeat&&(a(),m.one("close",c));k.connecting.lock();for(h=f=r=null;s.length;)m.send.apply(m,
s.shift())},close:function(){d="closed";var a,c,e=k.close.order;for(a in k)c=k[a],c.order<e&&c.lock();if(b.reconnect)m.one("close",function(){r=r||1;f=b.reconnect.call(m,f,r);!1!==f&&(h=setTimeout(function(){m.open()},f),m.fire("waiting",f,r))})},waiting:function(){d="waiting"},reply:function(a){var b=a.id,c=a.data;a=a.exception;var f=p[b];f&&(a=a?f.fail:f.done)&&(e.isFunction(a)?a.call(m,c):m.fire(a,c).fire("_message",[a,c]),delete p[b])}});return m.open()}var z,A,v,e,E,u,t={},F=[],B=Object.prototype.toString,
H=Object.prototype.hasOwnProperty,D=Array.prototype.slice,q=l.document,C=l.location;v={open:function(a,c){a=e.getAbsoluteURL(a);t[a]=G(a,c);return v.find(a)},find:function(a){var c;if(!arguments.length){for(c in t)if(t[c])return t[c];return null}return t[e.getAbsoluteURL(a)]||null},finalize:function(){var a,c;for(a in t)c=t[a],"closed"!==c.state()&&c.close(),delete t[a]}};v.support=e={now:function(){return(new Date).getTime()},isArray:function(a){return"[object Array]"===B.call(a)},isBinary:function(a){return/^\[object\s(?:Blob|ArrayBuffer|.+Array)\]$/.test(B.call(a))},
isFunction:function(a){return"[object Function]"===B.call(a)},getAbsoluteURL:function(a){var c=q.createElement("div");c.innerHTML='<a href="'+a+'"/>';return encodeURI(decodeURI(c.firstChild.href))},each:function(a,c){var b;for(b=0;b<a.length;b++)c(b,a[b])},extend:function(a){var c,b,e;for(c=1;c<arguments.length;c++)if(null!=(b=arguments[c]))for(e in b)a[e]=b[e];return a},on:function(a,c,b){a.addEventListener?a.addEventListener(c,b,!1):a.attachEvent&&a.attachEvent("on"+c,b)},off:function(a,c,b){a.removeEventListener?
a.removeEventListener(c,b,!1):a.detachEvent&&a.detachEvent("on"+c,b)},param:function(a){function c(a,b){b=e.isFunction(b)?b():null==b?"":b;d.push(encodeURIComponent(a)+"="+encodeURIComponent(b))}function b(a,f){var d;if(e.isArray(f))e.each(f,function(f,e){/\[\]$/.test(a)?c(a,e):b(a+"["+("object"===typeof e?f:"")+"]",e)});else if(null!=f&&"[object Object]"===B.call(f))for(d in f)b(a+"["+d+"]",f[d]);else c(a,f)}var g,d=[];for(g in a)b(g,a[g]);return d.join("&").replace(/%20/g,"+")},xhr:function(){try{return new l.XMLHttpRequest}catch(a){try{return new l.ActiveXObject("Microsoft.XMLHTTP")}catch(c){}}},
parseJSON:function(a){return a?l.JSON&&l.JSON.parse?l.JSON.parse(a):Function("return "+a)():null},stringifyJSON:function(a){function c(a){return'"'+a.replace(e,function(a){var b=d[a];return"string"===typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"'}function b(a){return 10>a?"0"+a:a}var e=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,d={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',
"\\":"\\\\"};return l.JSON&&l.JSON.stringify?l.JSON.stringify(a):function f(a,e){var d,g,s,n=e[a];s=typeof n;n&&"object"===typeof n&&"function"===typeof n.toJSON&&(n=n.toJSON(a),s=typeof n);switch(s){case "string":return c(n);case "number":return isFinite(n)?String(n):"null";case "boolean":return String(n);case "object":if(!n)return"null";switch(B.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;s=[];for(d=0;d<g;d++)s.push(f(d,n)||"null");return"["+s.join(",")+"]";default:s=[];for(d in n)H.call(n,d)&&(g=f(d,n))&&s.push(c(d)+":"+g);return"{"+s.join(",")+"}"}}}("",{"":a})},storage:!(!l.localStorage||!l.StorageEvent)};z=e.now();e.corsable="withCredentials"in e.xhr();e.on(l,"unload",function(){A=!0;v.finalize()});e.on(l,"online",function(){var a,c;for(a in t)c=t[a],"waiting"===c.state()&&c.open()});
e.on(l,"offline",function(){var a,c;for(a in t)c=t[a],"opened"===c.state()&&c.fire("close","error")});(function(a){var c={};a=/(msie) ([\w.]+)/.exec(a)||/(trident)(?:.*? rv:([\w.]+)|)/.exec(a)||[];c[a[1]||""]=!0;c.version=a[2]||"0";c.trident&&(c.msie=!0);e.browser=c})(l.navigator.userAgent.toLowerCase());v.defaults=E={transports:["ws","sse","stream","longpoll"],timeout:!1,heartbeat:!1,_heartbeat:5E3,lastEventId:0,sharing:!1,prepare:function(a){a()},reconnect:function(a){return 2*(a||250)},idGenerator:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,
function(a){var c=16*Math.random()|0;return("x"===a?c:c&3|8).toString(16)})},urlBuilder:function(a,c,b){return a+(/\?/.test(a)?"&":"?")+"when="+b+"&"+e.param(c)},inbound:e.parseJSON,outbound:e.stringifyJSON,credentials:!1,notifyAbort:!1,xdrURL:function(a){var c=/(?:^|; )(JSESSIONID|PHPSESSID)=([^;]*)/.exec(q.cookie);switch(c&&c[1]){case "JSESSIONID":return a.replace(/;jsessionid=[^\?]*|(\?)|$/,";jsessionid="+c[2]+"$1");case "PHPSESSID":return a.replace(/\?PHPSESSID=[^&]*&?|\?|$/,"?PHPSESSID="+c[2]+
"&").replace(/&$/,"");default:return!1}},streamParser:function(a){var c,b=/\r\n|[\r\n]/g,e=[],d=this.data("data"),h=[],f=0;for(a=a.replace(/^\s+/g,"");c=b.exec(a);)e.push(a.substring(f,c.index)),f=c.index+c[0].length;e.push(a.length===f?"":a.substring(f));d||(d=[],this.data("data",d));for(f=0;f<e.length;f++)(a=e[f])?/^data:\s/.test(a)?d.push(a.substring(6)):d[d.length-1]+=a:(h.push(d.join("\n")),d=[],this.data("data",d));return h}};v.transports=u={session:function(a,c){function b(a,b){var c,f=a.length;
for(c=0;c<f;c++)a[c]===b&&a.splice(c,1);return f!==a.length}function g(b){b=e.parseJSON(b);var d=b.data;if(!b.target)"fire"===b.type&&a.fire(d.type,d.data);else if("c"===b.target)switch(b.type){case "open":a.fire("open");break;case "close":f||(f=!0,"aborted"===d.reason?a.close():d.heir===c.id?a.fire("close",d.reason):setTimeout(function(){a.fire("close",d.reason)},100));break;case "message":if("connecting"===a.state())a.one("open",function(){a.fire.apply(a,d)});else a.fire.apply(a,d)}}function d(){var a=
RegExp("(?:^|; )("+encodeURIComponent(k)+")=([^;]*)").exec(q.cookie);if(a)return e.parseJSON(decodeURIComponent(a[2]))}var h,f,r,k="socket-"+c.url,x={storage:function(){function f(a){return e.parseJSON(h.getItem(k+"-"+a))}function d(a,b){h.setItem(k+"-"+a,e.stringifyJSON(b))}if(!e.browser.msie){var h=l.localStorage;return{init:function(){function h(a){a.key===k&&a.newValue&&g(a.newValue)}d("children",f("children").concat([c.id]));e.on(l,"storage",h);a.one("close",function(){var a=f("children");e.off(l,
"storage",h);a&&b(a,c.id)&&d("children",a)});return f("opened")},broadcast:function(a){var b=e.stringifyJSON(a);h.setItem(k,b);setTimeout(function(){g(b)},50)}}}},windowref:function(){var d=l.open("",k.replace(/\W/g,""));if(d&&!d.closed&&d.callbacks)return{init:function(){d.callbacks.push(g);d.children.push(c.id);a.one("close",function(){f||(b(d.callbacks,g),b(d.children,c.id))});return d.opened},broadcast:function(a){!d.closed&&d.fire&&d.fire(e.stringifyJSON(a))}}}};if((h=d())&&!(1E3<e.now()-h.ts)&&
(r=x.storage()||x.windowref()))return a.data("broadcastable",r),{open:function(){var b,f=c.timeout,k=c.heartbeat,l=c.outbound;c.timeout=c.heartbeat=!1;c.outbound=function(a){return a};b=setInterval(function(){var a=h;(h=d())&&a.ts!==h.ts||g(e.stringifyJSON({target:"c",type:"close",data:{reason:"error",heir:a.heir}}))},1E3);a.one("close",function(){clearInterval(b);c.timeout=f;c.heartbeat=k;c.outbound=l});r.init()&&setTimeout(function(){a.fire("open")},50)},send:function(a){r.broadcast({target:"p",
type:"send",data:a})},close:function(){A||r.broadcast({target:"p",type:"close"})}}},ws:function(a){var c,b,g=l.WebSocket;if(g)return{feedback:!0,open:function(){var d=e.getAbsoluteURL(a.data("url")).replace(/^http/,"ws");a.data("url",d);c=new g(d);c.onopen=function(b){a.data("event",b).fire("open")};c.onmessage=function(b){a.data("event",b)._fire(b.data)};c.onerror=function(c){a.data("event",c).fire("close",b?"aborted":"error")};c.onclose=function(c){a.data("event",c).fire("close",b?"aborted":c.wasClean?
"done":"error")}},send:function(a){c.send(a)},close:function(){b=!0;c.close()}}},httpbase:function(a,c){function b(){h.length?g(c.url,h.shift()):d=!1}var g,d,h=[];g=!c.crossDomain||e.corsable?function(a,d){var k=e.xhr();k.onreadystatechange=function(){4===k.readyState&&b()};k.open("POST",a);k.setRequestHeader("Content-Type","text/plain; charset=UTF-8");e.corsable&&(k.withCredentials=c.credentials);k.send("data="+d)}:l.XDomainRequest&&c.xdrURL&&c.xdrURL.call(a,"t")?function(f,d){var e=new l.XDomainRequest;
e.onload=e.onerror=b;e.open("POST",c.xdrURL.call(a,f));e.send("data="+d)}:function(a,c){var d=q.createElement("form");d.action=a;d.target="socket-"+ ++z;d.method="POST";d.enctype=d.encoding="text/plain";d.acceptCharset="UTF-8";d.style.display="none";d.innerHTML='<textarea name="data"></textarea><iframe name="'+d.target+'"></iframe>';d.firstChild.value=c;e.on(d.lastChild,"load",function(){q.body.removeChild(d);b()});q.body.appendChild(d);d.submit()};return{send:function(a){h.push(a);d||(d=!0,b())}}},
sse:function(a,c){var b,g=l.EventSource;if(g)return e.extend(u.httpbase(a,c),{open:function(){var d=a.data("url");b=new g(d,{withCredentials:c.credentials});b.onopen=function(b){a.data("event",b).fire("open")};b.onmessage=function(b){a.data("event",b)._fire(b.data)};b.onerror=function(c){b.close();a.data("event",c).fire("close","done")}},close:function(){b.close()}})},stream:function(a){a.data("candidates").unshift("streamxhr","streamxdr","streamiframe")},streamxhr:function(a,c){var b;if(!(e.browser.msie&&
10>+e.browser.version.split(".")[0]||c.crossDomain&&!e.corsable))return e.extend(u.httpbase(a,c),{open:function(){b=e.xhr();b.onreadystatechange=function(){if(3===b.readyState&&200===b.status){var c=a.data("index"),d=b.responseText.length;c?d>c&&a._fire(b.responseText.substring(c,d),!0):a.fire("open")._fire(b.responseText,!0);a.data("index",d)}else 4===b.readyState&&a.fire("close",200===b.status?"done":"error")};b.open("GET",a.data("url"));e.corsable&&(b.withCredentials=c.credentials);b.send(null)},
close:function(){b.abort()}})},streamiframe:function(a,c){var b,g,d=l.ActiveXObject;if(d&&!c.crossDomain){try{new d("htmlfile")}catch(h){return}return e.extend(u.httpbase(a,c),{open:function(){function c(a){var b;(function n(){b=setTimeout(function(){!1!==a()&&n()},1)})();return function(){clearTimeout(b)}}var e,k;b=new d("htmlfile");b.open();b.close();e=b.createElement("iframe");e.src=a.data("url");b.body.appendChild(e);k=e.contentDocument||e.contentWindow.document;g=c(function(){function b(){var a;
a=d.cloneNode(!0);a.appendChild(k.createTextNode("."));a=a.innerText;return a.substring(0,a.length-1)}var d;if(k.firstChild){d=k.body.lastChild;if(!d)return a.fire("close","error"),!1;a.fire("open")._fire(b(),!0);d.innerText="";g=c(function(){var c=b();c&&(d.innerText="",a._fire(c,!0));if("complete"===k.readyState)return a.fire("close","done"),!1});return!1}})},close:function(){g();b.execCommand("Stop")}})}},streamxdr:function(a,c){var b,g=l.XDomainRequest;if(g&&c.xdrURL&&c.xdrURL.call(a,"t"))return e.extend(u.httpbase(a,
c),{open:function(){var d=c.xdrURL.call(a,a.data("url"));a.data("url",d);b=new g;b.onprogress=function(){var c=a.data("index"),d=b.responseText.length;c?a._fire(b.responseText.substring(c,d),!0):a.fire("open")._fire(b.responseText,!0);a.data("index",d)};b.onerror=function(){a.fire("close","error")};b.onload=function(){a.fire("close","done")};b.open("GET",d);b.send()},close:function(){b.abort()}})},longpoll:function(a){a.data("candidates").unshift("longpollajax","longpollxdr","longpolljsonp")},longpollajax:function(a,
c){var b,g,d=0;if(!c.crossDomain||e.corsable)return e.extend(u.httpbase(a,c),{open:function(){function h(){var f=a.buildURL(d?"poll":"open",{count:++d});a.data("url",f);b=e.xhr();b.onreadystatechange=function(){var c;g||4!==b.readyState||(200===b.status?(c=b.responseText)||1===d?(1===d&&a.fire("open"),c&&a._fire(c),g||h()):a.fire("close","done"):a.fire("close","error"))};b.open("GET",f);e.corsable&&(b.withCredentials=c.credentials);b.send(null)}h()},close:function(){g=!0;b.abort()}})},longpollxdr:function(a,
c){var b,g,d=0,h=l.XDomainRequest;if(h&&c.xdrURL&&c.xdrURL.call(a,"t"))return e.extend(u.httpbase(a,c),{open:function(){function e(){var l=c.xdrURL.call(a,a.buildURL(d?"poll":"open",{count:++d}));a.data("url",l);b=new h;b.onload=function(){var c=b.responseText;c||1===d?(1===d&&a.fire("open"),c&&a._fire(c),g||e()):a.fire("close","done")};b.onerror=function(){a.fire("close","error")};b.open("GET",l);b.send()}e()},close:function(){g=!0;b.abort()}})},longpolljsonp:function(a,c){var b,g,d,h=0,f=F.pop()||
"socket_"+ ++z;return e.extend(u.httpbase(a,c),{open:function(){function c(){var e=a.buildURL(h?"poll":"open",{callback:f,count:++h}),l=q.head||q.getElementsByTagName("head")[0]||q.documentElement;a.data("url",e);b=q.createElement("script");b.async=!0;b.src=e;b.clean=function(){b.clean=b.src=b.onerror=b.onload=b.onreadystatechange=null;b.parentNode&&b.parentNode.removeChild(b)};b.onload=b.onreadystatechange=function(){if(!b.readyState||/loaded|complete/.test(b.readyState))b.clean(),g?(g=!1,d||c()):
1===h?(a.fire("open"),d||c()):a.fire("close","done")};b.onerror=function(){b.clean();a.fire("close","error")};l.insertBefore(b,l.firstChild)}l[f]=function(b){g=!0;1===h&&a.fire("open");a._fire(b)};a.one("close",function(){l[f]=function(){};F.push(f)});c()},close:function(){d=!0;b.clean&&b.clean()}})}};return v});