"use strict";
(function (){
const root=document.querySelector('[data-pod-nl-popup]');
if(!root)
return;
const dialog=root.querySelector('.pod-nlp__dialog');
const formRoot=root.querySelector('[data-pod-lead-form]');
const preview=root.getAttribute('data-preview')==='1';
const scriptUrl=root.getAttribute('data-script')||'';
const FLAG='pod_nl_prompt';
const ENG='pod_nl_eng';
const YEAR=365 * 24 * 60 * 60 * 1000;
const SUPPRESS_PATHS=/\/(contact|kontakt|werkenbij|werken-bij|careers|karriere|jobs|offerte-aanvragen|request-a-quote|angebot-anfordern|privacy[a-z-]*|datenschutz[a-z-]*)(\/|$)/i;
let variant='a';
try {
const c=JSON.parse((document.getElementById('pod-lead-config')||{ textContent: '{}' }).textContent||'{}');
if(c&&typeof c.variant==='string')
variant=c.variant;
}
catch (e){
}
function track(event, params){
try {
if(typeof window.gtag==='function')
window.gtag('event', event, Object.assign({ variant: variant }, params));
}
catch (e){
}}
function localStore(){
try {
const s=window.localStorage;
s.setItem('__pod_t', '1');
s.removeItem('__pod_t');
return s;
}
catch (e){
return null;
}}
const store=localStore();
function ssGet(k){
try {
return window.sessionStorage.getItem(k);
}
catch (e){
return null;
}}
function ssSet(k, v){
try {
window.sessionStorage.setItem(k, v);
}
catch (e){
}}
function flagActive(){
if(!store)
return true;
try {
const raw=store.getItem(FLAG);
if(!raw)
return false;
const d=JSON.parse(raw);
return !d||typeof d.t!=='number'||Date.now() - d.t < YEAR;
}
catch (e){
return true;
}}
function setFlag(why){
if(!store)
return;
try {
store.setItem(FLAG, JSON.stringify({ t: Date.now(), why: why }));
}
catch (e){
}}
function intOf(v){
const n=parseInt(v||'0', 10);
return isNaN(n) ? 0:n;
}
const sessionStart=intOf(ssGet('pod_ss'))||Date.now();
let engaged=intOf(ssGet(ENG));
let pageSeconds=0;
let maxScroll=0;
let shown=false;
let prevFocus=null;
let mode='desktop';
function pageViews(){
return intOf(ssGet('pod_pv'));
}
function measureScroll(){
const doc=document.documentElement;
const h=Math.max(doc.scrollHeight, document.body ? document.body.scrollHeight:0);
const ratio=h <=window.innerHeight ? 1:(window.scrollY + window.innerHeight) / h;
if(ratio > maxScroll)
maxScroll=ratio;
}
function isDesktop(){
return window.matchMedia('(min-width: 768px) and (pointer: fine)').matches;
}
function modalsOpen(){
return !!document.querySelector('#pod-engineer-modal.pod-emodal-overlay--open, .pod-phasio-hero-backdrop--visible');
}
function fromOurEmail(){
try {
const ft=JSON.parse(ssGet('pod_lead_ft')||'{}');
return String(ft.utm_medium||'').toLowerCase()==='email'||String(ft.utm_source||'').toLowerCase()==='activecampaign';
}
catch (e){
return false;
}}
function suppressed(){
if(!store||flagActive())
return true;
if(document.body.classList.contains('logged-in'))
return true;
if(SUPPRESS_PATHS.test(window.location.pathname))
return true;
if(document.querySelector('.paywall--active'))
return true;
if(fromOurEmail())
return true;
return false;
}
function warmedUp(){
return Date.now() - sessionStart >=30000&&engaged >=30;
}
let loading=null;
function ensureForm(){
if(window.podLeadForm)
return Promise.resolve();
if(!loading){
loading=new Promise((resolve, reject)=> {
const s=document.createElement('script');
s.src=scriptUrl;
s.async=true;
s.onload=()=> resolve();
s.onerror=()=> {
loading=null;
reject(new Error('form script'));
};
document.head.appendChild(s);
});
}
return loading;
}
function evaluate(){
if(shown||preview||suppressed()||modalsOpen()||!warmedUp())
return;
if(pageViews() >=2&&pageSeconds >=30&&maxScroll >=0.5)
show('engagement');
}
function focusables(){
return Array.prototype.slice.call(dialog.querySelectorAll('a[href], button:not([disabled]), input:not([type="hidden"]):not([tabindex="-1"]), textarea, select, [tabindex]:not([tabindex="-1"])')).filter((el)=> el.offsetParent!==null);
}
function onKey(e){
if(e.key==='Escape'){
e.preventDefault();
close();
return;
}
if(e.key!=='Tab'||mode!=='desktop')
return;
const items=focusables();
if(!items.length)
return;
const first=items[0];
const last=items[items.length - 1];
if(e.shiftKey&&(document.activeElement===first||document.activeElement===dialog)){
e.preventDefault();
last.focus();
}
else if(!e.shiftKey&&document.activeElement===last){
e.preventDefault();
first.focus();
}}
function show(trigger){
if(shown)
return;
shown=true;
if(!preview)
setFlag('shown');
mode=isDesktop() ? 'desktop':'mobile';
root.classList.toggle('pod-nlp--mobile', mode==='mobile');
dialog.setAttribute('aria-modal', mode==='desktop' ? 'true':'false');
prevFocus=document.activeElement;
root.hidden=false;
window.requestAnimationFrame(()=> root.classList.add('is-in'));
dialog.focus({ preventScroll: true });
document.addEventListener('keydown', onKey, true);
track('pod_newsletter_prompt_shown', { trigger: trigger, placement: mode });
ensureForm()
.then(()=> {
if(window.podLeadForm&&formRoot)
window.podLeadForm.open(formRoot, 'newsletter-popup');
})
.catch(()=> {
close();
});
}
function close(){
if(root.hidden)
return;
root.classList.remove('is-in');
root.hidden=true;
document.removeEventListener('keydown', onKey, true);
if(window.podLeadForm&&formRoot)
window.podLeadForm.close(formRoot);
if(prevFocus&&typeof prevFocus.focus==='function')
prevFocus.focus({ preventScroll: true });
}
root.addEventListener('click', (e)=> {
if(e.target.closest('[data-nlp-close]')){
e.preventDefault();
close();
}});
root.addEventListener('pod:lead-submitted', ()=> {
const decline=root.querySelector('.pod-nlp__decline');
if(decline)
decline.hidden=true;
});
if(preview){
window.setTimeout(()=> {
if(!modalsOpen())
show('preview');
}, 1000);
return;
}
if(suppressed())
return;
window.addEventListener('scroll', measureScroll, { passive: true });
measureScroll();
window.setInterval(()=> {
if(document.visibilityState!=='visible'||shown)
return;
pageSeconds++;
engaged++;
ssSet(ENG, String(engaged));
if(engaged >=20)
ensureForm().catch(()=> undefined);
evaluate();
}, 1000);
document.addEventListener('mouseout', (e)=> {
if(shown||e.relatedTarget||e.clientY > 0||!isDesktop())
return;
if(suppressed()||modalsOpen()||!warmedUp())
return;
show('exit');
});
})();