-
Notifications
You must be signed in to change notification settings - Fork 2
/
rest-min.js
3 lines (3 loc) · 1.14 KB
/
rest-min.js
1
2
3
(function(a){function j(a){return function(){this.readyState==4&&a(this.responseText)}}function k(){for(var a="cb",b=0;b<20;b++)a+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(Math.random()*62));return a}var g,h,f=!0;a.useJSON=function(){f=!1;return a};a.useJSONP=function(){f=!0;return a};a.login=function(c){g=c;return a};a.password=function(c){h=c;return a};a.baseURL=function(){return a};a.get=function(c,b){a.request("GET",c,null,b)};a.post=function(c,b,d){a.request("POST",
c,b,d)};a.put=function(c,b,d){a.request("PUT",c,b,d)};a.del=function(c,b){a.request("DELETE",c,null,b)};a.request=function(a,b,d,i){if(f){var d=document.createElement("script"),e=k();window[e]=function(a){i(a)};b+=b.indexOf("?")==-1?"?":"&";b+="callback="+e+"&jsoncallback="+e;if(a!="GET")throw b+="?_method="+a,"JSONP doesn't support "+a;d.type="text/javascript";d.src=b;document.getElementsByTagName("head")[0].appendChild(d)}else e=new XMLHttpRequest,e.onreadystatechange=j(i),e.open(a,b,!0,g,h),d?
e.send(d):e.send(null)};a.unpack=function(){window.get=a.get;window.post=a.post;window.put=a.put;window.del=a.del};window.restjs=a})(window.restjs||{});