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cAAc,YAAYiB,OAElDlC,SAASoD,KACnBM,GAAgB,KAItBD,EAAOE,QAAUD,EAfI,sCAnDmB,+DAqEtC,kBAAmB/C,WArEmB,sBAsElC8C,EAASzC,SAAS4C,eAAe,6BAtEC,kCAyEXjD,UAAUC,cAAciD,MAzEb,QAyEhCjC,EAzEgC,OA2EtC4B,EAAe5B,EAAc6B,GAE7BA,EAAO7D,iBAAiB,SAAxB6D,WAAAA,IAAAA,EAAAA,EAAAA,IAAAA,MAAkC,qFAASK,OAC9BH,QADqB,gCAExBhC,EAAyBC,GAFD,6CAIxBoB,EAA6BpB,GAJL,sCAAlC,wDAAA6B,IA7EsC,uCAA5C,QCCIM,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaE,QAGrB,IAAIC,EAASN,EAAyBE,GAAY,CAGjDG,QAAS,CAAC,GAOX,OAHAE,EAAoBL,GAAUI,EAAQA,EAAOD,QAASJ,GAG/CK,EAAOD,OACf","sources":["webpack://app/../usr/local/bundle/bundler/gems/decidim-c77d1346afca/decidim-core/app/packs/src/decidim/sw/a2hs.js","webpack://app/../usr/local/bundle/bundler/gems/decidim-c77d1346afca/decidim-core/app/packs/src/decidim/sw/loader.js","webpack://app/../usr/local/bundle/bundler/gems/decidim-c77d1346afca/decidim-core/app/packs/src/decidim/sw/push-permissions.js","webpack://app/webpack/bootstrap"],"sourcesContent":["const visitedPages = JSON.parse(sessionStorage.getItem(\"visitedPages\")) || []\nconst DELAYED_VISITS = 2\nlet deferredPrompt = null\n\nconst shouldCountVisitedPages = () => sessionStorage.getItem(\"userChoice\") !== \"dismissed\" && visitedPages.length < DELAYED_VISITS && !visitedPages.includes(location.pathname)\nconst shouldPrompt = () => {\n // Disable the application install prompt showing constantly.\n if (localStorage.getItem(\"pwaInstallPromptSeen\")) {\n return false\n }\n\n return deferredPrompt && sessionStorage.getItem(\"userChoice\") !== \"dismissed\" && visitedPages.length >= DELAYED_VISITS\n}\n\nwindow.addEventListener(\"beforeinstallprompt\", (event) => {\n event.preventDefault()\n deferredPrompt = event\n\n // allow the user browse through different locations before prompt them anything\n if (shouldCountVisitedPages()) {\n sessionStorage.setItem(\"visitedPages\", JSON.stringify([...visitedPages, location.pathname]))\n }\n});\n\n// to trigger the prompt, it must be a \"user gesture\"\nwindow.addEventListener(\"click\", async (event) => {\n if (shouldPrompt()) {\n event.preventDefault()\n deferredPrompt.prompt()\n\n const { outcome } = await deferredPrompt.userChoice;\n // store the user choice to avoid asking again in the current session\n sessionStorage.setItem(\"userChoice\", outcome)\n sessionStorage.removeItem(\"visitedPages\")\n localStorage.setItem(\"pwaInstallPromptSeen\", true)\n }\n});\n","// check if the browser supports serviceWorker at all\nwindow.addEventListener(\"load\", async () => {\n if (\"serviceWorker\" in navigator) {\n await navigator.serviceWorker.register(\"/sw.js\", { scope: \"/\" });\n\n const mandatoryElements = document.querySelector(\".js-sw-mandatory\");\n // Opera uses Opera for versions <= 12 and OPR for versions > 12\n const isOperaMini =\n ((navigator.userAgent.indexOf(\"OPR\") > -1) || (navigator.userAgent.indexOf(\"Opera\") > -1)) &&\n (navigator.userAgent.indexOf(\"Mini\") > -1);\n\n if (mandatoryElements && isOperaMini) {\n mandatoryElements.classList.add(\"hide\")\n }\n } else {\n console.log(\"Your browser doesn't support service workers 🤷‍♀️\");\n }\n});\n","window.addEventListener(\"DOMContentLoaded\", async () => {\n const GRANTED_PERMISSION = \"granted\"\n\n const hideReminder = function() {\n const reminder = document.querySelector(\"#push-notifications-reminder\")\n reminder.classList.add(\"hide\")\n }\n\n const subscribeToNotifications = async (registration) => {\n const permission = await window.Notification.requestPermission();\n\n if (registration && permission === GRANTED_PERMISSION) {\n const vapidElement = document.querySelector(\"#vapidPublicKey\")\n // element could not exist in DOM\n if (vapidElement) {\n const vapidPublicKeyElement = JSON.parse(vapidElement.value)\n const subscription = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: new Uint8Array(vapidPublicKeyElement)\n });\n\n if (subscription) {\n await fetch(\"/notifications_subscriptions\", {\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-CSRF-Token\": document.querySelector(\"meta[name=csrf-token]\")?.content\n },\n method: \"POST\",\n body: JSON.stringify(subscription)\n });\n }\n }\n hideReminder()\n } else {\n throw new Error(\"Permission not granted for Notification\");\n }\n }\n\n const unsubscribeFromNotifications = async (registration) => {\n /* eslint-disable no-shadow */\n const currentSubscription = await registration.pushManager.getSubscription()\n const auth = currentSubscription.toJSON().keys.auth\n await fetch(`/notifications_subscriptions/${auth}`, {\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-CSRF-Token\": document.querySelector(\"meta[name=csrf-token]\")?.content\n },\n method: \"DELETE\"\n });\n }\n\n const setToggleState = async (registration, toggle) => {\n const currentSubscription = await registration.pushManager.getSubscription()\n let toggleChecked = false\n\n if (window.Notification.permission === GRANTED_PERMISSION) {\n hideReminder()\n if (currentSubscription) {\n const auth = currentSubscription.toJSON().keys.auth\n const subKeys = JSON.parse(document.querySelector(\"#subKeys\").value)\n // Subscribed && browser notifications enabled\n if (subKeys.includes(auth)) {\n toggleChecked = true\n }\n }\n }\n toggle.checked = toggleChecked\n }\n\n if (\"serviceWorker\" in navigator) {\n const toggle = document.getElementById(\"allow_push_notifications\")\n\n if (toggle) {\n const registration = await navigator.serviceWorker.ready\n\n setToggleState(registration, toggle)\n\n toggle.addEventListener(\"change\", async ({ target }) => {\n if (target.checked) {\n await subscribeToNotifications(registration);\n } else {\n await unsubscribeFromNotifications(registration)\n }\n })\n }\n }\n});\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n"],"names":["visitedPages","JSON","parse","sessionStorage","getItem","deferredPrompt","window","addEventListener","event","preventDefault","length","includes","location","pathname","setItem","stringify","localStorage","_context","prompt","userChoice","outcome","removeItem","navigator","serviceWorker","register","scope","mandatoryElements","document","querySelector","isOperaMini","userAgent","indexOf","classList","add","console","log","GRANTED_PERMISSION","hideReminder","subscribeToNotifications","registration","Notification","requestPermission","permission","vapidElement","vapidPublicKeyElement","value","pushManager","subscribe","userVisibleOnly","applicationServerKey","Uint8Array","subscription","fetch","headers","_document$querySelect","content","method","body","Error","unsubscribeFromNotifications","getSubscription","_context2","currentSubscription","auth","toJSON","keys","_document$querySelect2","setToggleState","toggle","toggleChecked","checked","getElementById","ready","target","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","exports","module","__webpack_modules__"],"sourceRoot":""}