/** * install-app.js — handles the "Installeer app" button in the footer. * * Behavior: * - Hides itself if the user is already running the site as an installed PWA * (display-mode: standalone) or iOS web-app. * - On click, opens a modal with platform-specific instructions: * iOS → "Voeg toe aan beginscherm" via Safari share sheet * Android → PWA install (1-tap if available, else Chrome ⋮-menu instructions) * Desktop → instructions for Chrome/Edge install icon, or native prompt if available * - Listens for `beforeinstallprompt` (Android Chrome / desktop Chromium) and * deferreds it so the modal's "Install as PWA" button can fire it. * * Markup contract: `; document.body.appendChild(m); const close = () => m.remove(); m.querySelector('.install-modal-backdrop').addEventListener('click', close); m.querySelector('[data-close]').addEventListener('click', close); document.addEventListener('keydown', function onEsc(e) { if (e.key === 'Escape') { close(); document.removeEventListener('keydown', onEsc); } }); // If a [data-install-pwa] button is in the modal AND a deferredPrompt is // available: clicking triggers the native install dialog. const pwaBtn = m.querySelector('[data-install-pwa]'); if (pwaBtn) { pwaBtn.addEventListener('click', () => { if (!deferredPrompt) { close(); return; } deferredPrompt.prompt(); deferredPrompt.userChoice.finally(() => { deferredPrompt = null; close(); }); }); } } function iosInstructions() { showModal(`

📲 Installeer op iOS

Om deze site als app op je home-scherm te zetten:

  1. Tik op het deel-icoon onderaan in Safari
  2. Scroll tot je "Voeg toe aan beginscherm" ziet (soms achter "Meer…")
  3. Geef de app eventueel een naam en tik op Voeg toe

⚠️ Werkt alleen in Safari — niet in Chrome op iOS (Apple-beleid).

`); } function androidInstructions() { const nativeLine = deferredPrompt ? `` : `

Open deze site in Chrome en kies in het ⋮-menu → "App installeren" (of "Aan beginscherm toevoegen").

`; showModal(`

🤖 Installeer op Android

Voeg deze site als app toe aan je beginscherm:

${nativeLine}

⚠️ Werkt het best in Chrome.

`); } function desktopInstructions() { if (deferredPrompt) { deferredPrompt.prompt(); deferredPrompt.userChoice.finally(() => { deferredPrompt = null; }); return; } showModal(`

💻 Installeer op desktop

In Chrome, Edge of een andere Chromium-browser:

  1. Zoek het installeer-icoon in de adresbalk
  2. Klik erop en bevestig

Firefox/Safari desktop ondersteunen PWA-install niet — gebruik een bookmark.

`); } btn.addEventListener('click', () => { if (isIOS) return iosInstructions(); if (isAndroid) return androidInstructions(); return desktopInstructions(); }); })();