1/** 2 * SaporiNostri Core â WhatsApp Widget JS 3 * Gestisce apertura/chiusura popup e consenso GDPR con localStorage. 4 */ 5(function () { 6 'use strict'; 7 8 var GDPR_KEY = 'sn_wa_gdpr_accepted'; 9 10 document.addEventListener('DOMContentLoaded', function () { 11 var widget = document.getElementById('sn-whatsapp-widget'); 12 if (!widget) return; 13 14 var trigger = widget.querySelector('.sn-wa-trigger'); 15 var popup = document.getElementById('sn-wa-popup'); 16 var closeBtn = widget.querySelector('.sn-wa-popup__close'); 17 var cta = document.getElementById('sn-wa-cta'); 18 var gdprCheck = document.getElementById('sn-wa-gdpr-check'); 19 20 var gdprEnabled = widget.getAttribute('data-gdpr') === '1' && 21 typeof snWhatsApp !== 'undefined' && snWhatsApp.gdprEnabled; 22 23 /* GDPR: ripristina consenso salvato */ 24 if (gdprEnabled && gdprCheck) { 25 var accepted = false; 26 try { accepted = localStorage.getItem(GDPR_KEY) === '1'; } catch (e) {} 27 28 if (accepted) { 29 gdprCheck.checked = true; 30 setCTAEnabled(true); 31 } 32 33 gdprCheck.addEventListener('change', function () { 34 var checked = gdprCheck.checked; 35 setCTAEnabled(checked); 36 try { 37 if (checked) { localStorage.setItem(GDPR_KEY, '1'); } 38 else { localStorage.removeItem(GDPR_KEY); } 39 } catch (e) {} 40 }); 41 } else { 42 setCTAEnabled(true); 43 } 44 45 /* Apri / chiudi */ 46 if (trigger) trigger.addEventListener('click', togglePopup); 47 if (closeBtn) closeBtn.addEventListener('click', closePopup); 48 49 document.addEventListener('click', function (e) { 50 if (!widget.contains(e.target)) closePopup(); 51 }); 52 53 document.addEventListener('keydown', function (e) { 54 if (e.key === 'Escape') closePopup(); 55 }); 56 57 /* Blocca click su CTA disabilitata */ 58 if (cta) { 59 cta.addEventListener('click', function (e) { 60 if (cta.classList.contains('is-disabled')) { 61 e.preventDefault(); 62 if (gdprCheck) gdprCheck.focus(); 63 } 64 }); 65 } 66 67 function togglePopup() { 68 widget.classList.contains('is-open') ? closePopup() : openPopup(); 69 } 70 71 function openPopup() { 72 widget.classList.add('is-open'); 73 if (popup) popup.setAttribute('aria-hidden', 'false'); 74 if (trigger) trigger.setAttribute('aria-expanded', 'true'); 75 } 76 77 function closePopup() { 78 widget.classList.remove('is-open'); 79 if (popup) popup.setAttribute('aria-hidden', 'true'); 80 if (trigger) trigger.setAttribute('aria-expanded', 'false'); 81 } 82 83 function setCTAEnabled(enabled) { 84 if (!cta) return; 85 if (enabled) { 86 cta.classList.remove('is-disabled'); 87 cta.setAttribute('aria-disabled', 'false'); 88 cta.removeAttribute('tabindex'); 89 } else { 90 cta.classList.add('is-disabled'); 91 cta.setAttribute('aria-disabled', 'true'); 92 cta.setAttribute('tabindex', '-1'); 93 } 94 } 95 }); 96}());
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.