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