-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrekord-ajax.min.js
3 lines (3 loc) · 3.02 KB
/
rekord-ajax.min.js
1
2
3
/* rekord-ajax 1.5.6 - A dependency free AJAX implementation of Rekord.rest by Philip Diffenderfer */
!function(e,t){"function"==typeof define&&define.amd?define(["rekord"],function(n){return t(e,n)}):"object"==typeof module&&module.exports?module.exports=t(global,require("rekord")):e.Rekord=t(e,e.Rekord)}(this,function(e,t,n){function i(e){this.database=e}function r(e){return e.api?new i(e):R.call(this,e)}function s(e,t){e.send(t.data)}function o(e,t){return t?e.api+t.$key():e.api}var a="undefined"!=typeof window?window:e,u=t.copy,d=t.noop,c=t.transfer,l=t.format,f=t.isFormatInput,p=t.isEmpty,h=t.isNumber,m=t.isObject,R=(t.isString,t.rest),x=a.XMLHttpRequest||d,b="withCredentials"in new x?x:a.XDomainRequest,v=a.clearTimeout,y=a.setTimeout;return i.prototype={removeTrailingSlash:function(e){return"/"===e.charAt(e.length-1)?e.substring(0,e.length-1):e},buildURL:function(e){return this.removeTrailingSlash(t.Ajax.buildURL(this.database,e))},all:function(e,t,i){this.execute("GET",null,n,this.buildURL(),e,t,i,[])},get:function(e,t,i,r){this.execute("GET",e,n,this.buildURL(e),t,i,r)},create:function(e,t,n,i,r){this.execute("POST",e,t,this.buildURL(),n,i,r,{})},update:function(e,t,n,i,r){this.execute("PUT",e,t,this.buildURL(e),n,i,r,{})},remove:function(e,t,i,r){this.execute("DELETE",e,n,this.buildURL(e),t,i,r,{})},query:function(e,t,n,i,r){var s=p(t)?"GET":"POST";this.execute(s,null,t,e,n,i,r)},encode:function(e,t){var n,i=[];for(var n in e)if(e.hasOwnProperty(n)){var r=t?t+"["+n+"]":n,s=e[n];i.push(m(s)?this.encode(s,r):a.encodeURIComponent(r)+"="+a.encodeURIComponent(s))}return i.join("&")},execute:function(e,i,r,s,o,a,p,R){if(t.debug(t.Debugs.REST,this,e,s,r),t.forceOffline)p(R,0);else{var T,j,w=u(t.Ajax.options);m(o)&&c(o,w);var g=w.headers=w.headers||{},L=w.cors||w.useXDR?new b:new x,O=c(t.Ajax.vars,c(i,{}));if(w.method=e,w.url=s,w.data=r,m(o)){if(c(o,w),m(o.params)){var U=this.encode(o.params),A=w.url.indexOf("?");w.url+=-1===A?"?":"&",w.url+=U}m(o.vars)&&c(o.vars,O)}t.Ajax.adjustOptions(w,this.database,e,i,r,s,O,o,a,p),f(w.url)&&(w.url=l(w.url,O));var E=function(){4===L.readyState&&C()},S=function(){var e;L.response?e=L.response:"text"!==L.responseType&&L.responseType||(e=L.responseText||L.responseXML);try{e=JSON.parse(e)}catch(t){}return e},C=function(){if(!T){var e=(w.useXDR&&L.status===n?200:1223===L.status?204:L.status)||0,t=S();0!==e?a(t):p(t,0),a=d,p=d,v(j)}},q=function(){p(null,0),p=d,a=d,v(j)},D=function(){T=!0,L.abort("timeout"),q()};if(g.Accept="application/json","GET"!==e&&"HEAD"!==e&&(g["Content-Type"]="application/json",w.data=JSON.stringify(w.data)),L.onreadystatechange=E,L.onload=C,L.onerror=q,L.onprogress=function(){},L.ontimeout=q,L.open(w.method,w.url,!0,w.username,w.password),L.withCredentials=!!w.withCredentials,h(w.timeout)&&w.timeout>0&&(j=y(D,w.timeout)),L.setRequestHeader)for(var k in g)g.hasOwnProperty(k)&&L.setRequestHeader(k,g[k]);t.Ajax.ajax(L,w)}}},t.Rests.Ajax=r,t.setRest(r,!0),t.Ajax={rest:r,options:{},vars:{},adjustOptions:d,ajax:s,buildURL:o,RestClass:i},t});
//# sourceMappingURL=rekord-ajax.min.js.map