// DUMB Popup functionality const BACKDROP_ID = 'dumb-modal-backdrop'; const MODAL_ID = 'dumb-modal'; const CLOSE_ID = 'dumb-close'; const LATER_ID = 'dumb-later'; const FORM_ID = 'dumb-form'; const EMAIL_ID = 'dumb-email'; const MSG_ID = 'dumb-msg'; const STORAGE_KEY = 'dumb_popup_snooze_until'; const qs = (id) => document.getElementById(id); function snooze(days = 7) { const until = Date.now() + days * 24 * 60 * 60 * 1000; localStorage.setItem(STORAGE_KEY, String(until)); } function shouldShow() { const v = localStorage.getItem(STORAGE_KEY); return !v || Date.now() > Number(v); } function openModal() { const backdrop = qs(BACKDROP_ID); const modal = qs(MODAL_ID); if (!backdrop || !modal) return; backdrop.classList.remove('dumb-hidden'); backdrop.setAttribute('aria-hidden', 'false'); setTimeout(() => { const email = qs(EMAIL_ID); (email || modal).focus(); }, 10); } function closeModal() { const backdrop = qs(BACKDROP_ID); if (!backdrop) return; backdrop.classList.add('dumb-hidden'); backdrop.setAttribute('aria-hidden', 'true'); } function handleFormSubmit(e) { e.preventDefault(); const msg = qs(MSG_ID); const submitBtn = e.target.querySelector('.dumb-cta'); // Show loading state const originalText = submitBtn.textContent; submitBtn.textContent = 'Processing...'; submitBtn.disabled = true; // Show success message after a delay setTimeout(() => { if (msg) { msg.style.display = 'block'; msg.textContent = 'Thanks! You will be notified when we launch.'; } // Snooze for 180 days (successfully registered) snooze(180); // Close modal after showing success setTimeout(() => { closeModal(); }, 1500); }, 1000); } function handleCloseClick() { snooze(30); // Snooze for 30 days when closed closeModal(); } function handleLaterClick() { snooze(7); // Snooze for 7 days when "remind me later" closeModal(); } function init() { console.log('DUMB popup initialized'); const closeBtn = qs(CLOSE_ID); const laterBtn = qs(LATER_ID); const form = qs(FORM_ID); if (closeBtn) { closeBtn.addEventListener('click', handleCloseClick); } if (laterBtn) { laterBtn.addEventListener('click', handleLaterClick); } if (form) { form.addEventListener('submit', handleFormSubmit); } // Auto-show popup if it should be shown if (shouldShow()) { console.log('Showing popup after delay...'); setTimeout(openModal, 1200); } else { console.log('Popup is snoozed until:', new Date(Number(localStorage.getItem(STORAGE_KEY)))); } // Global function to manually open modal (for testing) window.__openDumbModal = openModal; } function teardown() { console.log('DUMB popup teardown'); const closeBtn = qs(CLOSE_ID); const laterBtn = qs(LATER_ID); const form = qs(FORM_ID); if (closeBtn) { closeBtn.removeEventListener('click', handleCloseClick); } if (laterBtn) { laterBtn.removeEventListener('click', handleLaterClick); } if (form) { form.removeEventListener('submit', handleFormSubmit); } // Close modal if open closeModal(); } // Export functions export { init, teardown };