0
    0
    Your Cart
    Your cart is emptyReturn to Shop
    /** * Exit Intent Popup * Displays a popup when user attempts to leave the page */ (function() { 'use strict'; // Configuration const config = { cookieName: 'exit_popup_shown', cookieDays: 1, // Days before popup can show again enabled: true }; // Check if popup should be shown function shouldShowPopup() { if (!config.enabled) return false; // Check if popup was already shown const cookie = getCookie(config.cookieName); return !cookie; } // Set cookie to remember popup was shown function setPopupCookie() { setCookie(config.cookieName, 'true', config.cookieDays); } // Cookie helper functions function setCookie(name, value, days) { const expires = new Date(); expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000)); document.cookie = name + '=' + value + ';expires=' + expires.toUTCString() + ';path=/'; } function getCookie(name) { const nameEQ = name + '='; const ca = document.cookie.split(';'); for (let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) === ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); } return null; } // Show popup function showPopup() { if (!shouldShowPopup()) return; const overlay = document.getElementById('exitPopupOverlay'); const closeBtn = document.getElementById('exitPopupClose'); const form = document.getElementById('exitPopupForm'); const noThanksBtn = document.querySelector('.btn-no'); const yesBtn = document.querySelector('.btn-yes'); // Trigger animation setTimeout(() => { document.querySelector('.exit-popup-overlay').classList.add('show'); console.log('Exit intent popup shown open'); setPopupCookie(); yesBtn.addEventListener('click', function() { document.querySelector('.exit-popup-content.step-1').classList.add('hide'); document.querySelector('.exit-popup-content.step-2').classList.add('show'); }); }, 10); // Close button handler closeBtn.addEventListener('click', closePopup); noThanksBtn.addEventListener('click', closePopup); // Overlay click handler overlay.addEventListener('click', function(e) { if (e.target === overlay) { closePopup(); } }); // Form submission handler form.addEventListener('submit', handleFormSubmit); // Escape key handler document.addEventListener('keydown', handleEscapeKey); // Remember popup was shown //setPopupCookie(); } // Close popup function closePopup() { const overlay = document.getElementById('exitPopupOverlay'); if (overlay) { overlay.classList.remove('show'); setTimeout(() => { overlay.remove(); }, 300); } } // Handle escape key function handleEscapeKey(e) { if (e.key === 'Escape') { closePopup(); } } // Handle form submission function handleFormSubmit(e) { e.preventDefault(); const form = e.target; const emailInput = form.querySelector('input[type="email"]'); const email = emailInput.value; // Here you would typically send the email to your backend console.log('Email submitted:', email); // Show success message (placeholder) alert('Thank you! We\'ll be in touch soon.'); // Close popup closePopup(); } // Detect exit intent function detectExitIntent() { // Desktop: detect mouse leaving viewport document.addEventListener('mouseout', function(e) { if (!e.toElement && !e.relatedTarget) { showPopup(); } }); // Mobile: detect back button or swipe let touchStartY = 0; document.addEventListener('touchstart', function(e) { touchStartY = e.touches[0].clientY; }); document.addEventListener('touchmove', function(e) { const touchEndY = e.touches[0].clientY; const deltaY = touchStartY - touchEndY; // User swiping up (attempting to leave) if (deltaY > 0 && window.scrollY === 0) { showPopup(); } }); } // Initialize when DOM is ready function init() { // Wait a bit to avoid immediate popup setTimeout(() => { detectExitIntent(); }, 3000); } // Start when DOM is ready console.log('Exit intent popup initialized'); if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();