"use strict" let _ = ( function ( ) { let u = 'https://sys.jp.etc.br/_/pro/', g = u+"_.php", gi = u+"_i.php", c = "1005p", q, ld, csss = {}, scripts = {}, scline = {}, scexec = "", lastUrl = window.location.pathname, lastBody, deferredH, bf = false, // block form ts = new Date().getTime(), lu, loader_cls = function ( ) { }, loader_opn = function ( ) { }, url_change = function ( url ) { lastUrl = url; history.pushState(null, null, window.location); history.replaceState(null, null, url); }, url_clean = function ( url ) { let z, x, y, q = ( url.search ) ? url.search.replace("?", "&") : ""; // querystring url = url.pathname.replace(zen_urep, ""); if ( url.startsWith("/") ) url = url.substr(1); url = url.split("/"); // zen_urep vem do arquivo html z = url.shift(); // arquivo php para onde será redirecionado x = url.shift(); // variável extra 1 y = url.join("/"); // demais variáveis lu = [z, x, y, q]; return lu; }, dH_mount = function ( ) { let temp; if ( deferredH ) { temp = JSON.parse(JSON.stringify(deferredH)); deferredH = null; mount_html( temp, null ); } else { loader_cls(); } }, dlf = function ( fl, tp, nm ) { // download file - file, type, name let link = document.createElement('a'), blob = new Blob([fl], {type: tp}); link.download = nm; link.href = URL.createObjectURL(blob); link.click(); URL.revokeObjectURL(link.href); }, exec_js = function ( ) { let s, k = Object.keys(scline); if ( k.length === 0 ) { if ( scexec ) { s = document.createElement('script'); s.innerHTML = scexec; document.body.appendChild(s); scexec = ""; } dH_mount(); } else { fetch_js(k[0]).then( js => { scripts[k[0]] = true; delete scline[js]; exec_js(); }); } }, fetch_css = function ( css ) { let css2 = u+css+".css?v="+ts; return new Promise((resolve, reject) => { let link = document.createElement( "link" ); link.type = "text/css"; link.rel = "stylesheet"; link.media = "screen,print"; link.href = css2; link.id = "css_"+css; link.onload = function() { resolve(link); }; document.getElementsByTagName( "head" )[0].appendChild( link ); }); }, fetch_js = function ( js ) { let js2 = u+js+".js?v="+ts; return new Promise((resolve, reject) => { let nscript = document.createElement( "script" ); nscript.src = js2; nscript.onload = function() { resolve(js); }; document.body.appendChild(nscript); }); }, fetch_html = function ( p, l = null, m = null ) { if ( p[0] ) { q = p; if ( l ) { ld = document.getElementById(l); ld.classList.remove('hid'); } else loader_opn ( m ); p[1] = p[1] || ""; p[2] = p[2] || ""; p[3] = p[3] || ""; fetch(g+"?z="+p[0]+"&x="+p[1]+"&y="+p[2]+p[3], {credentials: "include", cache:"no-store"}).then(response => response.json()).then(res => { mount_html(res, p[0]); }).catch ( e => { loader_cls(); }); } }, mount_html = function ( h, p ) { let id = h[0] || "zen", i, j, s, l, x, y; if ( h[10] ) { h[10][1] = h[10][1] || ""; h[10][2] = h[10][2] || ""; url_change(window.location.protocol+"//"+window.location.host+zen_urep+h[10][0]+h[10][1]+h[10][2]); } if ( h[7] ) { // redirecionamento ou simples reposição de url h[7][1] = h[7][1] || ""; h[7][2] = h[7][2] || ""; x = ( h[7][1] ) ? `/${h[7][1]}` : ""; y = ( h[7][2] ) ? `/${h[7][2]}` : ""; if ( h[7][3] ) { // redirecionamento com reload window.location.replace(window.location.protocol+"//"+window.location.host+zen_urep+h[7][0]+x+y); return; } else { // redirecionamento ajax ( sem reload ) url_change(window.location.protocol+"//"+window.location.host+zen_urep+h[7][0]+x+y); fetch_html(h[7]); // redirecionamento return; } } if ( h[8] ) { if ( Array.isArray( h[8] ) ) { for ( i in csss ) { if ( !h[8].includes(i) ) { csss[i].disabled = true; csss[i].parentNode.removeChild(csss[i]); delete csss[i]; } } } else { for ( i in csss ) { if ( i != h[8] ) { csss[i].disabled = true; csss[i].parentNode.removeChild(csss[i]); delete csss[i]; } } } } if ( h[9] && lastBody !== h[9] ) { deferredH = JSON.parse(JSON.stringify(h)); deferredH[9] = null; fetch_html([h[9]]); return; } if ( h[6] ) { if ( Array.isArray( h[6] ) ) { i = 0; j = h[6].length; for ( ; i < j; i++ ) { if ( !csss[h[6][i]] ) fetch_css(h[6][i]).then(res=>{csss[h[6][i]] = res; }); } } else if ( !csss[h[6]] ) { fetch_css(h[6]).then(res=>{csss[h[6]] = res; }); } } if ( h[1] ) { h[1] = h[1].replace(/K_URL/g, u).replace(/K_UCLI/g, u+"cli/"+c+"/"); if ( id == "body" ) { l = zen_loader; document.body.innerHTML = h[1]; document.body.appendChild(l); lastBody = p; } else { document.getElementById(id).innerHTML = h[1]; } } if ( h[2] ) { // title document.title = h[2]; } if ( h[3] ) { document.body.id = h[3]; } if ( h[5] ) scexec+= h[5]; if ( h[4] ) { i = 0; j = h[4].length; for ( ; i < j; i++ ) { if ( !scripts[h[4][i]] ) { scline[h[4][i]] = true; } } } exec_js(); }, getq = function ( ) { return lu; }, init = ( function ( ) { let nd = document.createElement('div'); //window.location = window.location.toString().replace(/\/$/, ""); //console.log(window.location.toString().endsWith("/")); zen_js.parentNode.removeChild(zen_js); zen.innerHTML = ""; nd.id = "zen_loader"; nd.innerHTML = `

Por favor aguarde...

`; document.body.appendChild(nd); /* .then( ok => alert(`${ok} is loaded!`), error => alert(`Error: ${error.message}`) ); */ fetch_css("_").then( ok => { loader_cls = function ( ) { zen_loader.className = ""; if ( ld ) ld.classList.add('hid'); bf = false; }; loader_opn = function ( tx = null ) { tx = tx || `Por favor aguarde...`; zen_loader_in.querySelector('p').innerHTML = tx; zen_loader.className = "opn"; }; }); document.body.addEventListener('click', function (event) { let u, uc; if ( event.target.tagName.toLowerCase() == "a" && !event.target.download && ( !event.target.target || event.target.target == "_self" ) ) { event.preventDefault(); event.stopPropagation(); if ( event.target.dataset.imt ) { //console.log(gi); window.open(gi+"?im="+event.target.dataset.imt); } else if ( event.target.href.substr(-1, 1) != "#" ) { u = new URL(event.target.href); uc = url_clean(u); if ( !event . target . dataset . nuc ) url_change(u.protocol+"//"+u.host+zen_urep+uc.filter(n => n).join('/')); fetch_html(uc); } event.stopPropagation(); } }, false); document.body.addEventListener("submit", async (e) => { let f = e.target, u = f.dataset.action, // página de destino do form - se undefined deixa o form submeter normalmente sem intervenção do js s = f.dataset.stop, // se true anula o submit t = f.dataset.totop, // reset do scroll vertical ( top ) do elemento t l = f.dataset.ld, // loader personalizado para substituir o loader grande n = f.dataset.nb, // no bf - o formulário não precisa respeitar o bloqueio m = f.dataset.lm || null, // mensagem curtomizada para aparecer no loader response, result; if ( u ) { e.preventDefault(); if ( !s ) { if ( !n ) { if ( bf ) { // Se já houver uma requisição aberta por outro formulário, bloqueia este submit return; } bf = true; } if ( l ) { ld = document.getElementById(l); ld.classList.remove('hid'); } else loader_opn ( null ); //url_change(u.protocol+"//"+u.host+zen_urep+uc[0]); try { response = await fetch(g+"?z="+u, { method: 'POST', body: new FormData(f), credentials: "include", cache: "no-store" }); result = await response.json(); mount_html(result, u); if ( t ) document.getElementById(t).scrollTop = 0; } catch ( e ) { loader_cls(); } } } }); window.addEventListener('popstate', function(e) { if ( window.location.pathname != lastUrl ) { lastUrl = window.location.pathname; fetch_html(url_clean(window.location)); } }); String.prototype.capitalize = function ( ) { return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase(); } if ( window.location.toString().endsWith("/") ) history.replaceState(null, null, window.location.toString().slice(0, -1)); if ( window.location.pathname+"/" == zen_urep ) fetch_html([zen_b]); else fetch_html(url_clean(window.location)); } ) ( ); return { c : c, u : u, g : g, q : q, url_clean : url_clean, url_change : url_change, fetch_html : fetch_html, fetch_css : fetch_css, loader_opn : loader_opn, loader_cls : loader_cls, dlf : dlf, getq : getq } } ) ( );