1(function () { 2 function byId(id) { return document.getElementById(id); } 3 4 function sanitizeText(value, maxLen) { 5 return String(value || '') 6 .replace(/<[^>]*>/g, ' ') 7 .replace(/[\u0000-\u001F\u007F]/g, ' ') 8 .replace(/[<>`]/g, '') 9 .replace(/\s+/g, ' ') 10 .trim() 11 .slice(0, maxLen || 200); 12 } 13 14 function sanitizeEmail(value) { 15 var email = sanitizeText(value, 200).toLowerCase(); 16 if (!/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9-]+)+$/i.test(email)) { 17 return ''; 18 } 19 return email; 20 } 21 22 window.pecExporterSite = window.pecExporterSite || {}; 23 window.pecExporterSite.sanitizeText = sanitizeText; 24 window.pecExporterSite.sanitizeEmail = sanitizeEmail; 25 26 function track(name, params) { 27 if (window.pecExporterSite && typeof window.pecExporterSite.trackEvent === 'function') { 28 window.pecExporterSite.trackEvent(name, params || {}); 29 } 30 } 31 32 var mobileToggle = byId('mobileMenuToggle'); 33 var mobileMenu = byId('mobileMenu'); 34 if (mobileToggle && mobileMenu) { 35 mobileToggle.addEventListener('click', function () { 36 mobileMenu.classList.toggle('hidden'); 37 track('mobile_menu_toggle', { 38 menu_state: mobileMenu.classList.contains('hidden') ? 'closed' : 'open' 39 }); 40 }); 41 } 42 43 var yearNode = document.querySelector('[data-current-year]'); 44 if (yearNode) yearNode.textContent = String(new Date().getFullYear()); 45 46 var leadForm = byId('leadForm'); 47 if (leadForm) { 48 var siteConfig = window.PEC_EXPORTER_SITE_CONFIG || {}; 49 var leadEndpoint = String(siteConfig.leadEndpoint || '').trim(); 50 var status = byId('leadFormStatus'); 51 var submitBtn = byId('leadFormSubmit'); 52 leadForm.addEventListener('submit', function (ev) { 53 ev.preventDefault(); 54 var name = sanitizeText((byId('leadName') || {}).value || '', 160); 55 var email = sanitizeEmail((byId('leadEmail') || {}).value || ''); 56 var category = sanitizeText((byId('leadCategory') || {}).value || '', 80); 57 var rawComment = sanitizeText((byId('leadComment') || {}).value || '', 900); 58 var comment = sanitizeText((category ? ('Categoria: ' + category + '. ') : '') + rawComment, 1000); 59 60 if (!email) { 61 if (status) status.textContent = 'Inserisci un indirizzo email valido.'; 62 track('lead_form_error', { 63 error_type: 'invalid_email', 64 form_id: 'leadForm' 65 }); 66 return; 67 } 68 if (!leadEndpoint) { 69 if (status) status.textContent = 'Endpoint contatti non configurato.'; 70 track('lead_form_error', { 71 error_type: 'missing_endpoint', 72 form_id: 'leadForm' 73 }); 74 return; 75 } 76 77 if (submitBtn) submitBtn.disabled = true; 78 if (status) status.textContent = 'Invio in corso...'; 79 track('lead_form_submit', { 80 form_id: 'leadForm', 81 has_name: Boolean(name), 82 has_comment: Boolean(comment) 83 }); 84 85 fetch(leadEndpoint, { 86 method: 'POST', 87 headers: { 88 'Content-Type': 'application/json', 89 'Accept': 'application/json' 90 }, 91 body: JSON.stringify({ 92 action: 'save-lead', 93 name: name, 94 email: email, 95 comment: comment, 96 category: category, 97 source: 'marketing-site', 98 page: (window.location && window.location.pathname) || '' 99 }) 100 }) 101 .then(function (res) { return res.json().catch(function () { return {}; }).then(function (body) { return { ok: res.ok, body: body }; }); }) 102 .then(function (result) { 103 if (!result.ok || !result.body || !result.body.ok) { 104 throw new Error((result.body && result.body.error) || 'Errore di salvataggio'); 105 } 106 if (status) status.textContent = 'Grazie. Ti contatteremo a breve.'; 107 track('generate_lead', { 108 form_id: 'leadForm', 109 lead_source: 'marketing-site', 110 has_comment: Boolean(comment) 111 }); 112 leadForm.reset(); 113 }) 114 .catch(function (err) { 115 if (status) status.textContent = 'Impossibile inviare ora. Riprova più tardi. (' + (err && err.message ? err.message : 'errore') + ')'; 116 track('lead_form_error', { 117 error_type: 'submit_failed', 118 form_id: 'leadForm' 119 }); 120 }) 121 .finally(function () { 122 if (submitBtn) submitBtn.disabled = false;
123 }); 124 }); 125 } 126})();
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.