1(function () { 2 var openBtn = document.getElementById('openCalcIframe'); 3 var popup = document.getElementById('calcIframePopup'); 4 var closeBtn = document.getElementById('closeCalcIframe'); 5 var frame = document.getElementById('calcIframeFrame'); 6 if (!openBtn || !popup || !closeBtn || !frame) return; 7 8 var pendingProducts = null; 9 var pendingOrigin = window.location.origin; 10 var pendingSelectedBase = null; 11 var pendingSelectedSkuId = null; 12 13 function parseProducts(raw) { 14 try { 15 var parsed = JSON.parse(raw || '{}'); 16 return parsed && typeof parsed === 'object' ? parsed : {}; 17 } catch (e) { 18 return {}; 19 } 20 } 21 22 function postProductsToFrame() { 23 if (!frame.contentWindow || !pendingProducts) return; 24 frame.contentWindow.postMessage({ 25 type: 'calc-products:init', 26 products: pendingProducts, 27 selectedBase: pendingSelectedBase, 28 selectedSkuId: pendingSelectedSkuId 29 }, pendingOrigin); 30 } 31 32 function handleAddToCartMessage(data) { 33 if (!data || data.type !== 'calc:add-to-cart') return; 34 var payload = { 35 product_id: data.product_id || null, 36 quantity: Number(data.quantity || 0), 37 coloring: data.coloring || null, 38 base: data.base || null, 39 source: data.source || null, 40 packs: Array.isArray(data.packs) ? data.packs : [], 41 liters: Number(data.liters || 0) 42 }; 43 44 window.lastCalcCartPayload = payload; 45 46 var basketItems = (Array.isArray(payload.packs) ? payload.packs : []) 47 .map(function (row) { 48 return { 49 base: payload.base || null, 50 size: Number(row.size || 0), 51 quantity: Number(row.count || 0), 52 price: Number(row.price || 0) 53 }; 54 }) 55 .filter(function (row) { 56 return row.base && isFinite(row.size) && row.size > 0 && isFinite(row.quantity) && row.quantity > 0; 57 }); 58 59 if (!basketItems.length && payload.product_id && payload.quantity > 0) { 60 basketItems.push({ 61 product_id: payload.product_id, 62 quantity: payload.quantity, 63 base: payload.base || null, 64 size: null, 65 price: 0 66 }); 67 } 68 69 try { 70 window.dispatchEvent(new CustomEvent('calc:add-to-cart', { 71 detail: { 72 payload: payload, 73 basketItems: basketItems 74 } 75 })); 76 } catch (e) {} 77 } 78 79 function openPopup() { 80 var src = openBtn.getAttribute('data-iframe-src') || './iframe.php'; 81 var sep = src.indexOf('?') === -1 ? '?' : '&'; 82 var liveSrc = src + sep + 'iframe_v=' + Date.now(); 83 pendingProducts = parseProducts(openBtn.getAttribute('data-products')); 84 pendingSelectedBase = openBtn.getAttribute('data-selected-base') || null; 85 pendingSelectedSkuId = openBtn.getAttribute('data-selected-sku-id') || null; 86 popup.hidden = false; 87 document.body.style.overflow = 'hidden'; 88 frame.setAttribute('src', liveSrc); 89 } 90 91 function closePopup() { 92 popup.hidden = true; 93 document.body.style.overflow = ''; 94 frame.setAttribute('src', 'about:blank'); 95 } 96 97 openBtn.addEventListener('click', openPopup); 98 closeBtn.addEventListener('click', closePopup); 99 popup.addEventListener('click', function (e) { 100 if (e.target && e.target.getAttribute('data-close-popup') === '1') { 101 closePopup(); 102 } 103 }); 104 document.addEventListener('keydown', function (e) { 105 if (e.key === 'Escape' && !popup.hidden) { 106 closePopup(); 107 } 108 }); 109 frame.addEventListener('load', postProductsToFrame); 110 window.addEventListener('message', function (event) {
111 if (event.origin !== pendingOrigin) return; 112 handleAddToCartMessage(event.data || {}); 113 }); 114})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.