-
Notifications
You must be signed in to change notification settings - Fork 1
/
jaxify.min.js
1 lines (1 loc) · 3.32 KB
/
jaxify.min.js
1
varJAX={processResponse:function($text,$type){if($type&&$type.toUpperCase()=="JSON"){try{returnJSON.parse($text);}catch(ex){console.log("AnErrorOccurredWhileProcessingResponseasJSON"+ex+""+console.trace());}}elseif($type&&$type.toUpperCase()=="HTML"){$doc=document.createElement("markup");$doc.innerHTML=$text;return$doc;}elseif($type&&$type.toUpperCase()=="JAXHTML"){var$working=JSON.parse($text),$compiled="";}return$text;},URL:function($mixed,$query,$method,$success,$failure,$endres){if(typeof$mixed=="number"){returnJAX.URLS[$mixed];}elseif(typeof$mixed=="string"){if(RegExp(/.*/).test($mixed)){$url_obj={mixed:$mixed,query:$query,method:$method,success:$success,failure:$failure,endres:$endres}JAX.URLS.push($url_obj);returntrue;}}returnfalse;},GET:function($mixed,$query,$method,$success,$failure,$endres){JAX.runLoader();if(typeof$mixed=="number"){$$=JAX.URL($mixed);$mixed=$$.mixed$method=$method||$$.method;$query=$query||$$.query;$success=$success||$$.success;$failure=$failure||$$.failure;$endres=$endres||$$.endres;}if(typeof$query!="object")returnconsole.log("Expectedobject,"+typeof$query+"givenonline:"+console.trace());$server=newXMLHttpRequest();$query_string="?";$query_string2="";for($paramin$query){$query_string+="&"+$param+"="+$query[$param];}if($method.toUpperCase()=="POST"){$query_string2=$query_string.substring(1);$query_string="";}if($query_string=="?")$query_string="";$server.onreadystatechange=function(){if(this.readyState==4&&this.status==200){JAX.runLoader();$response=JAX.processResponse(this.responseText,$endres);!$success||$success($response);}elseif(this.readyState==4&&this.status==400){!$failure||$failure(this.responseText);}}$server.open($method,((typeof$mixed=="number")?JAX.URL($mixed):$mixed)+$query_string,true);if($query_string2){$server.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}$server.send($query_string2);},registerLoader:function($id_html_obj,$class){$loader=$id_html_obj;if(typeof$id_html_obj=="string"){$loader=document.getElementById($id_html_obj.replace("#","",1));}$loader.setAttribute("JAX-LOADER-CLASS",$class);JAX.Loader=$loader;},runLoader:function(){$class=JAX.Loader.getAttribute("JAX-LOADER-CLASS");JAX.Loader.classList.toggle($class);},CyclicRequest:function($url,$method,$query,$delay){this.url=$url||console.log("Unabletocontinue:URLnotspecified");this.method=$method||"GET";this.query=$query||console.log("QueryMustBeanObject");this.delay=$delay||5000;this.holded=false;this.index=0;},sendForm:function($index,$form){$elements=$form.elements;$end_data={};for($i=0;$i<$elements.length;$i++){if($elements[$i]&&$elements[$i].type=="radio"){if($elements[$i].checked==true)$end_data[$elements[$i].name]=$elements[$i].value;elsecontinue;}!$elements[$i]||($end_data[$elements[$i].name]=$elements[$i].value);if($elements[$i]&&$elements[$i].type=="checkbox")$end_data[$elements[$i].name]=$elements[$i].checked;}JAX.GET($index,$end_data);},URLS:[],Loader:null}JAX.CyclicRequest.prototype.start=function(){!this.oncyclestart||this.oncyclestart();JAX.GET(this.url,this.query,this.method,this.onsuccess,this.onfailure,this.parsetype);$this=this;if(this.holded!==true){this.index++;setTimeout(function(){$this.start();},this.delay);}!this.oncycleend||this.oncycleend();}JAX.CyclicRequest.prototype.hold=function(){this.holded=true;}JAX.CyclicRequest.prototype.unhold=function(){this.holded=false;this.start();}