index.ts 811 B

1234567891011121314151617181920212223242526272829303132
  1. import {
  2. CookieConsentValue,
  3. cookieBannerRequired,
  4. hasMadeCookieChoice,
  5. setConsent,
  6. } from '@/features/cookie-banner/utils'
  7. function toggleCookieBanner(hidden: boolean) {
  8. const cookieBannerEl = document.querySelector('.cookie-banner')
  9. if (cookieBannerEl) {
  10. cookieBannerEl.classList.toggle('hidden', hidden)
  11. }
  12. }
  13. if (cookieBannerRequired()) {
  14. document
  15. .querySelectorAll('[data-ol-cookie-banner-set-consent]')
  16. .forEach(el => {
  17. el.addEventListener('click', function (e) {
  18. e.preventDefault()
  19. toggleCookieBanner(true)
  20. const consentType = el.getAttribute(
  21. 'data-ol-cookie-banner-set-consent'
  22. ) as CookieConsentValue | null
  23. setConsent(consentType)
  24. })
  25. })
  26. if (!hasMadeCookieChoice()) {
  27. toggleCookieBanner(false)
  28. }
  29. }