// service-worker-registration.js if ('serviceWorker' in navigator) { window.addEventListener('load', () => { const manifest = document.querySelector('link[rel="manifest"]'); const manifestURL = manifest ? new URL(manifest.href, location.href) : new URL('/', location.href); const basePath = manifestURL.pathname.replace(/manifest\.json.*$/i, ''); // e.g. "/prep-hoops/" // Use a query endpoint so it always hits WordPress/PHP const swUrl = basePath + '?pn_sw=1'; navigator.serviceWorker.register(swUrl, { scope: basePath }) .then(reg => console.log('ServiceWorker registered with scope:', reg.scope)) .catch(err => console.log('ServiceWorker registration failed:', err)); }); } ; class PWAInstall { constructor() { this.deferredPrompt = null; //this.init(); } // Utility function to set an item in localStorage with a timestamp setInstallPromptSeen() { const now = new Date(); const item = { value: 'true', expiry: now.getTime() + (30 * 24 * 60 * 60 * 1000) // Set expiration to 30 days }; localStorage.setItem('installPromptShown', JSON.stringify(item)); } // Utility function to check if the install prompt was shown within the last month isInstallPromptExpired() { const itemStr = localStorage.getItem('installPromptShown'); if (!itemStr) { return true; // No item found, so it is expired } const item = JSON.parse(itemStr); const now = new Date(); if (now.getTime() > item.expiry) { localStorage.removeItem('installPromptShown'); // Clean up expired item return true; // Expired } return false; // Not expired } // Initialize the event listeners and prompt handling init() { if (!window.matchMedia('(display-mode: standalone)').matches && !window.navigator.standalone) { window.addEventListener('beforeinstallprompt', (event) => this.handleBeforeInstallPrompt(event)); // Special handling for iOS devices const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; if (isIOS) { //this.handleIOSPrompt(); } else { //this.handleAndroidPrompt(); } //this.setupInstallButton(); } } // Handle the beforeinstallprompt event handleBeforeInstallPrompt(event) { if (this.isInstallPromptExpired()) { event.preventDefault(); this.deferredPrompt = event; const installOverlay = document.getElementById('install-overlay'); const installButton = document.getElementById('install-button'); if (installOverlay && installButton) { installOverlay.style.display = 'block'; // Show the overlay installButton.classList.remove('hidden'); // Show the install button } } } // Setup the install button event handler setupInstallButton() { const installButton = document.getElementById('install-button'); if (installButton) { installButton.addEventListener('click', async () => this.handleInstallButtonClick(installButton)); } } // Handle install button click async handleInstallButtonClick(installButton) { installButton.classList.add('hidden'); // Hide the button this.deferredPrompt.prompt(); const { outcome } = await this.deferredPrompt.userChoice; if (outcome !== 'accepted') { this.setInstallPromptSeen(); // Set timestamp to avoid prompting again for one month } this.deferredPrompt = null; document.getElementById('install-overlay').style.display = 'none'; // Hide overlay } // Handle iOS-specific prompt handleIOSPrompt() { const iosPrompt = document.getElementById('ios-prompt'); const installOverlay = document.getElementById('install-overlay'); const appleGif = document.getElementById('gif-apple'); if (iosPrompt && installOverlay && this.isInstallPromptExpired()) { appleGif.classList.remove('hidden'); installOverlay.style.display = 'flex'; // Show the overlay iosPrompt.classList.remove('hidden'); // Show iOS prompt this.setInstallPromptSeen(); // Set timestamp to avoid prompting again for one month } } // Handle Android-specific prompt handleAndroidPrompt() { const androidGif = document.getElementById('gif-android'); androidGif.classList.remove('hidden'); } } // Instantiate the class to handle PWA install prompts const pwaInstall = new PWAInstall();; class PWANavigation { constructor() { this.loadingIndicator = document.getElementById('loading-indicator'); this.init(); } init() { if (this.isPWA()) { this.setupNavigationControls(); this.setupLoadingListeners(); this.observePageChanges(); } } isPWA() { const isIOSPWA = window.navigator.standalone === true; const isStandalone = window.matchMedia('(display-mode: standalone)').matches; return isIOSPWA || isStandalone; } showLoading() { this.loadingIndicator?.classList.remove('hidden'); } hideLoading() { this.loadingIndicator?.classList.add('hidden'); } setupLoadingListeners() { let loadingTimeout; const showSpinner = () => { loadingTimeout = setTimeout(() => this.showLoading(), 200); }; const hideSpinner = () => { clearTimeout(loadingTimeout); this.hideLoading(); }; document.addEventListener('click', (event) => { const link = event.target.closest('a'); if ( link && link.origin === window.location.origin && !link.href.startsWith('javascript:') && link.getAttribute('href') !== '#' && link.getAttribute('href') !== 'javascript:void(0)' ) { event.preventDefault(); showSpinner(); setTimeout(() => { window.location.href = link.href; }, 500); } }); window.addEventListener('load', hideSpinner); window.addEventListener('popstate', hideSpinner); } setupNavigationControls() { const pwaNavigation = document.getElementById('pwaNavigation'); if (pwaNavigation) { if (window.history.length > 1) { pwaNavigation.classList.remove('hidden'); } else { pwaNavigation.classList.add('hidden'); } } } observePageChanges() { new MutationObserver(() => this.hideLoading()) .observe(document.body, { childList: true, subtree: true }); } } // Initialize PWA navigation document.addEventListener('DOMContentLoaded', () => new PWANavigation());; /*! This file is auto-generated */ (()=>{var t={507:(t,e,r)=>{"use strict";r.d(e,{A:()=>A});var n=function(t){return"string"!=typeof t||""===t?(console.error("The namespace must be a non-empty string."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(t)||(console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."),!1)};var i=function(t){return"string"!=typeof t||""===t?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(t)?(console.error("The hook name cannot begin with `__`."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(t)||(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)};var o=function(t,e){return function(r,o,s,c=10){const l=t[e];if(!i(r))return;if(!n(o))return;if("function"!=typeof s)return void console.error("The hook callback must be a function.");if("number"!=typeof c)return void console.error("If specified, the hook priority must be a number.");const a={callback:s,priority:c,namespace:o};if(l[r]){const t=l[r].handlers;let e;for(e=t.length;e>0&&!(c>=t[e-1].priority);e--);e===t.length?t[e]=a:t.splice(e,0,a),l.__current.forEach((t=>{t.name===r&&t.currentIndex>=e&&t.currentIndex++}))}else l[r]={handlers:[a],runs:0};"hookAdded"!==r&&t.doAction("hookAdded",r,o,s,c)}};var s=function(t,e,r=!1){return function(o,s){const c=t[e];if(!i(o))return;if(!r&&!n(s))return;if(!c[o])return 0;let l=0;if(r)l=c[o].handlers.length,c[o]={runs:c[o].runs,handlers:[]};else{const t=c[o].handlers;for(let e=t.length-1;e>=0;e--)t[e].namespace===s&&(t.splice(e,1),l++,c.__current.forEach((t=>{t.name===o&&t.currentIndex>=e&&t.currentIndex--})))}return"hookRemoved"!==o&&t.doAction("hookRemoved",o,s),l}};var c=function(t,e){return function(r,n){const i=t[e];return void 0!==n?r in i&&i[r].handlers.some((t=>t.namespace===n)):r in i}};var l=function(t,e,r,n){return function(i,...o){const s=t[e];s[i]||(s[i]={handlers:[],runs:0}),s[i].runs++;const c=s[i].handlers;if(!c||!c.length)return r?o[0]:void 0;const l={name:i,currentIndex:0};return(n?async function(){try{s.__current.add(l);let t=r?o[0]:void 0;for(;l.currentIndex0:Array.from(n.__current).some((t=>t.name===r))}};var u=function(t,e){return function(r){const n=t[e];if(i(r))return n[r]&&n[r].runs?n[r].runs:0}};class h{actions;filters;addAction;addFilter;removeAction;removeFilter;hasAction;hasFilter;removeAllActions;removeAllFilters;doAction;doActionAsync;applyFilters;applyFiltersAsync;currentAction;currentFilter;doingAction;doingFilter;didAction;didFilter;constructor(){this.actions=Object.create(null),this.actions.__current=new Set,this.filters=Object.create(null),this.filters.__current=new Set,this.addAction=o(this,"actions"),this.addFilter=o(this,"filters"),this.removeAction=s(this,"actions"),this.removeFilter=s(this,"filters"),this.hasAction=c(this,"actions"),this.hasFilter=c(this,"filters"),this.removeAllActions=s(this,"actions",!0),this.removeAllFilters=s(this,"filters",!0),this.doAction=l(this,"actions",!1,!1),this.doActionAsync=l(this,"actions",!1,!0),this.applyFilters=l(this,"filters",!0,!1),this.applyFiltersAsync=l(this,"filters",!0,!0),this.currentAction=a(this,"actions"),this.currentFilter=a(this,"filters"),this.doingAction=d(this,"actions"),this.doingFilter=d(this,"filters"),this.didAction=u(this,"actions"),this.didFilter=u(this,"filters")}}var A=function(){return new h}},8770:()=>{}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,r),o.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};(()=>{"use strict";r.r(n),r.d(n,{actions:()=>x,addAction:()=>s,addFilter:()=>c,applyFilters:()=>m,applyFiltersAsync:()=>v,createHooks:()=>t.A,currentAction:()=>y,currentFilter:()=>F,defaultHooks:()=>o,didAction:()=>b,didFilter:()=>k,doAction:()=>f,doActionAsync:()=>p,doingAction:()=>_,doingFilter:()=>g,filters:()=>w,hasAction:()=>d,hasFilter:()=>u,removeAction:()=>l,removeAllActions:()=>h,removeAllFilters:()=>A,removeFilter:()=>a});var t=r(507),e=r(8770),i={};for(const t in e)["default","actions","addAction","addFilter","applyFilters","applyFiltersAsync","createHooks","currentAction","currentFilter","defaultHooks","didAction","didFilter","doAction","doActionAsync","doingAction","doingFilter","filters","hasAction","hasFilter","removeAction","removeAllActions","removeAllFilters","removeFilter"].indexOf(t)<0&&(i[t]=()=>e[t]);r.d(n,i);const o=(0,t.A)(),{addAction:s,addFilter:c,removeAction:l,removeFilter:a,hasAction:d,hasFilter:u,removeAllActions:h,removeAllFilters:A,doAction:f,doActionAsync:p,applyFilters:m,applyFiltersAsync:v,currentAction:y,currentFilter:F,doingAction:_,doingFilter:g,didAction:b,didFilter:k,actions:x,filters:w}=o})(),(window.wp=window.wp||{}).hooks=n})();;