1/* 2 CookieConsent 3 */ 4 5document.addEventListener("DOMContentLoaded", function () { 6 7 // Cookie consent banner ID: 8 let consentBanner = document.getElementById('cookieConsent'); 9 10 // possible items to check: 11 // [checkboxElement, cookieName] 12 let checkBoxes = [ 13 ['videoPlatforms', 'videoPlatforms'], 14 ['googleTracking', 'google_tracking'], 15 ['matomoTracking', 'matomo_tracking'], 16 ['mapPlatforms', 'mapPlatforms'] 17 ]; 18 checkBoxes.forEach(cBox => { 19 20 let currentElement = document.getElementById(cBox[0]); 21 let currentConsentInt = parseInt(getCookie(cBox[1])); 22 23 // set checkbox to "checked" if cookie === 1 24 if (currentElement && currentConsentInt === 1) { 25 currentElement.setAttribute('checked', 'checked'); 26 } 27 28 // watch change of checkbox and set/unset cookie 29 if (currentElement) { 30 currentElement.addEventListener('change', function() { 31 if (currentElement.checked === true) { 32 setCookie(cBox[1], 1, 30); 33 } else { 34 setCookie(cBox[1], 0, 30); 35 } 36 }); 37 } 38 }); 39 40 41 // show consent banner if no cookie is found 42 if ( getCookie('cookie_status') !== 'consented' ) { 43 showCookieBanner(); 44 } 45 46 // for the 404-page: which cannot check the status => hide the cookiebanner if consented 47 if ( getCookie('cookie_status') === 'consented' && consentBanner.dataset.cookie === 'unconsented' ) { 48 showCookieBanner(); 49 } 50 51 52 // if "consent common button" is pressed 53 // verify all checkboxes and set/unset chosen cookies 54 document.getElementById('commonConsent').addEventListener('click', function() { 55 56 // set common cookieConsent 57 setCookie('cookie_status', 'consented', 30); 58 consentBanner.dataset.cookie = 'consented'; 59 60 // set/unset the tracking cookies 61 checkBoxes.forEach(cBox => { 62 let currentElement = document.getElementById(cBox[0]); 63 if (currentElement && currentElement.checked) { 64 setCookie(cBox[1], 1, 30); 65 } else { 66 if (currentElement) { 67 setCookie(cBox[1], 0, 30); 68 } 69 } 70 }); 71 72 // hide banner 73 hideCookieBanner() 74 75 // reload the page 76 location.reload(); 77 }); 78 79 80 81 82 // decline optional cookies 83 document.getElementById('declineCookies').addEventListener('click', function() { 84 85 checkBoxes.forEach(cBox => { 86 setCookie(cBox[1], 0, 30); 87 }); 88 89 setCookie('cookie_status', 'consented', 30); 90 consentBanner.dataset.cookie = 'consented'; 91 92 // hide banner 93 hideCookieBanner() 94 95 // reload the page 96 location.reload(); 97 }); 98 99 100 101 // consent all cookies by pressing the "all Cookies button" 102 document.getElementById('explicitConsent').addEventListener('click', function() { 103 104 // set common cookieConsent 105 setCookie('cookie_status', 'consented', 30); 106 107 // set all available tracking cookies to consented 108 checkBoxes.forEach(cBox => { 109 let currentElement = document.getElementById(cBox[0]); 110 if (currentElement) { 111 setCookie(cBox[1], 1, 30); 112 } 113 }); 114 115 // hide banner 116 hideCookieBanner(); 117 118 // reload the page 119 location.reload(); 120 }); 121 122 123 // show banner on button click 124 document.getElementById('cookieConsentTrigger').addEventListener('click', function () { 125 showCookieBanner(); 126 }); 127 128 129 // prevent from closing by escape => user has to choose an option 130 consentBanner.addEventListener('keydown', (event) => { 131 if (event.key === 'Escape') { 132 event.preventDefault(); 133 } 134 }); 135}); 136 137 138 139 140// Hide the cookie consent banner 141function hideCookieBanner() {
142 let consentBanner = document.getElementById('cookieConsent'); 143 consentBanner.close(); 144} 145 146// Show the cookie consent banner 147function showCookieBanner() { 148 let consentBanner = document.getElementById('cookieConsent'); 149 consentBanner.showModal(); 150}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.