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,EAAOD,EAAoBE,SAASC,KAAKF,KAC/B9D,KAAKC,MAAMwB,SAASC,cAAc,YAAYmB,OAElDnC,SAASoD,KACnBK,GAAgB,KAItBD,EAAOE,QAAUD,EAAa,2CAC/B,gBAhBmBhC,EAAAA,GAAAA,OAAAA,EAAAA,MAAAA,KAAAA,UAAAA,CAAAA,CAAA,KAkBhB,kBAAmBf,WAAS,iBACoC,KAA5D8C,EAASzC,SAAS4C,eAAe,6BAE5B,CAAD,iCACmBjD,UAAUC,cAAciD,MAAK,QAAlD/B,EAAY,OAElBJ,EAAeI,EAAc2B,GAE7BA,EAAO5D,iBAAiB,SAAQ,6BAAE,+EAAe,MAANiE,OAC9BH,QAAQ,CAAD,+BACV9B,EAAyBC,GAAc,KAAD,wCAEtCoB,EAA6BpB,GAAa,2CAEnD,mDAN+B,IAM9B,+CClFJiC,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://decidim-development-app/../usr/local/bundle/gems/decidim-core-0.27.0/app/packs/src/decidim/sw/a2hs.js","webpack://decidim-development-app/../usr/local/bundle/gems/decidim-core-0.27.0/app/packs/src/decidim/sw/loader.js","webpack://decidim-development-app/../usr/local/bundle/gems/decidim-core-0.27.0/app/packs/src/decidim/sw/push-permissions.js","webpack://decidim-development-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","prompt","userChoice","outcome","removeItem","navigator","serviceWorker","register","scope","mandatoryElements","document","querySelector","isOperaMini","userAgent","indexOf","classList","add","_context","console","log","setToggleState","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","currentSubscription","auth","toJSON","keys","_document$querySelect2","toggle","toggleChecked","checked","getElementById","ready","target","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","exports","module","__webpack_modules__"],"sourceRoot":""}