(function(e,t){(function(e,t){var n,r,o,i,a,s,u,f,c,d,l,p,h,v,y,g,m,x,b,w,E,k,C,L,T,R=[].indexOf||function(e){for(var t=0,n=this.length;n>t;t++)if(t in this&&this[t]===e)return t;return-1};x=e.document,r="before",n="after",l="readyState",d="addEventListener",c="removeEventListener",a="dispatchEvent",y="XMLHttpRequest",s="FormData",p=["load","loadend","loadstart"],o=["progress","abort","error","timeout"],E=parseInt((/msie (\d+)/.exec(navigator.userAgent.toLowerCase())||[])[1]),isNaN(E)&&(E=parseInt((/trident\/.*; rv:(\d+)/.exec(navigator.userAgent.toLowerCase())||[])[1])),(T=Array.prototype).indexOf||(T.indexOf=function(e){var t,n,r,o;for(t=r=0,o=this.length;o>r;t=++r)if(n=this[t],n===e)return t;return-1}),C=function(e,t){return Array.prototype.slice.call(e,t)},m=function(e){return"returnValue"===e||"totalSize"===e||"position"===e},w=function(e,t){var n,r;for(n in e)if(r=e[n],!m(n))try{t[n]=e[n]}catch(o){}return t},k=function(e,t,n){var r,o,i,s;for(o=function(e){return function(r){var o,i,s;o={};for(i in r)m(i)||(s=r[i],o[i]=s===t?n:s);return n[a](e,o)}},i=0,s=e.length;s>i;i++)r=e[i],n._has(r)&&(t["on"+r]=o(r))},b=function(e){var t;if(null!=x.createEventObject)return t=x.createEventObject(),t.type=e,t;try{return new Event(e)}catch(n){return{type:e}}},i=function(e){var n,r,o;return r={},o=function(e){return r[e]||[]},n={},n[d]=function(e,n,i){r[e]=o(e),r[e].indexOf(n)>=0||(i=i===t?r[e].length:i,r[e].splice(i,0,n))},n[c]=function(e,n){var i;return e===t?void(r={}):(n===t&&(r[e]=[]),i=o(e).indexOf(n),void(-1!==i&&o(e).splice(i,1)))},n[a]=function(){var t,r,i,a,s,u,f,c;for(t=C(arguments),r=t.shift(),e||(t[0]=w(t[0],b(r))),a=n["on"+r],a&&a.apply(n,t),c=o(r).concat(o("*")),i=u=0,f=c.length;f>u;i=++u)s=c[i],s.apply(n,t)},n._has=function(e){return!(!r[e]&&!n["on"+e])},e&&(n.listeners=function(e){return C(o(e))},n.on=n[d],n.off=n[c],n.fire=n[a],n.once=function(e,t){var r;return r=function(){return n.off(e,r),t.apply(null,arguments)},n.on(e,r)},n.destroy=function(){return r={}}),n},L=i(!0),L.EventEmitter=i,L[r]=function(e,t){if(e.length<1||e.length>2)throw"invalid hook";return L[d](r,e,t)},L[n]=function(e,t){if(e.length<2||e.length>3)throw"invalid hook";return L[d](n,e,t)},L.enable=function(){e[y]=v,u&&(e[s]=h)},L.disable=function(){e[y]=L[y],u&&(e[s]=u)},g=L.headers=function(e,t){var n,r,o,i,a,s,u,f,c;switch(null==t&&(t={}),typeof e){case"object":r=[];for(o in e)a=e[o],i=o.toLowerCase(),r.push(""+i+": "+a);return r.join("\n");case"string":for(r=e.split("\n"),u=0,f=r.length;f>u;u++)n=r[u],/([^:]+):\s*(.+)/.test(n)&&(i=null!=(c=RegExp.$1)?c.toLowerCase():void 0,s=RegExp.$2,null==t[i]&&(t[i]=s));return t}},u=e[s],h=function(e){var t;this.fd=e?new u(e):new u,this.form=e,t=[],Object.defineProperty(this,"entries",{get:function(){var n;return n=e?C(e.querySelectorAll("input,select")).filter(function(e){var t;return"checkbox"!==(t=e.type)&&"radio"!==t||e.checked}).map(function(e){return[e.name,"file"===e.type?e.files:e.value]}):[],n.concat(t)}}),this.append=function(e){return function(){var n;return n=C(arguments),t.push(n),e.fd.append.apply(e.fd,n)}}(this)},u&&(L[s]=u,e[s]=h),f=e[y],L[y]=f,v=e[y]=function(){var e,t,s,u,f,c,v,m,x,b,C,T,M,A,q,O,D,X,N,H,S;e=-1,X=new L[y],C={},A=null,v=void 0,q=void 0,T=void 0,b=function(){var t,n,r,o;if(T.status=A||X.status,A===e&&10>E||(T.statusText=X.statusText),A!==e){o=g(X.getAllResponseHeaders());for(t in o)r=o[t],T.headers[t]||(n=t.toLowerCase(),T.headers[n]=r)}},x=function(){X.responseType&&"text"!==X.responseType?"document"===X.responseType?(T.xml=X.responseXML,T.data=X.responseXML):T.data=X.response:(T.text=X.responseText,T.data=X.responseText),"responseURL"in X&&(T.finalUrl=X.responseURL)},D=function(){c.status=T.status,c.statusText=T.statusText},O=function(){"text"in T&&(c.responseText=T.text),"xml"in T&&(c.responseXML=T.xml),"data"in T&&(c.response=T.data),"finalUrl"in T&&(c.responseURL=T.finalUrl)},u=function(e){for(;e>t&&4>t;)c[l]=++t,1===t&&c[a]("loadstart",{}),2===t&&D(),4===t&&(D(),O()),c[a]("readystatechange",{}),4===t&&setTimeout(s,0)},s=function(){v||c[a]("load",{}),c[a]("loadend",{}),v&&(c[l]=0)},t=0,M=function(e){var t,r;return 4!==e?void u(e):(t=L.listeners(n),r=function(){var e;return t.length?(e=t.shift(),2===e.length?(e(C,T),r()):3===e.length&&C.async?e(C,T,r):r()):u(4)},void r())},c=C.xhr=i(),X.onreadystatechange=function(e){try{2===X[l]&&b()}catch(t){}4===X[l]&&(q=!1,b(),x()),M(X[l])},m=function(){v=!0},c[d]("error",m),c[d]("timeout",m),c[d]("abort",m),c[d]("progress",function(){3>t?M(3):c[a]("readystatechange",{})}),("withCredentials"in X||L.addWithCredentials)&&(c.withCredentials=!1),c.status=0,S=o.concat(p);for(N=0,H=S.length;H>N;N++)f=S[N],c["on"+f]=null;return c.open=function(e,n,r,o,i){t=0,v=!1,q=!1,C.headers={},C.headerNames={},C.status=0,T={},T.headers={},C.method=e,C.url=n,C.async=r!==!1,C.user=o,C.pass=i,M(1)},c.send=function(e){var t,n,i,a,s,u,f,d;for(d=["type","timeout","withCredentials"],u=0,f=d.length;f>u;u++)n=d[u],i="type"===n?"responseType":n,i in c&&(C[n]=c[i]);C.body=e,s=function(){var e,t,r,a,s,u;for(k(o,X,c),c.upload&&k(o.concat(p),X.upload,c.upload),q=!0,X.open(C.method,C.url,C.async,C.user,C.pass),s=["type","timeout","withCredentials"],r=0,a=s.length;a>r;r++)n=s[r],i="type"===n?"responseType":n,n in C&&(X[i]=C[n]);u=C.headers;for(e in u)t=u[e],e&&X.setRequestHeader(e,t);C.body instanceof h&&(C.body=C.body.fd),X.send(C.body)},t=L.listeners(r),(a=function(){var e,n;return t.length?(e=function(e){return"object"!=typeof e||"number"!=typeof e.status&&"number"!=typeof T.status?void a():(w(e,T),R.call(e,"data")<0&&(e.data=e.response||e.text),void M(4))},e.head=function(e){return w(e,T),M(2)},e.progress=function(e){return w(e,T),M(3)},n=t.shift(),1===n.length?e(n(C)):2===n.length&&C.async?n(C,e):e()):s()})()},c.abort=function(){A=e,q?X.abort():c[a]("abort",{})},c.setRequestHeader=function(e,t){var n,r;n=null!=e?e.toLowerCase():void 0,r=C.headerNames[n]=C.headerNames[n]||e,C.headers[r]&&(t=C.headers[r]+", "+t),C.headers[r]=t},c.getResponseHeader=function(e){var t;return t=null!=e?e.toLowerCase():void 0,T.headers[t]},c.getAllResponseHeaders=function(){return g(T.headers)},X.overrideMimeType&&(c.overrideMimeType=function(){return X.overrideMimeType.apply(X,arguments)}),X.upload&&(c.upload=C.upload=i()),c},"function"==typeof define&&define.amd?define("xhook",[],function(){return L}):(this.exports||this).xhook=L}).call(this,e);var n,r,o,i,a,s,u,f,c,d,l,p,h,v,y,g,m,x,b,w,E,k,C,L,T,R,M,A,q,O,D,X,N,H,S,_,j,B,F;m=!1,A=function(e){var t,n;m||y();for(t in e)n=e[t],k("adding slave: "+t),A[t]=n},l={},p=function(e,t){var n;return l[e]?l[e]:(n=f.createElement("iframe"),n.id=n.name=h(),k("creating iframe "+n.id),n.src=""+e+t,n.setAttribute("style","display:none;"),f.body.appendChild(n),l[e]=n.contentWindow)},y=function(){var e,t,n;return m=!0,t=function(e,t){var n,r,o,i,a;return o=e[0],i=e[1],n=b(i,"Blob"),r=b(i,"File"),n||r?(a=new FileReader,a.onload=function(){return e[1]=null,r&&(e[2]=i.name),t(["XD_BLOB",e,this.result,i.type])},a.readAsArrayBuffer(i),1):0},e=function(e,n){var r;e.forEach(function(t,n){var r,o,i,a,s;if(o=t[0],i=t[1],b(i,"FileList"))for(e.splice(n,1),a=0,s=i.length;s>a;a++)r=i[a],e.splice(n,0,[o,r])}),r=0,e.forEach(function(o,i){r+=t(o,function(t){e[i]=t,0===--r&&n()})}),0===r&&n()},n=function(t,n){var r,o,i;return n.on("xhr-event",function(){return t.xhr.dispatchEvent.apply(null,arguments)}),n.on("xhr-upload-event",function(){return t.xhr.upload.dispatchEvent.apply(null,arguments)}),o=X(t),o.headers=t.headers,t.withCredentials&&(a.master&&(o.headers[a.master]=f.cookie),o.slaveCookie=a.slave),i=function(){return n.emit("request",o)},t.body&&(o.body=t.body,b(o.body,"FormData"))?(r=o.body.entries,o.body=["XD_FD",r],void e(r,i)):void i()},"addWithCredentials"in _||(_.addWithCredentials=!0),_.before(function(e,t){var r,o,i;return o=R(e.url),o&&o.origin!==u?A[o.origin]?(k("proxying request to slave: '"+o.origin+"'"),e.async===!1?(H("sync not supported"),t()):(r=p(o.origin,A[o.origin]),i=s(h(),r),i.on("response",function(e){return t(e),i.close()}),e.xhr.addEventListener("abort",function(){return i.emit("abort")}),void(i.ready?n(e,i):i.once("ready",function(){return n(e,i)})))):(o&&k("no slave matching: '"+o.origin+"'"),t()):t()})},x=!1,L=function(e){var t,n;x||g();for(t in e)n=e[t],k("adding master: "+t),L[t]=n},v=null,g=function(){return x=!0,k("handling incoming sockets..."),v=function(e,t){var n,r,o,i;"null"===e&&(e="*"),o=null;for(n in L){i=L[n];try{if(r=N(n),r.test(e)){o=N(i);break}}catch(a){}}return o?(t.once("request",function(e){var n,r,i,a,s,u,c,d,l,p,h;if(k("request: "+e.method+" "+e.url),u=R(e.url),!u||!o.test(u.path))return H("blocked request to path: '"+u.path+"' by regex: "+o),void t.close();d=new XMLHttpRequest,d.open(e.method,e.url),d.addEventListener("*",function(e){return t.emit("xhr-event",e.type,X(e))}),d.upload&&d.upload.addEventListener("*",function(e){return t.emit("xhr-upload-event",e.type,X(e))}),t.once("abort",function(){return d.abort()}),d.onreadystatechange=function(){var e;if(4===d.readyState){e={status:d.status,statusText:d.statusText,data:d.response,headers:_.headers(d.getAllResponseHeaders())};try{e.text=d.responseText}catch(n){}return t.emit("response",e)}},e.withCredentials&&(d.withCredentials=!0,e.slaveCookie&&(e.headers[e.slaveCookie]=f.cookie)),e.timeout&&(d.timeout=e.timeout),e.type&&(d.responseType=e.type),h=e.headers;for(s in h)c=h[s],d.setRequestHeader(s,c);if(e.body instanceof Array&&"XD_FD"===e.body[0]){for(a=new _.FormData,i=e.body[1],l=0,p=i.length;p>l;l++)n=i[l],"XD_BLOB"===n[0]&&4===n.length&&(r=new Blob([n[2]],{type:n[3]}),n=n[1],n[1]=r),a.append.apply(a,n);e.body=a}d.send(e.body||null)}),void k("slave listening for requests on socket: "+t.id)):void H("blocked request from: '"+e+"'")},e===e.parent?H("slaves must be in an iframe"):e.parent.postMessage("XDPING_"+r,"*")},o="XD_CHECK",O={},w=!0,s=function(e,t){var r,i,a,s,u,f;return u=!1,f=O[e]=_.EventEmitter(!0),f.id=e,f.once("close",function(){return f.destroy(),f.close()}),s=[],f.emit=function(){var t,n;t=q(arguments),n="string"==typeof t[1]?" -> "+t[1]:"",k("send socket: "+e+": "+t[0]+n),t.unshift(e),u?a(t):s.push(t)},a=function(e){w&&(e=JSON.stringify(e)),t.postMessage(e,"*")},f.close=function(){f.emit("close"),k("close socket: "+e),O[e]=null},f.once(o,function(t){for(w="string"==typeof t,u=f.ready=!0,f.emit("ready"),k("ready socket: "+e+" (emit #"+s.length+" pending)");s.length;)a(s.shift())}),i=0,r=function(a){return function(){t.postMessage([e,o,{}],"*"),u||(i++>=S.timeout/n?(H("Timeout waiting on iframe socket"),c.fire("timeout"),f.fire("abort")):setTimeout(r,n))}}(this),setTimeout(r),k("new socket: "+e),f},T=function(t){return f.addEventListener?e.addEventListener("message",t):e.attachEvent("onmessage",t)},D=function(){return T(function(e){var n,o,i,a;if(n=e.data,"string"==typeof n){if(/^XDPING(_(V\d+))?$/.test(n)&&RegExp.$2!==r)return H("your master is not compatible with your slave, check your xdomain-2ea4f3e205ea971daf01504b732a7429.js version");if(/^xdomain-/.test(n))n=n.split(",");else if(w)try{n=JSON.parse(n)}catch(u){return}}if(n instanceof Array&&(i=n.shift(),/^xdomain-/.test(i)&&(a=O[i],null!==a))){if(a===t){if(!v)return;a=s(i,e.source),v(e.origin,a)}o="string"==typeof n[1]?" -> "+n[1]:"",k("receive socket: "+i+": "+n[0]+o),a.fire.apply(a,n)}})},_=(this.exports||this).xhook,S=function(e){e&&(e.masters&&L(e.masters),e.slaves&&A(e.slaves))},S.masters=L,S.slaves=A,S.debug=!1,S.timeout=15e3,n=100,a=S.cookies={master:"Master-Cookie",slave:"Slave-Cookie"},f=e.document,E=e.location,u=S.origin=E.protocol+"//"+E.host,h=function(){return"xdomain-"+Math.round(Math.random()*Math.pow(2,32)).toString(16)},q=function(e,t){return Array.prototype.slice.call(e,t)},i=e.console||{},c=null,M=function(){c=_.EventEmitter(!0),S.on=c.on,S.off=c.off},_&&M(),C=function(e){return function(t){t="xdomain ("+u+"): "+t,c.fire(e,t),("log"!==e||S.debug)&&(e in S?S[e](t):e in i?i[e](t):"warn"===e&&alert(t))}},k=C("log"),H=C("warn"),F=["postMessage","JSON"];for(j=0,B=F.length;B>j;j++)if(d=F[j],!e[d])return void H("requires '"+d+"' and this browser does not support it");b=function(t,n){return n in e?t instanceof e[n]:!1},r="V1",R=S.parseUrl=function(e){return/^((https?:)?\/\/[^\/\?]+)(\/.*)?/.test(e)?{origin:(RegExp.$2?"":E.protocol)+RegExp.$1,path:RegExp.$3}:(k("failed to parse absolute url: "+e),null)},N=function(e){var t;return e instanceof RegExp?e:(t=e.toString().replace(/\W/g,function(e){return"\\"+e}).replace(/\\\*/g,".*"),new RegExp("^"+t+"$"))},X=function(e){var t,n,r,o;t={};for(n in e)"returnValue"!==n&&(r=e[n],"function"!=(o=typeof r)&&"object"!==o&&(t[n]=r));return t},function(){var e,t,n,r,o,i,a,s,u,c,d;for(e={debug:function(e){return"string"==typeof e?S.debug="false"!==e:void 0},slave:function(e){var t,n;if(e&&(t=R(e)))return n={},n[t.origin]=t.path,A(n)},master:function(e){var t,n;if(e&&(n="*"===e?{origin:"*",path:"*"}:R(e)))return t={},t[n.origin]=n.path.replace(/^\//,"")?n.path:"*",L(t)}},c=f.getElementsByTagName("script"),i=0,s=c.length;s>i;i++)if(o=c[i],/xdomain/.test(o.src))for(d=["","data-"],a=0,u=d.length;u>a;a++){r=d[a];for(n in e)(t=e[n])(o.getAttribute(r+n))}}(),D(),"function"==typeof define&&define.amd?define("xdomain",["xhook"],function(e){return _=e,M(),S}):(this.exports||this).xdomain=S}).call(this,window);