Recent Content

New

3 Best Reef Safe Sunscreens (PADI Divemaster's Picks)

PADI Divemaster Austin Tuwiner breaks down which sunscreen chemicals harm coral reefs and shares his top 3 reef-safe picks: Stream2Sea, Coral Safe, and Sun Bum.

Blog and articles

Latest articles

/* * Check whether the popup has already appeared * during the current browser session. */ function hasAlreadyShown() { try { return sessionStorage.getItem(STORAGE_KEY) === "1"; } catch (error) { return false; } } /* * Mark the popup as shown for the current session. */ function markAsShown() { try { sessionStorage.setItem(STORAGE_KEY, "1"); } catch (error) { /* * Continue normally if sessionStorage * is unavailable or blocked. */ } } /* * Clear the active delay timer. */ function clearPopupTimer() { if (timer !== null) { window.clearTimeout(timer); timer = null; } } /* * Open the popup smoothly. */ function showPopup() { clearPopupTimer(); if (popupVisible || hasAlreadyShown()) { return; } popupVisible = true; previousActiveElement = document.activeElement; markAsShown(); popup.setAttribute("aria-hidden", "false"); overlay.setAttribute("aria-hidden", "false"); /* * Wait for two animation frames so the browser * registers the hidden state before adding * the visible animation class. */ window.requestAnimationFrame(function () { window.requestAnimationFrame(function () { overlay.classList.add("ei-visible"); popup.classList.add("ei-visible"); }); }); /* * Focus the close button after the animation begins. */ window.setTimeout(function () { closeButton.focus(); }, 450); } /* * Close the popup smoothly. */ function hidePopup() { if (!popupVisible) { return; } popupVisible = false; overlay.classList.remove("ei-visible"); popup.classList.remove("ei-visible"); popup.setAttribute("aria-hidden", "true"); overlay.setAttribute("aria-hidden", "true"); /* * Return keyboard focus to the element * the visitor was using before the popup opened. */ window.setTimeout(function () { if ( previousActiveElement && typeof previousActiveElement.focus === "function" ) { previousActiveElement.focus(); } }, 450); } /* * Start or resume the 30-second timer. * * The timer only runs while the browser tab * is visible to the visitor. */ function startPopupTimer() { if ( popupVisible || hasAlreadyShown() || document.visibilityState === "hidden" || timer !== null ) { return; } timerStartedAt = Date.now(); timer = window.setTimeout(function () { timer = null; remainingTime = 0; showPopup(); }, remainingTime); } /* * Pause the timer when the visitor leaves * or switches away from the browser tab. */ function pausePopupTimer() { if (timer === null) { return; } var elapsedTime = Date.now() - timerStartedAt; remainingTime = Math.max( 0, remainingTime - elapsedTime ); clearPopupTimer(); } /* * Handle browser-tab visibility changes. */ function handleVisibilityChange() { if (hasAlreadyShown()) { clearPopupTimer(); return; } if (document.visibilityState === "hidden") { pausePopupTimer(); return; } if (remainingTime <= 0) { showPopup(); } else { startPopupTimer(); } } /* * Initialize the popup. */ function initializePopup() { overlay.classList.remove("ei-visible"); popup.classList.remove("ei-visible"); popup.setAttribute("aria-hidden", "true"); overlay.setAttribute("aria-hidden", "true"); if (hasAlreadyShown()) { return; } startPopupTimer(); } /* * Close interactions */ closeButton.addEventListener("click", hidePopup); overlay.addEventListener("click", hidePopup); dismissButton.addEventListener("click", hidePopup); /* * Allow the dismiss text to work with Enter or Space. */ dismissButton.addEventListener("keydown", function (event) { if ( event.key === "Enter" || event.key === " " ) { event.preventDefault(); hidePopup(); } }); /* * Close with the Escape key. */ document.addEventListener("keydown", function (event) { if (event.key === "Escape" && popupVisible) { hidePopup(); } }); /* * Pause and resume the timer based on * whether the visitor is actively viewing the page. */ document.addEventListener( "visibilitychange", handleVisibilityChange ); /* * Track CTA clicks. */ ctaButton.addEventListener("click", function () { hidePopup(); if (typeof window.gtag === "function") { window.gtag( "event", "exit_popup_cta_click", { event_category: "Exit Intent", event_label: "Skool Community" } ); } }); /* * Start the delay after the full page, * including images and fonts, has loaded. */ if (document.readyState === "complete") { initializePopup(); } else { window.addEventListener( "load", initializePopup, { once: true } ); } })();