1(function() { 2 3 "use strict"; 4 5 var opts; 6 7 var Cookiesck = function (options) { 8 9 // check if Cookies CK has already been loaded in the html 10 if (document.getElementById('cookiesck')) return; 11 12 //set default options 13 var defaults = { 14 lifetime: '' 15 ,layout: '' 16 ,reload: '' 17 }; 18 19 if (!(this instanceof Cookiesck)) return new Cookiesck(options); 20 21 opts = Object.assign(defaults, options); 22 23 initHtml(); 24 initInterface(); 25 initEvents(); 26 initIframes(); 27 } 28 29 function initHtml() { 30 // remove the banner from the page if exists 31 let banner = document.getElementById('cookiesck'); 32 if (banner) banner.remove(); 33 34 // create the banner in the page 35 banner = document.createElement('div'); 36 banner.id = 'cookiesck'; 37 banner.setAttribute('data-layout', opts.layout); 38 banner.innerHTML = createBannerHtml(); 39 document.body.appendChild(banner); 40 41 // create the overlay 42 let overlay = document.createElement('div'); 43 overlay.id = 'cookiesck_overlay'; 44 document.body.appendChild(overlay); 45 46 // create the overlay 47 let options = document.createElement('div'); 48 options.id = 'cookiesck_options'; 49 options.className = 'cookiesck_options'; 50 options.setAttribute('role', 'button'); 51 options.setAttribute('tabindex', '0'); 52 options.setAttribute('aria-label', COOKIESCK.TEXT.OPTIONS.replace(/"/g, '"')); 53 options.innerHTML = '<div class="inner">' + COOKIESCK.TEXT.OPTIONS + '</div>'; 54 document.body.appendChild(options); 55 } 56 57 function createBannerHtml() { 58 let html = '<div class="inner">' 59 + '<span id="cookiesck_text">' + COOKIESCK.TEXT.INFO + '</span>' 60 + '<span id="cookiesck_buttons">' 61 + '<a role="button" tabindex="0" class="cookiesck_button" id="cookiesck_accept">' + COOKIESCK.TEXT.ACCEPT_ALL + '</a>' 62 + '<a role="button" tabindex="0" class="cookiesck_button" id="cookiesck_decline">' + COOKIESCK.TEXT.DECLINE_ALL + '</a>' 63 + '<a role="button" tabindex="0" class="cookiesck_button" id="cookiesck_settings">' + COOKIESCK.TEXT.SETTINGS + '</a>' 64 + '<div style="clear:both;"></div>' 65 + '</div>' 66 67 + '</div>'; 68 69 return html; 70 } 71 72 function initInterface() { 73 let cookie = readCookie('cookiesck'); 74 document.getElementById('cookiesck').style.display = 'none'; 75 document.getElementById('cookiesck_overlay').style.display = 'none'; 76 // cookies not set, display the bar 77 if(cookie == null) { 78 document.getElementById('cookiesck').style.display = 'block'; 79 document.getElementById('cookiesck_overlay').style.display = 'block'; 80 } else { 81 COOKIESCK.VALUE = decodeURIComponent(decodeURIComponent(cookie)); 82 debug('COOKIESCK.VALUE : ' + COOKIESCK.VALUE); 83 } 84 85 var cookieArray = toObject(); 86 let interfac = document.getElementById('cookiesck_interface'); 87 let platforms = interfac.querySelectorAll('.cookiesck-platform'); 88 debug('platforms :'); 89 debug(platforms); 90 platforms.forEach(function(platform) { 91 let platformName = platform.getAttribute('data-platform'); 92 let buttons = platform.querySelectorAll('.cookiesck_button'); 93 94 buttons.forEach(function(button) { 95 button.onclick = function() { 96 if (this.classList.contains('cookiesck-accept')) { 97 doAction(this, 'accept'); 98 } else { 99 doAction(this, 'decline'); 100 } 101 interfac.querySelectorAll('.cookiesck-main-buttons .cookiesck_button').forEach(function(btn) { btn.classList.remove('cookiesck-active'); }); 102 highlightAllButton(); 103 } 104 }); 105 106 // switchers events 107 platform.querySelectorAll('input[id^="cookiesck-switch"]').forEach(function(button) { 108 button.onchange = function() { 109 if (button.checked === true) { 110 button.parentNode.querySelector('.cookiesck-accept').click(); 111 } else { 112 button.parentNode.querySelector('.cookiesck-decline').click(); 113 } 114 } 115 }); 116 117 118 // set active button 119 if (cookieArray[platformName]) { 120 var switcher = platform.querySelector('input[id^="cookiesck-switch"]'); 121 if (cookieArray[platformName] == 1) { 122 platform.querySelector('.cookiesck-accept').classList.add('cookiesck-active'); 123 if (switcher) switcher.checked = true; 124 } else { 125 platform.querySelector('.cookiesck-decline').classList.add('cookiesck-active'); 126 if (switcher) switcher.checked = false; 127 } 128 } 129 }); 130 131 if (COOKIESCK.VALUE === 'yes') { 132 interfac.querySelectorAll('.cookiesck-accept').forEach(function(btn
132) { btn.classList.add('cookiesck-active'); }); 133 } else if (COOKIESCK.VALUE === 'no' || COOKIESCK.VALUE === 'null') { 134 interfac.querySelectorAll('.cookiesck-decline').forEach(function(btn) { btn.classList.add('cookiesck-active'); }); 135 } 136 137 // force essential to be active 138 if (interfac.querySelector('[data-category="essential"]')) { 139 interfac.querySelectorAll('[data-category="essential"] .cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); }); 140 } 141 142 highlightAllButton(); 143 144 // close the interface 145 interfac.querySelector('.cookiesck-main-close').onclick = function() { 146 updateCookieValue(); 147 hideInterface(); 148 if (opts.reload === '1') location.reload(); 149 } 150 151 // add accessibility on the buttons 152 const interfaceButtons = interfac.querySelectorAll('.cookiesck_button, .cookiesck-main-close, .cookiesck_button_switch'); 153 const cookieOptions = document.querySelectorAll('.cookiesck_options'); 154 const buttons = Array.from(interfaceButtons).concat(...cookieOptions); 155 buttons.forEach(function(btn) { 156 btn.addEventListener('keydown', function(event) { 157 // presse Enter key 158 if (event.which === 13) { 159 event.preventDefault(); 160 btn.click(); 161 } 162 }); 163 }); 164 165 // close on escape button 166 document.addEventListener('keydown', function(event) { 167 if (event.which === 27) { 168 hideInterface(); 169 } 170 }); 171 } 172 173 function hideInterface() { 174 let interfac = document.getElementById('cookiesck_interface'); 175 interfac.style.display = 'none'; 176 document.getElementById('cookiesck_options').style.display = 'block'; 177 document.getElementById('cookiesck_overlay').style.display = 'none'; 178 } 179 180 function highlightAllButton() { 181 let interfac = document.getElementById('cookiesck_interface'); 182 if (interfac.querySelectorAll('.cookiesck-category .cookiesck-accept').length === interfac.querySelectorAll('.cookiesck-category .cookiesck-accept.cookiesck-active').length) { 183 interfac.querySelectorAll('.cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); }); 184 } else if (interfac.querySelectorAll('.cookiesck-category .cookiesck-decline').length === interfac.querySelectorAll('.cookiesck-category .cookiesck-decline.cookiesck-active').length) { 185 interfac.querySelectorAll('.cookiesck-decline').forEach(function(btn) { btn.classList.add('cookiesck-active'); }); 186 } 187 } 188 189 function initEvents() { 190 let acceptButtons = document.querySelectorAll('#cookiesck_accept,.cookiesck-main-buttons .cookiesck-accept'); 191 acceptButtons.forEach(function(acceptButton) { 192 acceptButton.onclick = function() { 193 debug('acceptButton.onclick'); 194 acceptAll(); 195 setCookie("cookiesck","yes",COOKIESCK.LIFETIME); 196 if (COOKIESCK.LOG === '1') { 197 // if not unique key has been set, set it now with the session ID 198 if (! readCookie('cookiesckuniquekey')) { 199 setCookie('cookiesckuniquekey', COOKIESCK.UNIQUE_KEY, opts.lifetime); 200 } 201 } 202// doAjax(location.href, 'set_cookieck=1'); // don't do that, because it won't update consent. use updateCookieValue() instead 203 updateCookieValue(); 204 document.getElementById('cookiesck').classList.add('cookiesck-hide'); 205 document.getElementById('cookiesck').style.display = 'none'; 206 document.getElementById('cookiesck_options').style.display = 'block'; 207 document.getElementById('cookiesck_overlay').style.display = 'none'; 208 loadIframes(); 209 if (opts.reload === '1' && this.id == 'cookiesck_accept') location.reload(); 210 } 211 }); 212 let declineButtons = document.querySelectorAll('#cookiesck_decline, .cookiesck-main-buttons .cookiesck-decline'); 213 declineButtons.forEach(function(declineButton) { 214 declineButton.onclick = function() { 215 debug('declineButton.onclick'); 216 declineAll(); 217 // remove the cookies for all platforms 218 let interfac = document.getElementById('cookiesck_interface'); 219 let categories = interfac.querySelectorAll('.cookiesck-category'); 220 categories.forEach(function(category) { 221 let categoryName = category.getAttribute('data-category'); 222 if (categoryName !== 'Essential') { 223 let platforms = category.querySelectorAll('.cookiesck-platform');
224 platforms.forEach(function(platform) { 225 let platformName = platform.getAttribute('data-platform'); 226 removeCookie(platformName); 227 }) 228 } 229 }) 230 231 232 setCookie("cookiesck","no",COOKIESCK.LIFETIME); 233 if (COOKIESCK.LOG === '1') { 234 // if not unique key has been set, set it now with the session ID 235 if (! readCookie('cookiesckuniquekey')) { 236 setCookie('cookiesckuniquekey', COOKIESCK.UNIQUE_KEY, opts.lifetime); 237 } 238 } 239// doAjax(location.href, 'set_cookieck=0'); // don't do that, because it won't update consent. use updateCookieValue() instead 240 updateCookieValue(); 241 document.getElementById('cookiesck').classList.add('cookiesck-hide'); 242 document.getElementById('cookiesck').style.display = 'none'; 243 document.getElementById('cookiesck_options').style.display = 'block'; 244 document.getElementById('cookiesck_overlay').style.display = 'none'; 245 } 246 }); 247 document.getElementById('cookiesck_settings').onclick = function(){ 248 document.getElementById('cookiesck_interface').style.display = 'block'; 249 document.getElementById('cookiesck').style.display = 'none'; 250 } 251 // add management button to update the decision 252 document.querySelectorAll('.cookiesck_options').forEach(function(cookiesck_options) { 253 cookiesck_options.onclick = function(){ 254 document.getElementById('cookiesck_interface').style.display = 'block'; 255 document.getElementById('cookiesck_overlay').style.display = 'block'; 256 document.getElementById('cookiesck_interface').querySelector('.cookiesck-main-buttons .cookiesck-accept.cookiesck_button').focus(); 257 } 258 }); 259 } 260 261 function initIframes() { 262 let iframes = document.querySelectorAll('.cookiesck-iframe-wrap'); 263 debug('iframes : '); 264 debug(iframes); 265 iframes.forEach(function(iframe) { 266 iframe.onclick = function() { 267 if (! confirm(COOKIESCK.TEXT.CONFIRM_IFRAMES)) return; 268 this.outerHTML = this.outerHTML.replace('data-cookiesck-src', 'src'); 269 loadIframes(); 270 setCookie('cookiesckiframes', '1', COOKIESCK.LIFETIME); 271 } 272 }); 273 } 274 275 function setCookie(c_name,value,exdays) { 276 debug('setCookie : {name : ' + c_name + ', value : ' + value + ', exdays : ' + exdays); 277 var exdate=new Date(Date.now()); 278 exdate.setDate(exdate.getDate() + parseInt(exdays)); 279 var c_value=escape(value) + ((exdays===null) ? "" : "; expires="+exdate.toUTCString()) + "; path=/"; 280 document.cookie=c_name + "=" + c_value; 281 } 282 283 function readCookie(name) { 284 debug('readCookie : ' + name); 285 var nameEQ = name + "="; 286 var cooks = document.cookie.split(';'); 287 for(var i=0;i < cooks.length;i++) { 288 var c = cooks[i]; 289 while (c.charAt(0)==' ') c = c.substring(1,c.length); 290 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); 291 } 292 return null; 293 } 294 295 function removeCookie(platformName) { 296 debug('removeCookie : ' + platformName); 297 298 var keys = getKeyFromPlatform(platformName); 299 var domain = location.hostname.split('.').reverse(); 300 if (domain.length == 1) { 301 domain = '.' + domain[0]; 302 } else { 303 domain = '.' + domain[1] + '.' + domain[0]; 304 } 305 306 for (var i=0; i < keys.length; i++) { 307 debug('Platform Key to remove : ' + keys[i]); 308 let cookie = keys[i] + "=; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/"; 309 document.cookie = cookie; 310 document.cookie = cookie + '; domain=' + domain; 311 } 312 } 313 314 function getKeyFromPlatform(platformName) { 315 var list = JSON.parse(COOKIESCK.LIST.replace(/\|QQ\|/g, '"')); 316 var keys = new Array(); 317 for (const category in list) { 318 for (const platform in list[category]['platforms']) { 319 if (platform === platformName) { 320 for (var cookie in list[category]['platforms'][platform]['cookies']) { 321 keys.push(list[category]['platforms'][platform]['cookies'][cookie]['key']); 322 } 323 } 324 } 325 } 326 327 return keys; 328 } 329 330 function toObject() { 331 let list = new Object(); 332 let rows = COOKIESCK.VALUE.split('|ck|'); 333 for (var i=0; i < rows.length; i++) { 334 let cols = rows[i].split('|val|'); 335 list[cols[0]] = cols[1]; 336 } 337 return list; 338 } 339 340 function doAction(btn, action) { 341 btn.parentNode.querySelectorAll('.cookiesck_button').forEach(function(button) { 342 button.classList.remove('cookiesck-active'); 343 }); 344 btn.classList.add('cookiesck-active'); 345 updateCookieValue(); 346 // if (opts.reload === '1') location.reload(); 347 } 348 349 function updateCookieValue() { 350 debug('updateCookieValue'); 351 let interfac = document.getElementById('cookiesck_interface'); 352 let list = new Array(); 353 let platforms = interfac.querySelectorAll('.cookiesck-platform'); 354
355 platforms.forEach(function(platform) { 356 let selection = platform.querySelector('.cookiesck_button.cookiesck-active'); 357 let name = platform.getAttribute('data-platform'); 358 if (selection && selection.classList.contains('cookiesck-accept')) { 359 list.push(name + '|val|1'); 360 var state = '1'; 361 // trigger event 362 let event = new CustomEvent('cookieckstate', { "detail": {"name": name, "state": "1"} }); 363 document.dispatchEvent(event); 364 debug('cookieckstate : {name : ' + name + ', state : 1'); 365 } else { 366 list.push(name + '|val|0'); 367 var state = '0'; 368 removeCookie(name); 369 // trigger event 370 let event = new CustomEvent('cookieckstate', { "detail": {"name": name, "state": "0"} }); 371 document.dispatchEvent(event); 372 debug('cookieckstate : {name : ' + name + ', state : 0'); 373 } 374 // google consent update 375 if (name === 'cookiesckgoogleanalytics' || name === 'cookiesckgooglead') { 376 consentGrantedAdStorage(name, state); 377 } 378 }); 379 COOKIESCK.VALUE = list.join('|ck|'); 380 setCookie('cookiesck', encodeURIComponent(COOKIESCK.VALUE), opts.lifetime); 381 if (COOKIESCK.LOG === '1') { 382 // if not unique key has been set, set it now with the session ID 383 if (! readCookie('cookiesckuniquekey')) { 384 setCookie('cookiesckuniquekey', COOKIESCK.UNIQUE_KEY, opts.lifetime); 385 } 386 } 387 doAjax(location.href, 'set_cookieck=update&cookiesck_vars=' + encodeURIComponent(COOKIESCK.VALUE)); 388 } 389 390 function acceptAll() { 391 let interfac = document.getElementById('cookiesck_interface'); 392 interfac.querySelectorAll('.cookiesck-active').forEach(function(btn) { btn.classList.remove('cookiesck-active'); }); 393 interfac.querySelectorAll('.cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); }); 394 interfac.querySelectorAll('input[id^="cookiesck-switch"]').forEach(function(btn) { btn.checked = 'checked'; }); 395 loadIframes(); 396 // trigger event 397 let event = new CustomEvent('cookieckstate', { "detail": {"name": "all", "state": "1"} }); 398 document.dispatchEvent(event); 399 } 400 401 function declineAll() { 402 let interfac = document.getElementById('cookiesck_interface'); 403 interfac.querySelectorAll('.cookiesck-active').forEach(function(btn) { btn.classList.remove('cookiesck-active'); }); 404 interfac.querySelectorAll('.cookiesck-decline').forEach(function(btn) { btn.classList.add('cookiesck-active'); }); 405 interfac.querySelectorAll('input[id^="cookiesck-switch"]').forEach(function(btn) { btn.checked = ''; }); 406 // force essential to be active 407 if (interfac.querySelector('[data-category="essential"]')) { 408 interfac.querySelectorAll('[data-category="essential"] .cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); }); 409 } 410 // trigger event 411 let event = new CustomEvent('cookieckstate', { "detail": {"name": "all", "state": "0"} }); 412 document.dispatchEvent(event); 413 } 414 415 function loadIframes() { 416 let iframes = document.querySelectorAll('.cookiesck-iframe-wrap'); 417 iframes.forEach(function(iframetoenable) { 418 iframetoenable.closest('.cookiesck-iframe-wrap').className = 'cookiesck-iframe-wrap-allowed'; 419 iframetoenable.outerHTML = iframetoenable.outerHTML.replace('data-cookiesck-src', 'src'); 420 }); 421 } 422 423 function doAjax(url, vars) { 424 // ancien code de compatibilité, aujourdâhui inutile 425 if (window.XMLHttpRequest) { // Mozilla, Safari, IE7+... 426 var httpRequest = new XMLHttpRequest(); 427 } 428 else if (window.ActiveXObject) { // IE 6 et antérieurs 429 var httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); 430 } 431 httpRequest.onreadystatechange = function() { 432 // instructions de traitement de la réponse 433 }; 434 httpRequest.open('POST', url, true); 435 httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 436 httpRequest.send(vars); 437 } 438 439 function debug(str) { 440 if (COOKIESCK.DEBUG === '1') { 441 console.log(str); 442 } 443 } 444 445 // for Google Tag Manager 446 function consentGrantedAdStorage(name, state) { 447 var grant = state === '1' ? 'granted' : 'denied'; 448 if (typeof(gtag) === 'function') { 449 if (name === 'cookiesckgoogleanalytics') { 450 gtag('consent', 'update', {
451 'analytics_storage': grant 452 }); 453 } 454 if (name === 'cookiesckgooglead') { 455 gtag('consent', 'update', { 456 'ad_storage': grant, 457 'ad_user_data': grant, 458 'ad_personalization': grant 459 }); 460 } 461 } 462 } 463 window.Cookiesck = Cookiesck; 464 window.ckInitCookiesckIframes = initIframes; 465})(); 466 467// initialize the setter and getter for the cookies 468if (! document.__defineGetter__) { 469 Object.defineProperty(document, 'cookie',{ 470 get: function g(){ return ''; }, 471 set: function h(){ return true;} 472 }); 473} else { 474 var oldSetter = document.__lookupSetter__('cookie'); 475 var oldGetter = document.__lookupGetter__('cookie'); 476 if (oldSetter) { 477 Object.defineProperty(document, 'cookie', { 478 get: function g(){ return oldGetter.call(document); }, 479 set: function h(v){ 480 let name = v.split('=')[0]; 481 482 if (COOKIESCK.DEBUG === '1') { 483 console.log('v.match(/cookiesck\=/)'); 484 console.log(v.match(/cookiesck\=/)); 485 console.log('COOKIESCK.VALUE'); 486 console.log(COOKIESCK.VALUE); 487 console.log('COOKIESCK.ALLOWED'); 488 console.log(COOKIESCK.ALLOWED); 489 console.log('COOKIESCK.ALLOWED.indexOf(name)'); 490 console.log(COOKIESCK.ALLOWED.indexOf(name)); 491 console.log('ckCookiesSearchNameIn(name, COOKIESCK.ALLOWED)'); 492 console.log(ckCookiesSearchNameIn(name, COOKIESCK.ALLOWED)); 493 } 494 495 if(v.match(/cookiesck\=/) || COOKIESCK.VALUE === 'yes' || COOKIESCK.ALLOWED.indexOf(name) != -1 || ckCookiesSearchNameIn(name, COOKIESCK.ALLOWED)) { 496 oldSetter.call(document, v); 497 if (COOKIESCK.DEBUG === '1') { 498 console.log('>> set cookie allowed :'); 499 console.log(name); 500 } 501 } else { 502 let cookie = name + "=; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/;"; 503 oldSetter.call(document, cookie); 504 if (COOKIESCK.DEBUG === '1') { 505 console.log('>> set cookie blocked for :'); 506 console.log(name); 507 } 508 } 509 return true; 510 } 511 }); 512 } 513} 514 515function ckCookiesSearchNameIn(name, list) { 516 for (var i=0; i<list.length; i++) { 517 if (name.substr(0, list[i].length) == list[i]) return true; 518 } 519 return false; 520} 521 522// example of how to get the event 523//document.addEventListener("cookieckstate", function(e) { 524// console.log(e.detail) 525// console.log(e.detail.name); 526// console.log(e.detail.state); 527//}); 528
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.