NxTIC/js/lib/api-min.js

5 lines
1.1 KiB
JavaScript

function APIClass(b){this.target=b}
APIClass.prototype={xhr:[],send:function(b,d,e){b.hasOwnProperty("path")||d({ModuleError:4});for(var a=0;a<this.xhr.length;a++)4==this.xhr[a].readyState&&(this.xhr=this.xhr.slice(0,a-1).concat(this.xhr.slice(a,this.xhr.length-1)));this.xhr.push(null);a=this.xhr.length-1;this.xhr[a]=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHttpRequest");console.log(b);var c=this;this.xhr[a].onreadystatechange=function(){if(4==c.xhr[a].readyState)if(-1<[0,200].indexOf(c.xhr[a].status))try{d(JSON.parse(c.xhr[a].responseText))}catch(b){d({ModuleError:1})}else d({ModuleError:3})};
var g=new FormData,f;for(f in b)g.append(f,b[f]);this.xhr[a].open("POST",this.target,!0);null!=e&&this.xhr[a].setRequestHeader("Authorization","Digest "+e);this.xhr[a].send(g)}};
function fileUploader(b,d,e){var a=new FormData;a.append("prefix",d);a.append("file",b,b.name);var c=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHttpRequest");c.open("POST","/manager/uploader.php",!0);c.onreadystatechange=function(){4==c.readyState&&-1<[0,200].indexOf(c.status)&&e(c.responseText)};c.send(a)};