1document.addEventListener("DOMContentLoaded", function () { 2 const el = document.getElementById("CookieBanner"); 3 if (!el) 4 return; 5 6 Vue.createApp({ 7 data() { 8 return { 9 mandatoryDiv: false, 10 statisticDiv: false, 11 marketingDiv: false, 12 cookieBanner: false, 13 cookieContainer: false, 14 cookieSelector: false, 15 cbxStatistic: false, 16 cbxMarketing: false, 17 focusTrapHandler: null, 18 focusGuardHandler: null, 19 savedScrollY: 0, 20 focusableSelectors: 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])' 21 } 22 }, 23 created() { 24 this.checkForExistingCookie(); 25 this.cookieContainer = true; 26 }, 27 mounted() { 28 if (this.cookieBanner) { 29 this.$nextTick(() => this.activateModalMode()); 30 } 31 }, 32 watch: { 33 cookieBanner(newVal) { 34 if (newVal) { 35 this.$nextTick(() => this.activateModalMode()); 36 } else { 37 this.deactivateModalMode(); 38 } 39 } 40 }, 41 methods: { 42 toggleCookieSelector() { 43 this.cookieContainer = !this.cookieContainer; 44 this.cookieSelector = !this.cookieSelector; 45 }, 46 toggleMandatoryDiv() { 47 this.mandatoryDiv = !this.mandatoryDiv; 48 }, 49 toggleStatisticDiv() { 50 this.statisticDiv = !this.statisticDiv; 51 }, 52 toggleMarketingDiv() { 53 this.marketingDiv = !this.marketingDiv; 54 }, 55 cookieBannerAllClick() { 56 document.cookie = "GarantumSavedCookiesPreferences=all; expires=" + this.getCookieExpiration() + "; path=/"; 57 this.cookieBanner = false; 58 }, 59 cookieOnlyNecessary() { 60 document.cookie = "GarantumSavedCookiesPreferences=mandatory; expires=" + this.getCookieExpiration() + "; path=/"; 61 this.cookieBanner = false; 62 }, 63 cookieBannerPrefClick() { 64 let content; 65 66 if (this.cbxStatistic && this.cbxMarketing) { 67 content = "all"; 68 } else if (this.cbxStatistic) { 69 content = "statistic"; 70 } else if (this.cbxMarketing) { 71 content = "marketing"; 72 } else { 73 content = "mandatory"; 74 } 75 76 document.cookie = "GarantumSavedCookiesPreferences=" + 77 content + 78 "; expires=" + 79 this.getCookieExpiration() + 80 "; path=/"; 81 this.cookieBanner = false; 82 }, 83 checkForExistingCookie() { 84 let exist = this.checkCookie("GarantumSavedCookiesPreferences"); 85 this.cookieBanner = !exist; 86 }, 87 getCookieExpiration() { 88 let expirationDate = new Date(); 89 expirationDate.setMonth(expirationDate.getMonth() + 1); 90 return expirationDate.toUTCString(); 91 }, 92 checkCookie(name) { 93 let cookies = document.cookie.split(';'); 94 95 for (let i = 0; i < cookies.length; i++) { 96 let cookie = cookies[i].trim(); 97 if (cookie.indexOf(name + '=') === 0) { 98 return true; 99 } 100 } 101 return false; 102 }, 103 activateModalMode() { 104 let bannerEl = document.getElementById('CookieBanner'); 105 if (!bannerEl) { 106 return; 107 } 108 109 this.savedScrollY = window.scrollY || window.pageYOffset || 0; 110 document.body.style.position = 'fixed'; 111 document.body.style.top = '-' + this.savedScrollY + 'px'; 112 document.body.style.left = '0'; 113 document.body.style.right = '0'; 114 document.body.style.width = '100%'; 115 116 let focusFirst = () => { 117 let currentFocusable = Array.from(bannerEl.querySelectorAll(this.focusableSelectors)) 118 .filter(el => el.offsetParent !== null); 119 if (currentFocusable.length > 0) { 120 currentFocusable[0].focus(); 121 } else { 122 bannerEl.setAttribute('tabindex', '-1'); 123 bannerEl.focus(); 124 } 125 }; 126 127 focusFirst(); 128 129 this.focusTrapHandler = (e) => { 130 if (e.key !== 'Tab') { 131 return; 132 } 133 134 let focusables = Array.from(bannerEl.querySelectorAll(this.focusableSelectors)) 135 .filter(el => el.offsetParent !== null); 136 137 if (focusables.length === 0) { 138 e.preventDefault(); 139 return; 140 } 141 142 let first = focusables[0]; 143 let last = focusables[focusables.length - 1]; 144 let active = document.activeElement; 145 146 if (e.shiftKey) { 147 if (active === first || !bannerEl.contains(active)) { 148 e.preventDefault(); 149 last.focus(); 150 } 151 } else { 152 if (active === last) { 153 e.preventDefault(); 154 first.focus(); 155 } 156 } 157 }; 158 159 bannerEl.addEventListener('keydown', this.focusTrapHandler); 160 161 this.focusGuardHandler = (e) => { 162 if (!this.cookieBanner) { 163 return; 164 } 165 if (!bannerEl.contains(e.target)) { 166 e.stopPropagation(); 167 focusFirst(); 168 } 169 }; 170 171 document.addEventListener('focusin', this.focusGuardHandler); 172 }, 173 deactivateModalMode() { 174 let bannerEl = document.getElementById('CookieBanner'); 175 if (bannerEl && this.focusTrapHandler) { 176 bannerEl.removeEventListener('keydown', this.focusTrapHandler); 177 this.focusTrapHandler = null; 178 } 179 180 if (this.focusGuardHandler) { 181 document.removeEventListener('focusin', this.focusGuardHandler); 182 this.focusGuardHandler = null; 183 } 184 185 document.body.style.position = ''; 186 document.body.style.top = ''; 187 document.body.style.left = ''; 188 document.body.style.right = ''; 189 document.body.style.width = ''; 190 191 window.scrollTo(0, this.savedScrollY); 192 } 193 } 194 }).mount("#CookieBanner"); 195});
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.