-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcors.min.js
14 lines (13 loc) · 4.12 KB
/
cors.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
CORS (Cross-Origin Resource Sharing) library (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
@author ShirtlessKirk copyright 2014
@license WTFPL (http://www.wtfpl.net/txt/copying)
*/
(function(c,q){"function"===typeof define&&define.amd?define(function(){return q(c)}):"function"===typeof module&&module.exports?module.exports=q(c):q(c)})(this,function(c){function q(){var a=this.name;0!==this.message.length&&(a+=": "+this.message);return a}function v(a,b){this.name=a;this.message=b||""}function B(a,b){void 0!==b&&b!==this.status&&(this.status=b);if(this.readyState!==a&&(this.readyState=a,"function"===typeof this.onreadystatechange))this.onreadystatechange()}function C(){var a=this.parent,
b=g.i;if(void 0!==a){this.readyState===d.DONE&&(a.response=this.response,a.responseText=this.responseText);try{b=this.status}catch(c){}B.call(a,this.readyState,b)}}function l(a,b){this.readyState=a;void 0!==b&&(this.status=b);if("function"===typeof this.onreadystatechange)this.onreadystatechange()}function x(){var a=this.e,b;b=a.readyState||"complete";"loaded"!==b&&"complete"!==b||a.loaded||(a.loaded=!0,a.onload=a.onreadystatechange=null,a.parentNode.removeChild(a),delete this.e,l.call(this,d.DONE,
g.i))}function D(a,b,n){a=void 0!==n?n:!0;var e;n=r.createElement("script");var h=this;a&&(n.async=a);n.id=m.b+"_"+(new Date).getTime();n.loaded=!1;n.onload=n.onreadystatechange=function(){x.call(h)};e="__"+n.id;c[e]=function(a){h.response=h.responseText=a;c[e]=void 0;"function"===typeof h.l&&h.l.call(c,h)};n.src=(0===b.indexOf("//")?r.location.protocol:"")+b;l.call(this,d.j,g.g);this.e=n;l.call(this,d.c,g.h)}function E(a){var b,c,e,h,f,k,p;if(this.readyState!==d.c)throw new v("InvalidStateError",
"Failed to execute 'send' on '"+m.b+"': the object's state must be OPENED.");p=this.e;a=a||null;c=r.head||r.getElementsByTagName("head")[0];b=p.src.split("?");f=k=[];1<b.length&&(f=b[1].split("&"),p.src=b[0]);b=0;for(e=f.length;b<e;b+=1)0===f[b].indexOf("callback=")?this.callback=k[b].split("=")[1]:k.push(f[b]);for(h in a)a.hasOwnProperty(h)&&("callback"===h?this.callback=a[h]:k.push(encodeURIComponent(h)+"="+encodeURIComponent(a[h])));k.push("callback=__"+p.id);p.src+="?"+k.join("&");c.appendChild(p);
l.call(this,d.LOADING,g.f)}function F(){l.call(this,d.DONE,g.m)}function G(){this.response=this.responseText;l.call(this,d.DONE,g.i)}function H(){var a=w.call(arguments),b=this.a;this.method=a[0].toUpperCase();b.onerror=F;b.onload=G;l.call(b,d.j,g.g);b.open.apply(b,a);l.call(b,d.c,g.h)}function I(){var a=this.a;a.send.apply(a,arguments);l.call(a,d.LOADING,g.f)}function J(){var a=w.call(arguments),b=this.a;this.method=a[0].toUpperCase();b.open.apply(b,a)}function K(){var a=this.a;a.setRequestHeader("Content-Type",
("POST"===this.method?"multipart/form-data":"application/x-www-form-urlencoded")+"; charset=UTF-8");a.setRequestHeader("X-Requested-With",m.d);a.send.apply(a,arguments)}function L(){try{this.a.abort()}catch(a){}}function y(){var a=w.call(arguments),b=this.a;a[0]="get";this.method=a[0].toUpperCase();b.onload=x;l.call(b,d.j,g.g);b.open.apply(b,a);l.call(b,d.c,g.h)}function z(){var a=this.a;a.send.apply(a,arguments);l.call(a,d.LOADING,g.f)}function t(a){var b=a?m.b:u;this.readyState=this.response=this.status=
null;this.responseText="";b=this.a=new c[b];b.onreadystatechange=C;b.parent=this;a&&(this.TYPE=m.b,this.open=y,this.send=z)}function A(){this.readyState=this.status=null;this.responseText=""}var w=Array.prototype.slice,f,u,k,r=c.document,e,g={CONTINUE:100,CREATED:201,OK:200,ACCEPTED:202,SERVERERROR:500},d={UNSENT:0,OPENED:1,HEADERS_RECEIVED:2,LOADING:3,DONE:4},m={d:"XMLHttpRequest",k:"XDomainRequest",b:"JSONPHttpRequest"};if(!c.CORS){v.prototype=Error();k=v.prototype;k.toString=q;u=void 0!==c.XMLHttpRequest&&
void 0!==(new c.XMLHttpRequest).withCredentials?m.d:void 0!==c.XDomainRequest?m.k:m.b;k=A.prototype;k.open=D;k.send=E;e=t.prototype;e.TYPE=u;e.abort=L;switch(u){case m.b:e.open=y;e.send=z;break;case m.k:e.open=H;e.send=I;break;case m.d:e.open=J,e.send=K}for(f in d)d.hasOwnProperty(f)&&(e[f]=k[f]=d[f]);c.CORS=t;c[m.b]=A;c.JSON||(f=new t(!0),f.open("GET","//cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js",!1),f.send());return t}});