Follow the links below to download our app, and thank you for shopping at Piggly Wiggly!
Check out this week's deals!
(function () { const button = document.getElementById( "pw-weekly-ad-button" ); const overlay = document.getElementById( "pw-ad-overlay" ); const modal = document.getElementById( "pw-ad-modal" ); const closeButton = document.getElementById( "pw-ad-close" ); let lastFocusedElement = null; const FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]), input, select, textarea, [tabindex]:not([tabindex="-1"])'; function getFocusableEls() { return Array.from( modal.querySelectorAll(FOCUSABLE_SELECTOR) ).filter(function (el) { return el.offsetParent !== null; }); } /* ================================ OPEN POPUP Page scrolling remains enabled. ================================ */ button.addEventListener( "click", function () { lastFocusedElement = document.activeElement; overlay.classList.add( "pw-ad-open" ); overlay.setAttribute( "aria-hidden", "false" ); closeButton.focus(); document.addEventListener( "keydown", onKeydown ); } ); /* ================================ CLOSE POPUP ================================ */ function closePopup() { overlay.classList.remove( "pw-ad-open" ); overlay.setAttribute( "aria-hidden", "true" ); document.removeEventListener( "keydown", onKeydown ); if ( lastFocusedElement && typeof lastFocusedElement.focus === "function" ) { lastFocusedElement.focus(); } else { button.focus(); } } closeButton.addEventListener( "click", closePopup ); /* ================================ CLICK OUTSIDE POPUP ================================ */ overlay.addEventListener( "click", function (event) { if ( event.target === overlay ) { closePopup(); } } ); /* ================================ ESCAPE KEY + FOCUS TRAP ================================ */ function onKeydown(event) { if ( event.key === "Escape" && overlay.classList.contains( "pw-ad-open" ) ) { closePopup(); return; } if (event.key === "Tab") { const focusable = getFocusableEls(); if (focusable.length === 0) return; const first = focusable[0]; const last = focusable[focusable.length - 1]; if ( event.shiftKey && document.activeElement === first ) { event.preventDefault(); last.focus(); } else if ( !event.shiftKey && document.activeElement === last ) { event.preventDefault(); first.focus(); } } } })();