Passa alla homepage
Passa alla homepage
/*ANFANG Java Script von PA*/ /* === Badge & Offcanvas ==================================================== */ function wisyRefreshBadge(){ fetch('/widgets/checkout/info',{headers:{'X-Requested-With':'XMLHttpRequest'},credentials:'same-origin'}) .then(r=>r.text()).then(html=>{const t=document.querySelector('[data-cart-widget]');if(t) t.innerHTML=html;}) .catch(()=>{}); } function wisyOpenOffcanvas(){ const sels=['[data-offcanvas-cart]','[data-offcanvas-cart="true"]','.header-cart','a[href*="offcanvas-cart"]']; for(const s of sels){const t=document.querySelector(s);if(t){t.dispatchEvent(new MouseEvent('click',{bubbles:true}));return;}} fetch('/checkout/offcanvas',{headers:{'X-Requested-With':'XMLHttpRequest'},credentials:'same-origin'}) .then(r=>r.text()).then(html=>{const wrap=document.createElement('div');wrap.innerHTML=html;document.body.appendChild(wrap);}) .catch(()=>{}); } /* === Modal & Hidden-Formulare einmalig bereitstellen ===================== */ function wisyEnsureModal(){ if(document.getElementById('wisyCoverModal')) return; const b=document.createElement('div'); b.id='wisyCoverBackdrop'; b.className='wisy-modal-backdrop'; const m=document.createElement('div'); m.id='wisyCoverModal'; m.className='wisy-modal'; m.innerHTML = ` ×
Abdeckung wählen
Bitte wähle die Ausführung der Abdeckung:
begehbarbegehbar
PKW-befahrbarPKW-befahrbar
`; document.body.appendChild(b); document.body.appendChild(m); const close=()=>{m.style.display='none'; b.style.display='none';}; b.addEventListener('click',close); m.querySelector('#wisyCoverClose').addEventListener('click',close); } function wisyEnsureForms(){ if(document.getElementById('wisy-global-form-begehbar')) return; const wrap=document.createElement('div'); wrap.style.display='none'; wrap.id='wisy-global-forms'; wrap.innerHTML = `
`; document.body.appendChild(wrap); } /* === Preis-Ermittlung (parallel) ========================================= */ async function wisyExtractPriceTextFromDetail(html){ try{ const doc = new DOMParser().parseFromString(html,'text/html'); const candidates = [ '.product-detail-price .price', '.product-detail-price-amount', '.product-prices .price', '[itemprop="price"]' ]; for(const sel of candidates){ const el = doc.querySelector(sel); if(!el) continue; if(el.tagName === 'META' && el.getAttribute('content')){ // Meta-Preis + Währung formatieren const val = parseFloat(el.getAttribute('content').replace(',', '.')); const cur = doc.querySelector('[itemprop="priceCurrency"]')?.getAttribute('content') || 'EUR'; if(!isNaN(val)){ try{ return new Intl.NumberFormat(undefined,{style:'currency',currency:cur}).format(val); } catch{ return val.toLocaleString() + ' ' + cur; } } } const txt = el.textContent.trim(); if(txt){ return txt; } } }catch(e){} return null; } async function wisyFetchPriceText(variantId){ try{ const res = await fetch(`/detail/${variantId}#`, {credentials:'same-origin', headers:{'X-Requested-With':'XMLHttpRequest'}}); const html = await res.text(); const txt = await wisyExtractPriceTextFromDetail(html); return txt || '—'; }catch(e){ return '—'; } } async function wisyFillPrices(root){ const boxes = Array.from(root.querySelectorAll('.wisy-price-bbl[data-variant-id]')); if(!boxes.length) return; // Ladezustand boxes.forEach(b=>{ const v=b.querySelector('.wisy-price-value'); if(v){ v.textContent='…'; v.classList.add('is-loading'); } }); // Parallel abrufen const tasks = boxes.map(async (b)=>{ const id = b.getAttribute('data-variant-id'); const v = b.querySelector('.wisy-price-value'); const priceText = id ? await wisyFetchPriceText(id) : '—'; if(v){ v.textContent = priceText; v.classList.remove('is-loading'); if(priceText==='—') v.classList.add('is-error'); } }); await Promise.allSettled(tasks); } /* === Rendering & Verhalten ============================================== */ (function(){ wisyEnsureModal(); wisyEnsureForms(); let pendingCtx=null; // {map, ui} function openModal(ctx){ pendingCtx = ctx; // Texte/Icons pro Instanz setzen document.getElementById('wisyCoverTitle').textContent = ctx.ui.title; document.getElementById('wisyCoverSub').textContent = ctx.ui.sub; document.getElementById('wisyLblBegehbar').textContent= ctx.ui.lblB; document.getElementById('wisyLblPkw').textContent = ctx.ui.lblP; const ib=document.getElementById('wisyIconBegehbar'), ip=document.getElementById('wisyIconPkw'); if(ib && ctx.ui.icoB) ib.src = ctx.ui.icoB; if(ip && ctx.ui.icoP) ip.src = ctx.ui.icoP; document.getElementById('wisyCoverBackdrop').style.display='block'; document.getElementById('wisyCoverModal').style.display='block'; } function handleChoice(cover){ if(!pendingCtx) return; const key = pendingCtx.activeFilter + '-' + cover; const ref = pendingCtx.map[key]; document.getElementById('wisyCoverBackdrop').style.display='none'; document.getElementById('wisyCoverModal').style.display='none'; if(!ref){ console.warn('[WISY] fehlende ID für', key); return; } const formId = cover === 'begehbar' ? 'wisy-global-form-begehbar' : 'wisy-global-form-pkw'; const form = document.getElementById(formId); form.querySelector('input[name="lineItems[0][referencedId]"]').value = ref; if(form.requestSubmit){ form.requestSubmit(); } else { form.submit(); } setTimeout(function(){ wisyRefreshBadge(); wisyOpenOffcanvas(); }, 250); try{ localStorage.setItem('wisyCartOpen','1'); }catch(e){} setTimeout(function(){ window.location.href = '/detail/' + ref + '#'; }, 900); } document.addEventListener('click',function(e){ const c=e.target.closest('.wisy-choice'); if(!c) return; handleChoice(c.getAttribute('data-cover')); }); document.addEventListener('DOMContentLoaded',function(){ try{ if(localStorage.getItem('wisyCartOpen')==='1'){ localStorage.removeItem('wisyCartOpen'); setTimeout(function(){ wisyRefreshBadge(); wisyOpenOffcanvas(); },250); } }catch(e){} }); // Öffentliche Init: rendert alle .wisy-buyrow Container window.wisyInitBuyrows = function(){ document.querySelectorAll('.wisy-buyrow').forEach(function(host){ const ui = { btnText: host.dataset.btnText || 'In den Warenkorb', title : host.dataset.modalTitle || 'Abdeckung wählen', sub : host.dataset.modalSub || 'Bitte wähle die Ausführung der Abdeckung:', lblB : host.dataset.labelBegehbar || 'begehbar', lblP : host.dataset.labelPkw || 'PKW-befahrbar', icoB : host.dataset.iconBegehbar || 'https://wisy-water.com/media/75/cc/15/1763015021/begehbar.png?ts=1763015038', icoP : host.dataset.iconPkw || 'https://wisy-water.com/media/1e/c5/e8/1763015021/pkw-befahrbar.png?ts=1763015048' }; const map = { 'slimrain-begehbar': host.dataset.slimrainBegehbar, 'slimrain-pkw' : host.dataset.slimrainPkw, 'wff100-begehbar' : host.dataset.wff100Begehbar, 'wff100-pkw' : host.dataset.wff100Pkw, 'wff150-begehbar' : host.dataset.wff150Begehbar, 'wff150-pkw' : host.dataset.wff150Pkw }; // Markup mit Preis über dem Button (begehbar) host.innerHTML = `
`; // Klick-Handling (Modal) host.addEventListener('click',function(ev){ const btn=ev.target.closest('.wisy-open-cover'); if(!btn) return; ev.preventDefault(); openModal({map: map, ui: ui, activeFilter: btn.dataset.filter}); }); // Preise parallel laden wisyFillPrices(host); }); }; // Auto-Init if(document.readyState==='loading'){ document.addEventListener('DOMContentLoaded',function(){ window.wisyInitBuyrows(); }); }else{ window.wisyInitBuyrows(); } })(); /*ENDE Java Script von PA*/