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,KAEnC3B,SAASS,iBAAiB,sBAClCC,SAAQgB,IAC7B,MAAM2C,EAAQ3C,EAAa6B,QAAQE,WAAU,GAC7C/B,EAAarC,WAAWC,aAAa+E,EAAO3C,EAAa,GACzD,GAEJ,EAKFD,EAAe","sources":["webpack://openforms/./node_modules/django-cookie-consent/lib/cookiebar.js","webpack://openforms/./src/openforms/js/utils/dom.js","webpack://openforms/./src/openforms/js/components/auth-mode.js","webpack://openforms/./src/openforms/js/public.js"],"sourcesContent":["/**\n * Cookiebar functionality, as a TS/JS module.\n *\n * About modules: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules\n *\n * The code is organized here in a way to make the templates work with Django's page\n * cache. This means that anything user-specific (so different django session and even\n * cookie consent cookies) cannot be baked into the templates, as that breaks caches.\n *\n * The cookie bar operates on the following principles:\n *\n * - The developer using the library includes the desired template in their django\n *   templates, using the HTML <template> element. This contains the content for the\n *   cookie bar.\n * - The developer is responsible for loading some Javascript that loads this script.\n * - The main export of this script needs to be called (showCookieBar), with the\n *   appropriate options.\n * - The options include the backend URLs where the retrieve data, which selectors/DOM\n *   nodes to use for various functionality and the hooks to tap into the accept/decline\n *   life-cycle.\n * - When a user accepts or declines (all) cookies, the call to the backend is made via\n *   a fetch request, bypassing any page caches and preventing full-page reloads.\n */\n;\nconst DEFAULT_FETCH_HEADERS = {\n    'X-Cookie-Consent-Fetch': '1'\n};\nclass FetchClient {\n    constructor(statusUrl, csrfHeaderName) {\n        this.statusUrl = statusUrl;\n        this.csrfHeaderName = csrfHeaderName;\n        this.cookieStatus = null;\n    }\n    async getCookieStatus() {\n        if (this.cookieStatus === null) {\n            const response = await window.fetch(this.statusUrl, {\n                method: 'GET',\n                credentials: 'same-origin',\n                headers: DEFAULT_FETCH_HEADERS,\n            });\n            this.cookieStatus = await response.json();\n        }\n        // type checker sanity check\n        if (this.cookieStatus === null) {\n            throw new Error('Unexpectedly received null cookie status');\n        }\n        return this.cookieStatus;\n    }\n    ;\n    async saveCookiesStatusBackend(urlProperty) {\n        const cookieStatus = await this.getCookieStatus();\n        const url = cookieStatus[urlProperty];\n        if (!url) {\n            throw new Error(`Missing url for ${urlProperty} - was the cookie status not loaded properly?`);\n        }\n        await window.fetch(url, {\n            method: 'POST',\n            credentials: 'same-origin',\n            headers: Object.assign(Object.assign({}, DEFAULT_FETCH_HEADERS), { [this.csrfHeaderName]: cookieStatus.csrftoken })\n        });\n    }\n}\n/**\n * Read the JSON script node contents and parse the content as JSON.\n *\n * The result is the list of available/configured cookie groups.\n * Use the status URL to get the accepted/declined status for an individual user.\n */\nexport const loadCookieGroups = (selector) => {\n    const node = document.querySelector(selector);\n    if (!node) {\n        throw new Error(`No cookie groups (script) tag found, using selector: '${selector}'`);\n    }\n    return JSON.parse(node.innerText);\n};\nconst doInsertBefore = (beforeNode, newNode) => {\n    const parent = beforeNode.parentNode;\n    if (parent === null)\n        throw new Error('Reference node doesn\\'t have a parent.');\n    parent.insertBefore(newNode, beforeNode);\n};\n/**\n * Register the accept/decline event handlers.\n *\n * Note that we can't just set the decline or accept cookie purely client-side, as the\n * cookie possibly has the httpOnly flag set.\n */\nconst registerEvents = ({ client, cookieBarNode, cookieGroups, acceptSelector, onAccept, declineSelector, onDecline, acceptedCookieGroups: accepted, declinedCookieGroups: declined, notAcceptedOrDeclinedCookieGroups: undecided, }) => {\n    const acceptNode = cookieBarNode.querySelector(acceptSelector);\n    if (acceptNode) {\n        acceptNode.addEventListener('click', event => {\n            event.preventDefault();\n            const acceptedGroups = filterCookieGroups(cookieGroups, accepted.concat(undecided));\n            onAccept === null || onAccept === void 0 ? void 0 : onAccept(acceptedGroups, event);\n            // trigger async action, but don't wait for completion\n            client.saveCookiesStatusBackend('acceptUrl');\n            cookieBarNode.parentNode.removeChild(cookieBarNode);\n        });\n    }\n    const declineNode = cookieBarNode.querySelector(declineSelector);\n    if (declineNode) {\n        declineNode.addEventListener('click', event => {\n            event.preventDefault();\n            const declinedGroups = filterCookieGroups(cookieGroups, declined.concat(undecided));\n            onDecline === null || onDecline === void 0 ? void 0 : onDecline(declinedGroups, event);\n            // trigger async action, but don't wait for completion\n            client.saveCookiesStatusBackend('declineUrl');\n            cookieBarNode.parentNode.removeChild(cookieBarNode);\n        });\n    }\n};\n/**\n * Filter the cookie groups down to a subset of specified varnames.\n */\nconst filterCookieGroups = (cookieGroups, varNames) => {\n    return cookieGroups.filter(group => varNames.includes(group.varname));\n};\n// See https://github.com/microsoft/TypeScript/issues/283\nfunction cloneNode(node) {\n    return node.cloneNode(true);\n}\nexport const showCookieBar = async (options = {}) => {\n    const { templateSelector = '#cookie-consent__cookie-bar', cookieGroupsSelector = '#cookie-consent__cookie-groups', acceptSelector = '.cookie-consent__accept', declineSelector = '.cookie-consent__decline', insertBefore = null, onShow, onAccept, onDecline, statusUrl = '', csrfHeaderName = 'X-CSRFToken', // Django's default, can be overridden with settings.CSRF_HEADER_NAME\n     } = options;\n    const cookieGroups = loadCookieGroups(cookieGroupsSelector);\n    // no cookie groups -> abort, nothing to do\n    if (!cookieGroups.length)\n        return;\n    const templateNode = document.querySelector(templateSelector);\n    if (!templateNode) {\n        throw new Error(`No (template) element found for selector '${templateSelector}'.`);\n    }\n    // insert before a given node, if specified, or append to the body as default behaviour\n    const doInsert = insertBefore === null\n        ? (cookieBarNode) => document.querySelector('body').appendChild(cookieBarNode)\n        : typeof insertBefore === 'string'\n            ? (cookieBarNode) => {\n                const referenceNode = document.querySelector(insertBefore);\n                if (referenceNode === null)\n                    throw new Error(`No element found for selector '${insertBefore}'.`);\n                doInsertBefore(referenceNode, cookieBarNode);\n            }\n            : (cookieBarNode) => doInsertBefore(insertBefore, cookieBarNode);\n    if (!statusUrl)\n        throw new Error('Missing status URL option, did you forget to pass the `statusUrl` option?');\n    const client = new FetchClient(statusUrl, csrfHeaderName);\n    const cookieStatus = await client.getCookieStatus();\n    // calculate the cookie groups to invoke the callbacks. We deliberately fire those\n    // without awaiting so that our cookie bar is shown/hidden as soon as possible.\n    const { acceptedCookieGroups, declinedCookieGroups, notAcceptedOrDeclinedCookieGroups } = cookieStatus;\n    const acceptedGroups = filterCookieGroups(cookieGroups, acceptedCookieGroups);\n    if (acceptedGroups.length)\n        onAccept === null || onAccept === void 0 ? void 0 : onAccept(acceptedGroups);\n    const declinedGroups = filterCookieGroups(cookieGroups, declinedCookieGroups);\n    if (declinedGroups.length)\n        onDecline === null || onDecline === void 0 ? void 0 : onDecline(declinedGroups);\n    // there are no (more) cookie groups to accept, don't show the bar\n    if (!notAcceptedOrDeclinedCookieGroups.length)\n        return;\n    // grab the contents from the template node and add them to the DOM, optionally\n    // calling the onShow callback\n    const childToClone = templateNode.content.firstElementChild;\n    if (childToClone === null)\n        throw new Error('The cookie bar template element may not be empty.');\n    const cookieBarNode = cloneNode(childToClone);\n    registerEvents({\n        client,\n        cookieBarNode,\n        cookieGroups,\n        acceptSelector,\n        onAccept,\n        declineSelector,\n        onDecline,\n        acceptedCookieGroups,\n        declinedCookieGroups,\n        notAcceptedOrDeclinedCookieGroups,\n    });\n    doInsert(cookieBarNode);\n    onShow === null || onShow === void 0 ? void 0 : onShow();\n};\n","const onLoaded = callback => {\n  if (document.readyState !== 'loading') {\n    callback();\n  } else {\n    document.addEventListener('DOMContentLoaded', event => callback());\n  }\n};\n\nexport {onLoaded};\n","import {onLoaded} from 'utils/dom';\n\nconst onModeSelect = event => {\n  const {value: mode, checked} = event.target;\n  if (!checked) return;\n\n  const nodesToHide = document.querySelectorAll(`.auth-mode:not(.auth-mode--${mode})`);\n  nodesToHide.forEach(node => {\n    node.classList.remove('auth-mode--active');\n    node.querySelectorAll('input').forEach(input => (input.value = ''));\n  });\n\n  const nodesToShow = document.querySelectorAll(`.auth-mode.auth-mode--${mode}`);\n  nodesToShow.forEach(node => node.classList.add('auth-mode--active'));\n};\n\nconst init = () => {\n  const radios = document.querySelectorAll('#registrator-subject [name=\"mode\"]');\n  if (!radios.length) return;\n\n  radios.forEach(node => {\n    node.addEventListener('change', onModeSelect);\n    node.dispatchEvent(new Event('change'));\n  });\n};\n\nonLoaded(init);\n","import {showCookieBar} from 'django-cookie-consent';\n\nimport 'components/auth-mode';\nimport {onLoaded} from 'utils/dom';\n\n// connect the \"Print this page\" link element to a handler\nconst registerPrintHandler = () => {\n  const node = document.getElementById('print-button');\n  if (!node) return;\n  node.addEventListener('click', event => {\n    event.preventDefault();\n    window.print();\n  });\n};\n\nconst initCookieBar = () => {\n  const templateNode = document.getElementById('cookie-consent__cookie-bar');\n  if (!templateNode) return;\n\n  const {varName, statusUrl} = templateNode.dataset;\n  showCookieBar({\n    statusUrl,\n    templateSelector: '#cookie-consent__cookie-bar',\n    cookieGroupsSelector: '#cookie-consent__cookie-groups',\n    acceptSelector: '.cookie-notice__accept',\n    declineSelector: '.cookie-notice__decline',\n    insertBefore: '#cookie-consent__cookie-bar',\n    onAccept: groups => {\n      const isAnalyticsEnabled = groups.find(group => group.varname === varName);\n      if (!isAnalyticsEnabled) return;\n      const analyticsTemplateNodes = document.querySelectorAll('.analytics-scripts');\n      analyticsTemplateNodes.forEach(templateNode => {\n        const clone = templateNode.content.cloneNode(true);\n        templateNode.parentNode.insertBefore(clone, templateNode);\n      });\n    },\n  });\n};\n\nconst init = () => {\n  registerPrintHandler();\n  initCookieBar();\n};\n\nonLoaded(init);\n"],"names":["DEFAULT_FETCH_HEADERS","FetchClient","constructor","statusUrl","csrfHeaderName","this","cookieStatus","getCookieStatus","response","window","fetch","method","credentials","headers","json","Error","saveCookiesStatusBackend","urlProperty","url","Object","assign","csrftoken","doInsertBefore","beforeNode","newNode","parent","parentNode","insertBefore","filterCookieGroups","cookieGroups","varNames","filter","group","includes","varname","onLoaded","callback","document","readyState","addEventListener","event","onModeSelect","value","mode","checked","target","querySelectorAll","forEach","node","classList","remove","input","add","init","radios","length","dispatchEvent","Event","registerPrintHandler","getElementById","preventDefault","print","initCookieBar","templateNode","varName","dataset","async","options","templateSelector","cookieGroupsSelector","acceptSelector","declineSelector","onShow","onAccept","onDecline","selector","querySelector","JSON","parse","innerText","loadCookieGroups","doInsert","cookieBarNode","appendChild","referenceNode","client","acceptedCookieGroups","declinedCookieGroups","notAcceptedOrDeclinedCookieGroups","acceptedGroups","declinedGroups","childToClone","content","firstElementChild","cloneNode","accepted","declined","undecided","acceptNode","concat","removeChild","declineNode","registerEvents","showCookieBar","groups","find","clone"],"sourceRoot":""}