Не Просто Торт
ЗАМОВИТИ ТОРТ
Індивідуальне оформлення вашого солодкого замовлення
ФОРМА ТОРТА
ЯРУСИ ТОРТА
СМАК
КРЕМ
ВСТАВКИ В ТОРТ
ДЕКОР
Передоплата: 200 грн
кг
Вартість за кг: 850 грн
`; } function initPrintWindow(win) { const shareBtn = win.document.getElementById('nptInnerShareBtn'); const printBtn = win.document.getElementById('nptInnerPrintBtn');if (printBtn) { printBtn.addEventListener('click', function() { win.print(); }); }if (shareBtn) { shareBtn.addEventListener('click', async function() { try { if (win.navigator.share) { await win.navigator.share({ title: 'Замовлення торта — Не Просто Торт', text: 'Замовлення торта — Не Просто Торт', url: win.location.href }); } else { win.print(); } } catch (e) {} }); } }function openPrintOrShare(form) { const weightInput = form.querySelector('.npt-weight-input'); const totalInput = form.querySelector('.npt-total-price'); const weightNum = normalizeWeightValue(weightInput ? weightInput.value : ''); if (totalInput && !totalInput.value && weightNum > 0) { totalInput.value = formatTotal(weightNum); }const html = buildPrintableHtml(form); const w = window.open('', '_blank');if (!w) { alert('Браузер заблокував нове вікно. Дозвольте спливаючі вікна або скористайтеся звичайним друком.'); return; }w.document.open(); w.document.write(html); w.document.close();const afterLoad = function() { initPrintWindow(w); w.focus();const isMobile = /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent); if (!isMobile) { setTimeout(() => { try { w.print(); } catch(e) {} }, 500); } };if (w.document.readyState === 'complete') { afterLoad(); } else { w.onload = afterLoad; } }function initCakeForm(form) { if (!form || form.dataset.nptInit === '1') return; form.dataset.nptInit = '1';const weightInput = form.querySelector('.npt-weight-input'); const totalInput = form.querySelector('.npt-total-price'); const submitBtn = form.querySelector('.npt-submit-btn'); const printBtn = form.querySelector('.npt-print-btn'); const successBox = form.querySelector('.npt-success-message');function calculateTotal() { if (!weightInput || !totalInput) return; const weight = normalizeWeightValue(weightInput.value); totalInput.value = weight > 0 ? formatTotal(weight) : ''; }if (weightInput) { ['input', 'change', 'keyup'].forEach(evt => { weightInput.addEventListener(evt, calculateTotal); }); calculateTotal(); }if (printBtn) { printBtn.addEventListener('click', function() { calculateTotal(); openPrintOrShare(form); }); }form.addEventListener('submit', function(e) { e.preventDefault(); calculateTotal();submitBtn.disabled = true; submitBtn.textContent = 'Надсилання...';const formData = new FormData(form);fetch(AJAX_URL, { method: 'POST', body: formData }) .then(r => r.text()) .then(res => { if (String(res).trim() === 'OK') { form.querySelectorAll('input, textarea, button').forEach(el => { if ( !el.classList.contains('npt-cake-popup-close') && !el.classList.contains('npt-print-btn') ) { el.disabled = true; } });if (successBox) { successBox.style.display = 'block'; successBox.scrollIntoView({behavior:'smooth', block:'center'}); } } else { alert('Щось пішло не так. Спробуйте ще раз.'); submitBtn.disabled = false; submitBtn.textContent = 'Замовити торт'; } }) .catch(err => { alert('Помилка відправки форми: ' + err); submitBtn.disabled = false; submitBtn.textContent = 'Замовити торт'; }); }); }document.querySelectorAll('.npt-order-sheet').forEach(initCakeForm);const popup = document.getElementById('npt-cake-popup'); if (popup) { const overlay = popup.querySelector('.npt-cake-popup-overlay'); const closeBtn = popup.querySelector('.npt-cake-popup-close');document.querySelectorAll('.npt-open-cake-popup').forEach(btn => { btn.addEventListener('click', function(e) { e.preventDefault(); popup.style.display = 'block'; document.body.style.overflow = 'hidden';const popupForm = popup.querySelector('.npt-order-sheet'); if (popupForm) initCakeForm(popupForm); }); });function closeCakePopup() { popup.style.display = 'none'; document.body.style.overflow = ''; }if (overlay) overlay.addEventListener('click', closeCakePopup); if (closeBtn) closeBtn.addEventListener('click', closeCakePopup); } });