(function(k){"object"===typeof exports&&"undefined"!==typeof module?module.exports=k():"function"===typeof define&&define.amd?define([],k):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).OmniFaces=k()})(function(){return function(){function k(q,b,p){function h(c,d){if(!b[c]){if(!q[c]){var f="function"==typeof require&&require;if(!d&&f)return f(c,!0);if(n)return n(c,!0);d=Error("Cannot find module '"+c+"'");throw d.code="MODULE_NOT_FOUND",
d;}d=b[c]={exports:{}};q[c][0].call(d.exports,function(a){return h(q[c][1][a]||a)},d,d.exports,k,q,b,p)}return b[c].exports}for(var n="function"==typeof require&&require,l=0;l<p.length;l++)h(p[l]);return h}return k}()({1:[function(k,q,b){Object.defineProperty(b,"__esModule",{value:!0});b.DeferredScript=void 0;const p=k("./Util");(function(h){function n(d){if(!(0>d||d>=l.length)){var f=l[d];p.Util.loadScript(f.url,f.crossorigin,f.integrity,f.begin,f.success,f.error,function(){n(d+1)})}}const l=[];
class c{constructor(d,f,a,e,g,m){this.url=d;this.crossorigin=f;this.integrity=a;this.begin=e;this.success=g;this.error=m}}h.add=function(d,f,a,e,g,m){l.push(new c(d,f,a,e,g,m));1==l.length&&p.Util.addOnloadListener(function(){n(0)})}})(b.DeferredScript||(b.DeferredScript={}))},{"./Util":12}],2:[function(k,q,b){Object.defineProperty(b,"__esModule",{value:!0});b.Form=void 0;const p=k("./OmniFaces"),h=k("./OmniFaces"),n=k("./Util");(function(l){n.Util.addOnloadListener(function(){const c=window.faces;
if(c){const d=c.ajax.request;c.ajax.request=function(f,a,e){const g=c.getViewState;c.getViewState=function(m){const r=g(m);if("true"!==m.dataset.partialsubmit)return r;m=e?.execute;if(!m||m.includes("@form")||m.includes("@all"))return r;let t=[],u=[];m.includes("@none")||(t=m.replace("@this",f instanceof HTMLElement?f.id:f).split(" "),u=t.map(encodeURIComponent));u.push(p.VIEW_STATE_PARAM,h.CLIENT_WINDOW_PARAM);const y=[];r.replace(/([^=&]+)=([^&]*)/g,function(v,x,z){if(!(v=u.includes(x)))a:{var w=
t;const A=x.replace(/%3A/g,"\\:");try{for(const B of w){const C=document.getElementById(B);if(C&&C.querySelector("[name='"+A+"']")){v=!0;break a}}}catch(B){console.warn(`Cannot determine if ${w} contains child ${A}`,B)}v=!1}v&&y.push(`${x}=${z}`)});return y.join("&")};d(f,a,e)}}})})(b.Form||(b.Form={}))},{"./OmniFaces":7,"./Util":12}],3:[function(k,q,b){Object.defineProperty(b,"__esModule",{value:!0});b.GraphicImage=void 0;const p=k("./Util");(function(h){function n(){return document.querySelectorAll("img[src][data-src][data-lazy]")}
function l(c){const d=c.dataset;d.lazy&&d.src&&(c.src=d.src);delete d.src;delete d.lazy}p.Util.addOnloadListener(function(){const c=n();if(0!=c.length)if(window.IntersectionObserver){const d=new IntersectionObserver(function(f){f.forEach(function(a){a.isIntersecting&&a.target instanceof HTMLImageElement&&(a=a.target,l(a),d.unobserve(a))})});c.forEach(function(f){d.observe(f)})}else{let d;const f=function(){d&&clearTimeout(d);d=setTimeout(function(){const a=n(),e=window.innerHeight+window.pageYOffset;
for(var g=0;g<a.length;g++){const m=a[g];m.offsetTop<e&&l(m)}0==n().length&&(p.Util.removeEventListener(window,"resize orientationChange",f),p.Util.removeEventListener(document,"scroll",f))},50)};p.Util.addEventListener(window,"resize orientationChange",f);p.Util.addEventListener(document,"scroll",f)}})})(b.GraphicImage||(b.GraphicImage={}))},{"./Util":12}],4:[function(k,q,b){Object.defineProperty(b,"__esModule",{value:!0});b.HashParam=void 0;const p=k("./OmniFaces"),h=k("./Util");(function(n){function l(){if(!d){const f=
{execute:c,hash:window.location.hash.substring(1)};f[p.EVENT]="setHashParamValues";window.faces.ajax.request(h.Util.getFacesForm(),null,f)}}let c,d;n.init=function(f){c=f;h.Util.getFacesForm()&&(window.location.hash&&l(),h.Util.addEventListener(window,"hashchange",l))};n.update=function(f,a){d=!0;const e=window.location;var g=e.hash;g&&"#"==g.charAt(0)&&(g=g.substring(1));f=h.Util.updateParameter(g,f,a);f!=g&&((g=window.history)&&g.pushState&&(a=e.href.split(/#/,2)[0]+(f?"#":"")+f,g.pushState(null,
document.title,a)),e.hash!=f&&(e.hash=f));d=!1}})(b.HashParam||(b.HashParam={}))},{"./OmniFaces":7,"./Util":12}],5:[function(k,q,b){Object.defineProperty(b,"__esModule",{value:!0});b.Highlight=void 0;const p=k("./Util");(function(h){function n(){p.Util.removeEventListener(this,"click input",n);const c=this.getAttribute(h.DATA_HIGHLIGHT_CLASS);if(c){this.removeAttribute(h.DATA_HIGHLIGHT_CLASS);this.classList.remove(c);let d=this.getAttribute(h.DATA_HIGHLIGHT_LABEL);d&&(this.removeAttribute(h.DATA_HIGHLIGHT_LABEL),
d=l[this.id],d.classList.remove(c))}}h.DATA_HIGHLIGHT_CLASS="data-omnifaces-highlight-class";h.DATA_HIGHLIGHT_LABEL="data-omnifaces-highlight-label";let l;h.apply=function(c,d,f){var a=document.getElementsByTagName("LABEL"),e={};for(const g of Array.from(a))(a=g.htmlFor)&&(e[a]=g);l=e;for(let g of c)if(e=g,c=document.getElementById(e),c||(e=document.getElementsByName(e))&&e.length&&(c=e[0]),c){c.classList.add(d);c.setAttribute(h.DATA_HIGHLIGHT_CLASS,d);if(e=l[c.id])e.classList.add(d),c.setAttribute(h.DATA_HIGHLIGHT_LABEL,
"true");f&&(c.focus(),f=!1);p.Util.addEventListener(c,"click input",n)}}})(b.Highlight||(b.Highlight={}))},{"./Util":12}],6:[function(k,q,b){Object.defineProperty(b,"__esModule",{value:!0});b.InputFile=void 0;const p=k("./OmniFaces");(function(h){h.validate=function(n,l,c,d){if(!window.FileReader)return!0;document.getElementById(c).innerHTML="";for(c=0;c<l.files.length;c++){const f=l.files[c];if(f.size>d){d=f.name;let a;window.mojarra&&(a=l.form.enctype,l.form.enctype="application/x-www-form-urlencoded");
l.type="text";l.type="file";d={fileName:d};d[p.EVENT]="validationFailed";window.faces.ajax.request(l.id,n,d);a&&(l.form.enctype=a);return!1}}return!0}})(b.InputFile||(b.InputFile={}))},{"./OmniFaces":7}],7:[function(k,q,b){Object.defineProperty(b,"__esModule",{value:!0});b.GraphicImage=b.ServiceWorker=b.ScriptParam=b.HashParam=b.Form=b.InputFile=b.Push=b.Unload=b.DeferredScript=b.Highlight=b.Util=b.CLIENT_WINDOW_PARAM=b.VIEW_STATE_PARAM=b.EVENT=void 0;b.EVENT="omnifaces.event";b.VIEW_STATE_PARAM=
"jakarta.faces.ViewState";b.CLIENT_WINDOW_PARAM="jakarta.faces.ClientWindow";var p=k("./Util");Object.defineProperty(b,"Util",{enumerable:!0,get:function(){return p.Util}});var h=k("./Highlight");Object.defineProperty(b,"Highlight",{enumerable:!0,get:function(){return h.Highlight}});var n=k("./DeferredScript");Object.defineProperty(b,"DeferredScript",{enumerable:!0,get:function(){return n.DeferredScript}});var l=k("./Unload");Object.defineProperty(b,"Unload",{enumerable:!0,get:function(){return l.Unload}});
var c=k("./Push");Object.defineProperty(b,"Push",{enumerable:!0,get:function(){return c.Push}});var d=k("./InputFile");Object.defineProperty(b,"InputFile",{enumerable:!0,get:function(){return d.InputFile}});var f=k("./Form");Object.defineProperty(b,"Form",{enumerable:!0,get:function(){return f.Form}});var a=k("./HashParam");Object.defineProperty(b,"HashParam",{enumerable:!0,get:function(){return a.HashParam}});var e=k("./ScriptParam");Object.defineProperty(b,"ScriptParam",{enumerable:!0,get:function(){return e.ScriptParam}});
var g=k("./ServiceWorker");Object.defineProperty(b,"ServiceWorker",{enumerable:!0,get:function(){return g.ServiceWorker}});var m=k("./GraphicImage");Object.defineProperty(b,"GraphicImage",{enumerable:!0,get:function(){return m.GraphicImage}})},{"./DeferredScript":1,"./Form":2,"./GraphicImage":3,"./HashParam":4,"./Highlight":5,"./InputFile":6,"./Push":8,"./ScriptParam":9,"./ServiceWorker":10,"./Unload":11,"./Util":12}],8:[function(k,q,b){Object.defineProperty(b,"__esModule",{value:!0});b.Push=void 0;
const p=k("./Util");(function(h){function n(a){l(a).open()}function l(a){const e=d[a];if(e)return e;throw Error(`Unknown channel: ${a}`);}const c=window.location.protocol.replace("http","ws")+"//",d={};class f{constructor(a,e,g,m,r,t,u){this.url=a;this.channel=e;this.onopen=g;this.onmessage=m;this.onerror=r;this.onclose=t;this.behaviors=u}open(){const a=this;this.socket&&1==this.socket.readyState||(this.socket=new WebSocket(this.url),this.socket.onopen=()=>{if(null==a.reconnectAttempts)a.onopen(a.channel);
a.reconnectAttempts=0},this.socket.onmessage=e=>{const g=JSON.parse(e.data);a.onmessage(g,a.channel,e);a.behaviors[g]?.forEach(m=>m())},this.socket.onclose=e=>{if(!a.socket||1E3==e.code&&"Expired"==e.reason||1008==e.code&&"Unknown channel"==e.reason||null==a.reconnectAttempts||25<=a.reconnectAttempts)a.onclose(e.code,a.channel,e);else a.onerror(e.code,a.channel,e),setTimeout(a.open.bind(a),500*a.reconnectAttempts++)})}close(){if(this.socket){const a=this.socket;this.reconnectAttempts=this.socket=
null;a.close()}}}h.init=function(a,e,g,m,r,t,u,y){t=p.Util.resolveFunction(t);const v=e.split(/\?/)[0];if(window.WebSocket){if(!d[v]){a=a??"";const x=!a||a.startsWith("/")?window.location.host:a.startsWith(":")?window.location.hostname:"";d[v]=new f(`${c}${x}${a}${"/omnifaces.push"}/`+e,v,p.Util.resolveFunction(g),p.Util.resolveFunction(m),p.Util.resolveFunction(r),t,u)}y&&n(v)}else t(-1,v)};h.open=n;h.close=function(a){l(a).close()}})(b.Push||(b.Push={}))},{"./Util":12}],9:[function(k,q,b){Object.defineProperty(b,
"__esModule",{value:!0});b.ScriptParam=void 0;const p=k("./OmniFaces"),h=k("./Util");(function(n){n.run=function(l,c){const d=h.Util.getFacesForm();if(d){var f={};for(let r in c){var a=r,e=JSON,g=e.stringify;a:{var m=c[r];if(!(m instanceof Object))break a;const t={};for(let u in m)m[u]instanceof Function||m[u]instanceof Object||(t[u]=m[u]);m=t}f[a]=g.call(e,m)}f.execute=l;f[p.EVENT]="setScriptParamValues";window.faces.ajax.request(d,null,f)}}})(b.ScriptParam||(b.ScriptParam={}))},{"./OmniFaces":7,
"./Util":12}],10:[function(k,q,b){Object.defineProperty(b,"__esModule",{value:!0});b.ServiceWorker=void 0;const p=k("./OmniFaces");(function(h){h.init=function(n,l){navigator.serviceWorker&&(navigator.serviceWorker.register(n,{scope:l}),navigator.serviceWorker.addEventListener("message",function(c){c.data&&c.data.type==p.EVENT&&window.dispatchEvent(new CustomEvent(c.data.name,{detail:c.data.detail}))}))}})(b.ServiceWorker||(b.ServiceWorker={}))},{"./OmniFaces":7}],11:[function(k,q,b){Object.defineProperty(b,
"__esModule",{value:!0});b.Unload=void 0;const p=k("./OmniFaces"),h=k("./OmniFaces"),n=k("./Util");(function(l){let c,d;l.init=function(f){if(window.XMLHttpRequest){if(null==c){if(!n.Util.getFacesForm())return;n.Util.addEventListener(window,"onbeforeunload"in window&&!window.onbeforeunload?"beforeunload":"onpagehide"in window?"pagehide":"unload",function(){if(d)d=!1;else try{const a=n.Util.getFacesForm(),e=a.action,g=p.EVENT+"=unload&id="+c+"&"+h.VIEW_STATE_PARAM+"="+encodeURIComponent(a[h.VIEW_STATE_PARAM].value);
if(navigator.sendBeacon)navigator.sendBeacon(e,new Blob([g],{type:"application/x-www-form-urlencoded"}));else{const m=new XMLHttpRequest;m.open("POST",e,!1);m.setRequestHeader("X-Requested-With","XMLHttpRequest");m.setRequestHeader("Content-Type","application/x-www-form-urlencoded");m.send(g)}}catch(a){}});n.Util.addSubmitListener(function(){d=!0})}c=f;d=!1}};l.disable=function(){d=!0};l.reenable=function(){d=!1}})(b.Unload||(b.Unload={}))},{"./OmniFaces":7,"./Util":12}],12:[function(k,q,b){Object.defineProperty(b,
"__esModule",{value:!0});b.Util=void 0;const p=k("./OmniFaces");(function(h){function n(a,e,g){d(a,"addEventListener",e,g)}function l(a){window.jQuery?window.jQuery(a):"complete"===document.readyState?setTimeout(a):n(window,"load",a)}function c(a){return"function"===typeof a?a:window[a]??(()=>{})}function d(a,e,g,m){g.trim().split(/\s+/).forEach(r=>a[e]?.(r,m))}function f(a,e,g){const m=a[e];m&&(a[e]=function(...r){g();return m.apply(this,r)})}h.addEventListener=n;h.removeEventListener=function(a,
e,g){d(a,"removeEventListener",e,g)};h.addOnloadListener=l;h.addSubmitListener=function(a){n(document,"submit",a);window.mojarra&&f(window.mojarra,"cljs",a);window.myfaces&&f(window.myfaces.oam,"submitForm",a);window.PrimeFaces&&f(window.PrimeFaces,"addSubmitParam",a)};h.resolveFunction=c;h.getFacesForm=function(){var a=Array.from(document.forms).find(e=>e[p.VIEW_STATE_PARAM]);if(a)return a;(a=window.faces)&&"Development"!==a.getProjectStage()||console.error?.("OmniFaces: Cannot find a Faces form in the document. Please add one.");
return null};h.updateParameter=function(a,e,g){a=new URLSearchParams(a);g?a.set(e,g):a.delete(e);return a.toString()};h.loadScript=function(a,e,g,m,r,t,u){const y=c(m),v=c(r),x=c(t),z=c(u),w=document.createElement("script"),A=document.head??document.documentElement;w.async=!0;w.src=a;w.setAttribute("crossorigin",e||"anonymous");w.setAttribute("integrity",g||"");w.onerror=()=>{x();z()};w.onload=()=>{v();z()};l(()=>{y();A.appendChild(w)})}})(b.Util||(b.Util={}))},{"./OmniFaces":7}]},{},[7])(7)});
