NxTIC/js/lib/page-manager-min.js

10 lines
4.0 KiB
JavaScript

function pageManagerClass(){}var ptrPageManagerClass;
pageManagerClass.prototype={depJS:null,depCSS:null,xhr:[],activeXHR:null,page:null,vars:[],root:"",path:"",jsPath:"js",cssPath:"css",pagelist:null,container:null,ajax:function(b,d,e,a){for(var f=0;f<this.xhr.length;f++)this.xhr=this.xhr.slice(0,f-1).concat(this.xhr.slice(f,this.xhr.length-1));var c;c=window.XMLHttpRequest?this.xhr.push(new XMLHttpRequest)-1:this.xhr.push(new ActiveXObject("Microsoft.XMLHttpRequest"))-1;this.activeXHR=this.xhr[c];var g=this;this.xhr[c].onreadystatechange=function(){4==
g.xhr[c].readyState&&(-1<[0,200].indexOf(g.xhr[c].status)?d(g.xhr[c].responseText):d())};e="string"==typeof e&&/^POST|GET$/i.test(e)?e.toUpperCase():"POST";a="POST"==e&&"object"==typeof a&&a instanceof FormData?a:null;this.xhr[c].open(e,b,!0);this.xhr[c].send(a);return this},explodeURL:function(b){b=1<=arguments.length?b:document.URL;if(null!=this.pagelist&&/^(?:(?:https?:\/\/)?[^\/]+)\/([a-z0-9_]+)\/?(?:\/((?:.+\/)+)\/?)?$/i.test(b)){for(var d=RegExp.$2.split("/");""==d[d.length-1];)d.pop();return-1<
this.pagelist.indexOf(RegExp.$1)?{page:RegExp.$1,"var":d}:null}return null},loadDependencies:function(){"object"==typeof this.depCSS&&this.depCSS instanceof Element&&this.depCSS.parentNode==document.head&&document.head.removeChild(this.depCSS);"object"==typeof this.depJS&&this.depJS instanceof Element&&this.depJS.parentNode==document.head&&document.head.removeChild(this.depJS);ptrPageManagerClass=this;this.ajax(this.root+this.path+"/"+this.cssPath+"/"+this.page+".css",function(b){null!=b?(ptrPageManagerClass.depCSS=
document.createElement("link"),ptrPageManagerClass.depCSS.rel="stylesheet",ptrPageManagerClass.depCSS.type="text/css",ptrPageManagerClass.depCSS.href=ptrPageManagerClass.root+ptrPageManagerClass.path+"/"+ptrPageManagerClass.cssPath+"/"+ptrPageManagerClass.page+".css",document.head.appendChild(ptrPageManagerClass.depCSS)):console.warn("[loadDependencies_Error] - ("+ptrPageManagerClass.root+ptrPageManagerClass.path+"/"+ptrPageManagerClass.cssPath+"/"+ptrPageManagerClass.page+".css)")});this.ajax(this.root+
this.path+"/"+this.jsPath+"/"+this.page+".js",function(b){null!=b?(ptrPageManagerClass.depJS=document.createElement("script"),ptrPageManagerClass.depJS.type="text/javascript",ptrPageManagerClass.depJS.src=ptrPageManagerClass.root+ptrPageManagerClass.path+"/"+ptrPageManagerClass.jsPath+"/"+ptrPageManagerClass.page+".js",document.head.appendChild(ptrPageManagerClass.depJS)):console.warn("[loadDependencies_Error] - ("+ptrPageManagerClass.root+ptrPageManagerClass.path+"/"+ptrPageManagerClass.jsPath+"/"+
ptrPageManagerClass.page+".js)")})},updateURL:function(){0<this.vars.length?window.history.pushState(this.page,this.page,this.root+"/"+this.page+"/"+this.vars.join("/")+"/"):window.history.pushState(this.page,this.page,this.root+"/"+this.page+"/")},setPage:function(b,d,e,a,f){var c="object"==typeof a&&a instanceof Array?a:null;if(null!=c)for(a=0;a<c.length&&(c="string"==typeof c[a]&&/^[a-z0-9_]+$/i.test(c[a])?c:null,null!=c);a++);this.pagelist=null!=c?c:this.pagelist;this.page=this.pagelist[0];this.root=
"string"==typeof f?f:this.root;this.path="string"==typeof d?d:this.path;this.container="object"==typeof e&&e instanceof Element?e:this.container;if(null!=this.pagelist&&null!=this.container)if("string"==typeof b&&-1<this.pagelist.indexOf(b)){this.page=b;var g=this;b=new FormData;for(a=0;a<this.vars.length;a++)b.append(this.vars[a],null);this.ajax(this.root+this.path+"/"+this.page+".php",function(a){g.container.innerHTML=a;g.loadDependencies()},"POST",b);this.updateURL()}else if(d=this.explodeURL(),
null!=d){this.page=d.page;var h=this;b=new FormData;for(a=this.vars.length=0;a<d["var"].length;a++)this.vars[a]=d["var"][a],b.append(this.vars[a],null);this.ajax(this.root+this.path+"/"+this.page+".php",function(a){h.container.innerHTML=a;h.loadDependencies()},"POST",b);this.updateURL()}else this.setPage(this.pagelist[0]);else console.warn("pagelist et container manquant");return this},refresh:function(){this.setPage(this.page);return this}};