1/** 2 * newsletter.js â Formulário de newsletter do footer 3 * Integração: RD Station (RdIntegration) 4 */ 5 6document.addEventListener('DOMContentLoaded', () => { 7 8 const form = document.querySelector('.footer-newsletter__form'); 9 if (!form) return; 10 11 const input = form.querySelector('.footer-newsletter__input'); 12 const btn = form.querySelector('.footer-newsletter__btn'); 13 const newsletter = document.querySelector('.footer-newsletter__inner'); 14 15 // âââ Validação ââââââââââââââââââââââââââââââââââââââââââââââââ 16 function isValidEmail(email) { 17 return /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email.trim()); 18 } 19 20 // âââ Helpers de UI ââââââââââââââââââââââââââââââââââââââââââââ 21 function getOrCreateErrorEl() { 22 let el = newsletter?.querySelector('.footer-newsletter__error-msg'); 23 if (!el) { 24 el = document.createElement('p'); 25 el.className = 'footer-newsletter__error-msg'; 26 el.setAttribute('role', 'alert'); 27 form.insertAdjacentElement('afterend', el); 28 } 29 return el; 30 } 31 32 function showError(msg) { 33 input?.classList.add('footer-newsletter__input--error'); 34 const errorEl = getOrCreateErrorEl(); 35 errorEl.textContent = msg; 36 errorEl.hidden = false; 37 } 38 39 function clearError() { 40 input?.classList.remove('footer-newsletter__input--error'); 41 const errorEl = newsletter?.querySelector('.footer-newsletter__error-msg'); 42 if (errorEl) { 43 errorEl.textContent = ''; 44 errorEl.hidden = true; 45 } 46 } 47 48 function setLoading(isLoading) { 49 if (!btn) return; 50 btn.disabled = isLoading; 51 btn.textContent = isLoading ? 'Enviando...' : 'Inscrever-se'; 52 } 53 54 function showSuccess() { 55 form.style.transition = 'opacity 0.3s ease'; 56 form.style.opacity = '0'; 57 58 setTimeout(() => { 59 form.style.display = 'none'; 60 clearError(); 61 62 const successEl = document.createElement('p'); 63 successEl.className = 'footer-newsletter__success'; 64 successEl.setAttribute('role', 'status'); 65 successEl.textContent = 'â Pronto! Você receberá nossas novidades em breve.'; 66 form.insertAdjacentElement('afterend', successEl); 67 }, 300); 68 } 69 70 // âââ Limpar erro ao digitar âââââââââââââââââââââââââââââââââââ 71 input?.addEventListener('input', clearError); 72 73 // âââ Submit âââââââââââââââââââââââââââââââââââââââââââââââââââ 74 form.addEventListener('submit', (e) => { 75 e.preventDefault(); 76 clearError(); 77 78 const email = input?.value.trim() ?? ''; 79 80 if (!email) { 81 showError('O e-mail é obrigatório.'); 82 input?.focus(); 83 return; 84 } 85 86 if (!isValidEmail(email)) { 87 showError('Insira um e-mail válido.'); 88 input?.focus(); 89 return; 90 } 91 92 // if (typeof RdIntegration === 'undefined') { 93 // showError('Serviço temporariamente indisponÃvel. Tente novamente.'); 94 // return; 95 // } 96 97 setLoading(true); 98 99 RdIntegration.post({ 100 token: '74ca6e86756c4d6ff84f345b12d482e9', 101 identifier: 'tecidoskite-newsletter', 102 values: { 103 email: email, 104 }, 105 success: function () { 106 setLoading(false); 107 showSuccess(); 108 }, 109 error: function () { 110 setLoading(false); 111 showError('Não foi possÃvel cadastrar. Tente novamente.'); 112 }, 113 }); 114 }); 115 116});
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.