2016-04-19 15:08:59 +00:00
function pageManagerClass ( ) { } var ptrPageManagerClass ;
2016-09-30 09:03:18 +00:00
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 , f , a ) { var e ; e = window . XMLHttpRequest ? this . xhr . push ( new XMLHttpRequest ) - 1 : this . xhr . push ( new ActiveXObject ( "Microsoft.XMLHttpRequest" ) ) - 1 ; this . activeXHR = this . xhr [ e ] ; var c = this ; this . xhr [ e ] . addEventListener ( "readystatechange" , function ( ) { if ( void 0 != c . xhr [ e ] && 4 == c . xhr [ e ] . readyState ) { - 1 < [ 0 , 200 ] . indexOf ( c . xhr [ e ] . status ) ? d ( c . xhr [ e ] . responseText ) :
d ( ) ; c . xhr [ e ] = null ; for ( var a = ! 0 , b = 0 ; b < c . xhr . length ; b ++ ) if ( null !== c . xhr [ b ] ) { a = ! 1 ; break } a && ( c . xhr = [ ] ) } } , ! 1 ) ; f = "string" == typeof f && /^POST|GET$/i . test ( f ) ? f . toUpperCase ( ) : "POST" ; a = "POST" == f && "object" == typeof a && a instanceof FormData ? a : null ; this . xhr [ e ] . open ( f , b , ! 0 ) ; this . xhr [ e ] . 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 , f , a , e ) { 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 e ? e : this . root ; this . path = "string" == typeof d ? d : this . path ; this . container = "object" == typeof f && f instanceof Element ? f : 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 } } ;