1/* 2 * ISC License 3 * 4 * Copyright (c) 2025 idnovate.com 5 * idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 13 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 16 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 * 19 * @author idnovate 20 * @copyright 2025 idnovate.com 21 * @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License 22 */ 23var cookiesPlusBlockedScripts = cookiesPlusBlockedScripts || []; 24 25var cookieGdpr = { 26 init: function () { 27 var self = this; // Store reference to 'this' 28 29 self.loadedScriptsCount = 0; 30 self.loadedScriptsTotal = 0; 31 self.consentsGiven = 0; 32 33 if (document.cookie.indexOf('cookiesplus=') === -1) { 34 // cookiesplus cookie doesn't exist, initialize it 35 // cookiesplusVars = []; 36 // cookiesplusVars['C_P_DISPLAY_MODAL'] = false; 37 38 if (typeof C_P_EXPIRY === 'undefined') { 39 console.log('%cC_P_EXPIRY is not defined', 'background: red; color: white'); 40 return; 41 } 42 43 var expireTime = new Date(); 44 expireTime.setDate(expireTime.getDate() + C_P_EXPIRY); 45 var expires = "expires=" + expireTime.toUTCString(); 46 47 var cookieString = "cookiesplus={}; domain=" + C_P_DOMAIN + "; " + expires + "; path=/; SameSite=" + PS_COOKIE_SAMESITE + ";"; 48 49 if (PS_COOKIE_SECURE === 1) { 50 cookieString += " Secure;"; 51 } 52 53 document.cookie = cookieString; 54 } 55 56 // Check if the cookie cookiesplus is duplicated 57 const cookies = document.cookie.split('; '); 58 59 // Filter the cookies array to find occurrences of the specified cookie name 60 const occurrences = cookies.filter(cookie => cookie.startsWith('cookiesplus=')); 61 if (occurrences.length > 1) { 62 console.log('%cDuplicate cookies found for cookiesplus', 'background: red; color: white'); 63 occurrences.forEach(() => { 64 document.cookie = 'cookiesplus=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; 65 }); 66 } 67 68 // mode DIVs before </body> 69 $('.cookiesplus-move').appendTo(document.body); 70 71 let cookiesplusVars = cookieGdpr.tryParseJSONObject(decodeURIComponent(cookieGdpr.getCookiesPlusCookieValue('cookiesplus'))); 72 73 // Initialize values 74 let consentRefused = false; 75 if (typeof cookiesplusVars.consents === 'object' && cookiesplusVars.consents !== null) { 76 cookiesplusFinalities = Object.keys(cookiesplusVars.consents).filter(v => v.startsWith('cookiesplus-finality')); 77 78 self.consentsGiven = false; 79 80 cookiesplusFinalities.forEach(function (key) { 81 self.consentsGiven = true; 82 if (cookiesplusVars.consents[key] === 'on') { 83 $("label[for='" + key + '-' + cookiesplusVars.consents[key] + "']").click() 84 } else { 85 consentRefused = true; 86 } 87 }) 88 89 if (cookiesplusVars.consent_hash) { 90 $('.cookiesplus-consent-hash a').attr('href', C_P_CONSENT_DOWNLOAD + '?hash=' + cookiesplusVars.consent_hash + '&getPdf'); 91 $('.cookiesplus-consent-hash a').text(cookiesplusVars.consent_hash); 92 $('.cookiesplus-consent-hash').show(); 93 } 94 } 95 96 cookieGdpr.removeCookies(); 97 98 cookieGdpr.loadJs(); 99 cookieGdpr.executeScriptsAndCss(); 100 //cookieGdpr.executeCustomScripts(); 101 102 // Don't display modal in Cookies CMS 103 if ($('body#cms').length) { 104 id = $('body#cms').attr('class').match(/cms-[\w-]*\b/); 105 if (id) { 106 id = parseInt(id[0].replace(/[^0-9]/gi, '')); 107 if ( 108 (typeof C_P_CMS_PAGE !== 'undefined' && 109 C_P_CMS_PAGE === id) 110 || ( 111 typeof C_P_COOKIES_POLICIES !== 'undefined' && 112 C_P_COOKIES_POLICIES === id 113 )) { 114 return; 115 } 116 } 117 } 118 119 // If the consent is given more than X days before and the user rejected the cookies, display again 120 if (typeof C_P_DISPLAY_AGAIN !== 'undefined' 121 && C_P_DISPLAY_AGAIN > 0 122 && consentRefused) {
123 var dateCookiesAccepted = new Date(cookiesplusVars.consent_date.replace(/\+/g, ' ')); 124 125 // Calculate X days ago 126 var xDaysAgo = new Date(); 127 xDaysAgo.setDate(xDaysAgo.getDate() - C_P_DISPLAY_AGAIN); 128 129 // Compare dates 130 if (dateCookiesAccepted < xDaysAgo) { 131 cookieGdpr.displayModal(); 132 } 133 } 134 135 if (typeof cookiesplusVars.C_P_DISPLAY_MODAL === 'undefined' 136 || (typeof cookiesplusVars.C_P_DISPLAY_MODAL !== 'undefined' 137 && cookiesplusVars.C_P_DISPLAY_MODAL == true)) { 138 cookieGdpr.displayModal(); 139 } 140 }, 141 displayModal: function () { 142 if (typeof $.uniform !== "undefined" && typeof $.uniform.update !== "undefined") { 143 $.uniform.update(".cookiesplus-finality-checkbox"); 144 $.uniform.restore(".cookiesplus-finality-checkbox"); 145 } 146 147 if (typeof C_P_FINALITIES_COUNT === 'undefined' 148 || C_P_FINALITIES_COUNT <= 1) { 149 console.log('%cC_P_FINALITIES_COUNT is empty', 'background: red; color: white'); 150 return; 151 } 152 153 if ($('.cookiesplus-move.container').length == 0) { 154 console.log('%cCookiesplus banner not found', 'background: red; color: white'); 155 } 156 157 if ($('.cookiesplus-move.container').length > 1) { 158 console.log('%cCookiesplus banner is duplicated', 'background: red; color: white'); 159 } 160 161 162 if (typeof C_P_NOT_AVAILABLE_OUTSIDE_EU !== 'undefined' 163 && C_P_NOT_AVAILABLE_OUTSIDE_EU === 0) { 164 console.log('%cC_P_NOT_AVAILABLE_OUTSIDE_EU', 'background: red; color: white'); 165 return; 166 } 167 168 this.displayOverlay(); 169 170 171 $('.cookiesplus-actions .first-layer').show(); 172 $("#cookiesplus-modal").addClass("first-layer-visible"); 173 174 $('.cookiesplus-finalities').slideUp('fast'); 175 $('.cookiesplus-actions .second-layer').hide(); 176 $("#cookiesplus-modal").removeClass("second-layer-visible"); 177 178 $('#cookiesplus-modal .cookiesplus-close-and-save').show(); 179 $('#cookiesplus-modal .cookiesplus-close').hide(); 180 181 $('#cookiesplus-modal').fadeIn('fast'); 182 183 184 // this.checkEvenDimensions('#cookiesplus-modal'); 185 /*$(window).resize(function () { 186 cookieGdpr.checkEvenDimensions('#cookiesplus-modal'); 187 });*/ 188 }, 189 displayModalAdvanced: function (fromFirstLayer) { 190 if (typeof $.uniform !== "undefined" && typeof $.uniform.update !== "undefined") { 191 $.uniform.update(".cookiesplus-finality-checkbox"); 192 $.uniform.restore(".cookiesplus-finality-checkbox"); 193 } 194 195 // Close all the finalities 196 $('.cookiesplus-finality-content').each(function() { 197 $(this).hide(); 198 $(this).parent().find('.cookiesplus-finality-chevron').removeClass('up').addClass('bottom'); 199 }); 200 201 /*if (C_P_FINALITIES_COUNT === 0) { 202 return; 203 }*/ 204 this.displayOverlay(); 205 206 if (typeof C_P_NOT_AVAILABLE_OUTSIDE_EU !== 'undefined' 207 && C_P_NOT_AVAILABLE_OUTSIDE_EU === 0) { 208 $('#cookiesplus-modal-not-available').fadeIn('fast'); 209 $('#cookiesplus-overlay').click(function() { 210 cookieGdpr.close(); 211 }) 212 } else { 213 $('#cookiesplus-modal').fadeIn('fast'); 214 215 $('.cookiesplus-actions .first-layer').hide(); 216 $("#cookiesplus-modal").removeClass("first-layer-visible"); 217 218 $('.cookiesplus-finalities').slideDown('fast'); 219 $('.cookiesplus-actions .second-layer').show(); 220 $("#cookiesplus-modal").addClass("second-layer-visible"); 221 222 if (!fromFirstLayer) { 223 $('#cookiesplus-modal .cookiesplus-close-and-save').hide(); 224 $('#cookiesplus-modal .cookiesplus-close-and-reject').hide(); 225 $('#cookiesplus-modal #cookiesplus-back').hide(); 226 227 $('#cookiesplus-modal .cookiesplus-close').show(); 228 } 229 } 230 231 // this.checkEvenDimensions('#cookiesplus-modal'); 232 }, 233 save: function () { 234 return cookieGdpr.sendForm(); 235 }, 236 acceptAllCookies: function () { 237 $('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=on]').prop('checked', true); 238 239 return cookieGdpr.sendForm(); 240 }, 241 rejectAllCookies: function () { 242 if ($('.cookiesplus-text-encourage').length > 0) { // Encourage text exists 243 if ($('.cookiesplus-text-encourage').is(":visible")) { // Encourage text is visible 244 $('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=off]').prop('checked', true); 245 246 return cookieGdpr.sendForm(); 247 } else { 248 $('.cookiesplus-text').hide(); 249 $('.cookiesplus-buttons').hide(); 250 251 $('.cookiesplus-text-encourage').show(); 252 $('.cookiesplus-buttons-encourage').show(); 253 254 return false;
255 } 256 } else { 257 $('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=off]').prop('checked', true); 258 259 return cookieGdpr.sendForm(); 260 } 261 }, 262 rejectAllCookiesFromX: function () { 263 $('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=off]').prop('checked', true); 264 265 return cookieGdpr.sendForm(); 266 }, 267 displayOverlay: function () { 268 if (typeof C_P_OVERLAY !== 'undefined' && C_P_OVERLAY === '1') { 269 $('#cookiesplus-overlay').fadeIn('fast'); 270 $('#cookiesplus-overlay').css('background-color', 'rgba(0, 0, 0, ' + C_P_OVERLAY_OPACITY + ')'); 271 } 272 273 $('#cookiesplus-overlay').off('click.shake'); 274 275 let isShaking = false; 276 277 $('#cookiesplus-overlay').on('click.shake', function () { 278 if (isShaking) return; 279 isShaking = true; 280 281 cookieGdpr.shake($('#cookiesplus-modal'), 4, 2, 20, function () { 282 isShaking = false; 283 }); 284 }); 285 }, 286 close: function () { 287 $('#cookiesplus-modal, #cookiesplus-modal-not-available, #cookiesplus-overlay').hide(); 288 // $('.cookiesplus-save').prop('disabled', true); 289 }, 290 checkEvenDimensions: function (div) { 291 // $(div).css('height', ''); 292 var styleObject = $(div).prop('style'); 293 styleObject.removeProperty('height'); 294 if ($(div).height() % 2 === 1) { 295 $(div).height(2 * Math.round(($(div).height() - 1) / 2)); 296 } 297 298 styleObject.removeProperty('width'); 299 $(div).css('width', ''); 300 if ($(div).width() % 2 === 1) { 301 $(div).width(2 * Math.round(($(div).width() - 1) / 2)); 302 } 303 }, 304 shake: function (div, shakes, distance, duration, done) { 305 if (shakes > 0) { 306 div.each(function () { 307 var $el = $(this); 308 var left = $el.css('left'); 309 310 $el.animate({left: "-=" + distance}, duration, function () { 311 $el.animate({left: "+=" + distance * 2}, duration, function () { 312 $el.animate({left: left}, duration, function () { 313 // Recursive call, pass the same callback 314 cookieGdpr.shake($el, shakes - 1, distance, duration, done); 315 }); 316 }); 317 }); 318 }); 319 } else if (typeof done === 'function') { 320 done(); // All shakes completed 321 } 322 }, 323 sendForm: function() { 324 this.consentsGiven = true; 325 326 // Read cookie value 327 let cookiesplusVars = cookieGdpr.tryParseJSONObject(decodeURIComponent(cookieGdpr.getCookiesPlusCookieValue('cookiesplus'))); 328 329 if (cookiesplusVars instanceof Array) { 330 cookiesplusVars = Object.assign({}, cookiesplusVars); 331 } 332 333 // Save new info 334 cookiesplusVars['C_P_DISPLAY_MODAL'] = false; 335 336 cookiesplusVars['consents'] = {}; 337 $('#cookiesplus-form input:checked').each(function() { 338 cookiesplusVars['consents'][$(this).attr('name')] = $(this).val(); 339 }); 340 341 cookiesplusVars['consent_date'] = C_P_DATE; 342 343 var expireTime = new Date(); 344 expireTime.setDate(expireTime.getDate() + C_P_EXPIRY); 345 var expires = "expires=" + expireTime.toUTCString(); 346 347 var cookieString = "cookiesplus=" + encodeURIComponent(JSON.stringify(cookiesplusVars)) + "; domain=" + C_P_DOMAIN + "; " + expires + "; path=/; SameSite=" + PS_COOKIE_SAMESITE + ";"; 348 349 if (PS_COOKIE_SECURE === 1) { 350 cookieString += " Secure;"; 351 } 352 353 document.cookie = cookieString; 354 355 cookieGdpr.removeCookies(); 356 357 if (typeof C_P_REFRESH !== 'undefined' 358 && !C_P_REFRESH) { 359 $.ajax({ 360 type: "POST", 361 cache : false, 362 async : true, 363 url : $('#cookiesplus-form').attr('action'), 364 data: 'saveCookiesPlusPreferences=&ajax=1&'+$('#cookiesplus-form').serialize(), 365 dataType: 'json', 366 headers: { 367 "cache-control": "no-cache" 368 }, 369 success: function(data) { 370 if (data.consent_hash) { 371 $('.cookiesplus-consent-hash a').attr('href', C_P_CONSENT_DOWNLOAD + '?hash=' + cookiesplusVars.consent_hash + '&getPdf'); 372 $('.cookiesplus-consent-hash a').text(data.consent_hash); 373 $('.cookiesplus-consent-hash').show(); 374 375 cookiesplusVars['consent_hash'] = data.consent_hash; 376 377 var cookieString = "cookiesplus=" + encodeURIComponent(JSON.stringify(cookiesplusVars)) + "; domain=" + C_P_DOMAIN + "; " + expires + "; path=/; SameSite=" + PS_COOKIE_SAMESITE + ";"; 378 379 if (PS_COOKIE_SECURE === 1) { 380 cookieString += " Secure;"; 381 } 382 383 document.cookie = cookieString; 384 } 385 386 /*var d = new Date(); 387 d.setTime(d.getTime() + (365 * 1000)); 388 var expires = "expires=" + d.toUTCString();*/ 389 // document.cookie = "cookiesplus=" + data.cookie + "; " + expires + ";path=/"; 390 391 cookieGdpr.loadJs(); 392 cookieGdpr.executeScriptsAndCss(); 393 //cookieGdpr.executeCustomScripts(); 394 cookieGdpr.fireGTMEvents(); 395 cookieGdpr.fireMUETEvents(); 396 //cookieGdpr.fireFBPixel(); 397 }, 398 error: function(XMLHttpRequest, textStatus, errorThrown) { 399 window.cookiesplus_debug === true && console.log(errorThrown); 400 } 401 }); 402 403 cookieGdpr.close(); 404 405 return false;
406 } else { 407 cookieGdpr.close(); 408 409 return true; 410 } 411 }, 412 removeCookies : function() { 413 $('#cookiesplus-form input:checked').each(function() { 414 if ($(this).val() !== 'on') { 415 // Save preferences 416 let nameAttr = $(this).attr('name'); // Get the attribute value 417 let finalityId = parseInt(nameAttr.split('-').pop()); // Extract and convert to integer 418 if (typeof C_P_COOKIE_CONFIG[finalityId] !== 'undefined' 419 && typeof C_P_COOKIE_CONFIG[finalityId].cookies !== 'undefined') { 420 Object.keys(C_P_COOKIE_CONFIG[finalityId].cookies).forEach(function (key) { 421 if (C_P_COOKIE_CONFIG[finalityId].cookies[key].name.includes('#')) { 422 let cookieValue = C_P_COOKIE_CONFIG[finalityId].cookies[key].name; 423 let hashIndex = cookieValue.indexOf("#"); 424 let prefix = cookieValue.substr(0, hashIndex); 425 let suffix = cookieValue.substr(hashIndex + 1); 426 window.cookiesplus_debug === true && console.log('Removing cookies starting with ' + prefix + ' and ending with ' + suffix); 427 document.cookie.split(";").forEach(function(cookie) { 428 let cookieName = cookie.trim().split("=")[0]; 429 if (cookieName.indexOf(prefix) === 0 && cookieName.endsWith(suffix)) { 430 var urlParts = location.hostname.split('.'); 431 for (var i = 2; i < urlParts.length + 1; i++) { 432 window.cookiesplus_debug === true && console.log('Removing cookie ' + cookieName); 433 document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/;'; 434 document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain='+urlParts.slice(-i).join('.'); 435 document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain=.'+urlParts.slice(-i).join('.'); 436 } 437 } 438 }); 439 } else { 440 window.cookiesplus_debug === true && console.log('Removing cookie ' + C_P_COOKIE_CONFIG[finalityId].cookies[key].name); 441 var urlParts = location.hostname.split('.'); 442 for (var i = 2; i < urlParts.length + 1; i++) { 443 document.cookie = C_P_COOKIE_CONFIG[finalityId].cookies[key].name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/;'; 444 document.cookie = C_P_COOKIE_CONFIG[finalityId].cookies[key].name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain='+urlParts.slice(-i).join('.'); 445 document.cookie = C_P_COOKIE_CONFIG[finalityId].cookies[key].name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain=.'+urlParts.slice(-i).join('.'); 446 } 447 } 448 }) 449 } 450 } 451 }); 452 }, 453 loadJs : function() { 454 // Don't execute scripts if the user has not given the consent yet 455 if (!this.consentsGiven) { 456 return; 457 } 458 459 // Get the variable names starting with 'cookiesplus_js_' 460 const variableNames = this.getVariablesStartingWith('cookiesplus_js_'); 461 462 // Iterate over each variable name, access the variable, parse it, and add to the array 463 variableNames.forEach(variableName => { 464 try { 465 const variableValue = window[variableName]; 466 if (variableValue) { 467 const parsedValue = cookieGdpr.tryParseJSONObject(variableValue); 468 469 var hookModuleData = []; 470 hookModuleData['id_module'] = parsedValue.id_module; 471 hookModuleData['location'] = `#${parsedValue.divName}`; 472 hookModuleData['finalities'] = parsedValue.finalities; 473 hookModuleData['script'] = parsedValue.script; 474 hookModuleData['js'] = cookieGdpr.tryParseJSONObject(parsedValue.js); 475 hookModuleData['css'] = cookieGdpr.tryParseJSONObject(parsedValue.css); 476 477 window.cookiesPlusBlockedScripts.push(hookModuleData); 478 } 479 } catch (e) { 480 console.error(`Error parsing variable ${variableName}:`, e); 481 } 482 }); 483 484 // Append blocked script, js and css 485 for (var i = 0; i < cookiesPlusBlockedScripts.length; i++) { 486 let cookiesPlusBlockedScript = cookiesPlusBlockedScripts[i]; 487 let finalities = cookiesPlusBlockedScript['finalities'].split(','); 488 let allFinalitiesAccepted = true; 489 for (var j = 0; j < finalities.length; j++) {
490 if (!$('#cookiesplus-form input#cookiesplus-finality-' + finalities[j] + '-on:checked').val()) { 491 allFinalitiesAccepted = false; 492 break; 493 } 494 } 495 496 if (allFinalitiesAccepted) { 497 // Append JS and scripts 498 // We add JS first because it's possible that the scripts need the JS library 499 if (!$.isEmptyObject(cookiesPlusBlockedScript['js'])) { 500 // Counter to keep track of the loaded scripts 501 502 Object.keys(cookiesPlusBlockedScript['js']).forEach((key) => { 503 self.loadedScriptsTotal += Object.keys(cookiesPlusBlockedScript['js']).length; 504 var s = document.createElement( 'script'); 505 s.setAttribute( 'src', cookiesPlusBlockedScript['js'][key] ); 506 //s.setAttribute('defer', ''); 507 508 s.onload = () => { 509 // Increment the loaded scripts count 510 self.loadedScriptsCount++; 511 }; 512 513 document.body.appendChild(s); 514 }) 515 516 // Reset the js array after all scripts are added 517 cookiesPlusBlockedScripts[i]['js'] = []; 518 } 519 } 520 } 521 522 return true; 523 }, 524 executeScriptsAndCss : function() { 525 // Store reference to 'this' 526 var self = this; 527 528 // Don't execute scripts if the user has not given the consent yet 529 if (!self.consentsGiven) { 530 return; 531 } 532 533 cookieGdpr.tryParseJSONObject(decodeURIComponent(cookieGdpr.getCookiesPlusCookieValue('cookiesplus'))) 534 535 if (self.loadedScriptsCount === self.loadedScriptsTotal) { 536 self.executeScriptsAndCssLoaded(); 537 self.executeCustomScripts(); 538 self.fireFBPixel(); 539 self.replaceYTDomain(); 540 } else { 541 // Check again after a delay 542 setTimeout(function () { 543 self.executeScriptsAndCss(); 544 }, 100); // Adjust the delay as needed 545 } 546 }, 547 executeScriptsAndCssLoaded : function() { 548 // Get the variable names starting with 'cookiesplus_js_' 549 const variableNames = this.getVariablesStartingWith('cookiesplus_js_'); 550 551 // Iterate over each variable name, access the variable, parse it, and add to the array 552 variableNames.forEach(variableName => { 553 try { 554 const variableValue = window[variableName]; 555 if (variableValue) { 556 const parsedValue = cookieGdpr.tryParseJSONObject(variableValue); 557 558 var hookModuleData = []; 559 hookModuleData['id_module'] = parsedValue.id_module; 560 hookModuleData['location'] = `#${parsedValue.divName}`; 561 hookModuleData['finalities'] = parsedValue.finalities; 562 hookModuleData['script'] = parsedValue.script; 563 hookModuleData['js'] = cookieGdpr.tryParseJSONObject(parsedValue.js); 564 hookModuleData['css'] = cookieGdpr.tryParseJSONObject(parsedValue.css); 565 566 window.cookiesPlusBlockedScripts.push(hookModuleData); 567 } 568 } catch (e) { 569 console.error(`Error parsing variable ${variableName}:`, e); 570 } 571 }); 572 573 // Append blocked script, js and css 574 for (var i = 0; i < cookiesPlusBlockedScripts.length; i++) { 575 let cookiesPlusBlockedScript = cookiesPlusBlockedScripts[i]; 576 let finalities = cookiesPlusBlockedScript['finalities'].split(','); 577 let allFinalitiesAccepted = true; 578 for (var j = 0; j < finalities.length; j++) { 579 if (!$('#cookiesplus-form input#cookiesplus-finality-' + finalities[j] + '-on:checked').val()) { 580 allFinalitiesAccepted = false; 581 break; 582 } 583 } 584 585 if (allFinalitiesAccepted) {
586 if (cookiesPlusBlockedScript['script']) { 587 $(cookiesPlusBlockedScript['location']).replaceWith(cookiesPlusBlockedScript['script']); 588 cookiesPlusBlockedScripts[i]['script'] = []; 589 } 590 591 // Append CSS 592 Object.keys(cookiesPlusBlockedScript['css']).forEach(function(key) { 593 var s = document.createElement('link'); 594 s.setAttribute('rel', 'stylesheet'); 595 s.setAttribute('href', cookiesPlusBlockedScript['css'][key] ); 596 document.head.appendChild(s); 597 }) 598 cookiesPlusBlockedScripts[i]['css'] = []; 599 } 600 } 601 602 return true; 603 }, 604 executeCustomScripts : function() { 605 // For each checked finality, execute associated script 606 $('#cookiesplus-form input:checked').each(function() { 607 if ($(this).val() === 'on') { 608 // Execute finality script 609 if (typeof C_P_COOKIE_CONFIG !== 'undefined' 610 && C_P_COOKIE_CONFIG[$(this).data('finality-id')] 611 && C_P_COOKIE_CONFIG[$(this).data('finality-id')].script) { 612 $('body').append('<div style="display: none;" id="cookiesplus-scripts-' + $(this).data('finality-id') + '"></div>'); 613 cookieGdpr.setInnerHTML(document.querySelector('#cookiesplus-scripts-' + $(this).data('finality-id')), C_P_COOKIE_CONFIG[$(this).data('finality-id')].script); 614 615 // Remove script to avoid execute it more than once 616 C_P_COOKIE_CONFIG[$(this).data('finality-id')].script = []; 617 } 618 619 // Add code to body 620 if (typeof C_P_COOKIE_CONFIG !== 'undefined' && 621 C_P_COOKIE_CONFIG[$(this).data('finality-id')] && 622 C_P_COOKIE_CONFIG[$(this).data('finality-id')].body_code) { 623 $('body').append('<div style="display: none;" id="cookiesplus-body_code-' + $(this).data('finality-id') + '"></div>'); 624 cookieGdpr.setInnerHTML(document.querySelector('#cookiesplus-body_code-' + $(this).data('finality-id')), C_P_COOKIE_CONFIG[$(this).data('finality-id')].body_code); 625 626 C_P_COOKIE_CONFIG[$(this).data('finality-id')].body_code = []; 627 } 628 } else if ($(this).val() === 'off') { 629 // Execute finality script 630 if (typeof C_P_COOKIE_CONFIG !== 'undefined' 631 && C_P_COOKIE_CONFIG[$(this).data('finality-id')] 632 && C_P_COOKIE_CONFIG[$(this).data('finality-id')].script_not) { 633 $('body').append('<div style="display: none;" id="cookiesplus-scripts-' + $(this).data('finality-id') + '"></div>'); 634 cookieGdpr.setInnerHTML(document.querySelector('#cookiesplus-scripts-' + $(this).data('finality-id')), C_P_COOKIE_CONFIG[$(this).data('finality-id')].script_not); 635 636 // Remove script to avoid execute it more than once 637 C_P_COOKIE_CONFIG[$(this).data('finality-id')].script_not = []; 638 } 639 } 640 }); 641 642 return true; 643 }, 644 fireGTMEvents : function() { 645 // For each checked finality, execute associated script 646 let consentUpdateObject = {}; // Create an empty object to accumulate keys and values 647 $('#cookiesplus-form input:checked').each(function () { 648 if (typeof C_P_COOKIE_CONFIG !== 'undefined' 649 && C_P_COOKIE_CONFIG[$(this).data('finality-id')] 650 && C_P_COOKIE_CONFIG[$(this).data('finality-id')].gtm_consent_type) { 651 Object.keys(C_P_COOKIE_CONFIG[$(this).data('finality-id')].gtm_consent_type).forEach(key => { 652 if ($(this).val() === 'on') { 653 // Grant consent 654 window.cookiesplus_debug === true && console.log('GTM - Granting consent ' + key); 655 consentUpdateObject[key] = 'granted'; 656 } else {
657 // Deny consent 658 window.cookiesplus_debug === true && console.log('GTM - Denying consent ' + key); 659 consentUpdateObject[key] = 'denied'; 660 } 661 }); 662 } 663 }); 664 665 window.dataLayer = window.dataLayer || []; 666 function gtag() { dataLayer.push(arguments); } 667 668 // Send all the accumulated keys and values to gtag 669 window.cookiesplus_debug === true && console.log('GTM - Consent update object:', consentUpdateObject); 670 gtag('consent', 'update', consentUpdateObject); 671 672 $('#cookiesplus-form input:checked').each(function() { 673 if ($(this).val() === 'on') { 674 // Fire GTM events 675 if (typeof C_P_COOKIE_CONFIG !== 'undefined' 676 && C_P_COOKIE_CONFIG[$(this).data('finality-id')] 677 && C_P_COOKIE_CONFIG[$(this).data('finality-id')].firingEvent) { 678 window.cookiesplus_debug === true && console.log('Firing event '+[C_P_COOKIE_CONFIG[$(this).data('finality-id')].firingEvent]); 679 dataLayer.push({'event': [C_P_COOKIE_CONFIG[$(this).data('finality-id')].firingEvent]}); 680 } 681 } 682 }); 683 //dataLayer.push({'event': 'gtm.init_consent'}); 684 685 return true; 686 }, 687 fireMUETEvents : function() { 688 // For each checked finality, execute associated script 689 let consentUpdateObject = {}; // Create an empty object to accumulate keys and values 690 $('#cookiesplus-form input:checked').each(function () { 691 if (typeof C_P_COOKIE_CONFIG !== 'undefined' 692 && C_P_COOKIE_CONFIG[$(this).data('finality-id')] 693 && C_P_COOKIE_CONFIG[$(this).data('finality-id')].muet_consent_type) { 694 Object.keys(C_P_COOKIE_CONFIG[$(this).data('finality-id')].muet_consent_type).forEach(key => { 695 if ($(this).val() === 'on') { 696 // Grant consent 697 window.cookiesplus_debug === true && console.log('MUET - Granting consent ' + key); 698 consentUpdateObject[key] = 'granted'; 699 } else { 700 // Deny consent 701 window.cookiesplus_debug === true && console.log('MUET - Denying consent ' + key); 702 consentUpdateObject[key] = 'denied'; 703 } 704 }); 705 } 706 }); 707 708 if (consentUpdateObject && Object.keys(consentUpdateObject).length > 0) { 709 window.uetq = window.uetq || []; 710 711 // Send all the accumulated keys and values to gtag 712 window.cookiesplus_debug === true && console.log('MUET - Consent update object:', consentUpdateObject); 713 window.uetq.push('consent', { 714 consentUpdateObject 715 }); 716 } 717 718 return true; 719 }, 720 fireFBPixel : function() { 721 if (typeof C_P_COOKIE_CONFIG === 'undefined') { 722 return false; 723 } 724 725 let fbAllConsents = false; 726 727 // For each finality, execute associated script 728 $('#cookiesplus-form input:checked').each(function() { 729 // Fire FB Pixel 730 fbAllConsents = true; 731 if ($(this).val() !== 'on' 732 && C_P_COOKIE_CONFIG[$(this).data('finality-id')] 733 && C_P_COOKIE_CONFIG[$(this).data('finality-id')].fb) { 734 fbAllConsents = false; 735 return false; 736 } 737 }); 738 739 if (fbAllConsents) { 740 window.cookiesplus_debug === true && console.log('Firing FB Pixel'); 741 if (typeof fbq !== 'undefined') { 742 fbq('consent', 'grant'); 743 } 744 } 745 746 return true; 747 }, 748 replaceYTDomain : function() { 749 if (typeof C_P_COOKIE_CONFIG === 'undefined') { 750 return false; 751 } 752 753 let ytAllConsents = false; 754 755 // For each finality, execute associated script 756 $('#cookiesplus-form input:checked').each(function() { 757 // Fire FB Pixel 758 ytAllConsents = true; 759 if ($(this).val() !== 'on' 760 && C_P_COOKIE_CONFIG[$(this).data('finality-id')] 761 && C_P_COOKIE_CONFIG[$(this).data('finality-id')].yt) { 762 ytAllConsents = false;
763 return false; 764 } 765 }); 766 767 if (ytAllConsents) { 768 window.cookiesplus_debug === true && console.log('Replacing YT domain'); 769 $('iframe, script').each(function() { 770 var src = $(this).attr('src'); 771 if (src && src.includes('youtube-nocookie.com')) { 772 var newSrc = src.replace('youtube-nocookie.com', 'youtube.com'); 773 $(this).attr('src', newSrc); 774 } 775 }); 776 777 $('a').each(function() { 778 var href = $(this).attr('href'); 779 if (href && href.includes('youtube-nocookie.com')) { 780 var newHref = href.replace('youtube-nocookie.com', 'youtube.com'); 781 $(this).attr('href', newHref); 782 } 783 }); 784 } 785 786 return true; 787 }, 788 setInnerHTML : function(elm, html) { 789 elm.innerHTML = html; 790 Array.from(elm.querySelectorAll("script")).forEach( function(oldScript) { 791 const newScript = document.createElement("script"); 792 Array.from(oldScript.attributes) 793 .forEach( function(attr) { 794 newScript.setAttribute(attr.name, attr.value) 795 }); 796 newScript.appendChild(document.createTextNode(oldScript.innerHTML)); 797 oldScript.parentNode.replaceChild(newScript, oldScript); 798 }); 799 }, 800 tryParseJSONObject: function(jsonString) { 801 try { 802 var o = JSON.parse(jsonString); 803 804 if (o && typeof o === "object") { 805 return o; 806 } 807 } 808 catch (e) { } 809 810 return {}; 811 }, 812 getCookiesPlusCookieValue: function(name) { 813 // return document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || ''; 814 var match = document.cookie.match(RegExp('(?:^|;\\s*)' + name + '=([^;]*)')); 815 return match ? match[1] : null; 816 }, 817 getVariablesStartingWith: function(prefix) { 818 const globalObj = typeof window !== 'undefined' ? window : global; 819 return Object.keys(globalObj).filter(key => key.startsWith(prefix)); 820 } 821} 822 823function waitForJqueryAndInitCookies() { 824 if (typeof jQuery !== 'undefined') { 825 // jQuery is loaded, you can use it here 826 $(document).ready(function() { 827 if (window.cookiesplus_debug) { 828 debugger; 829 } 830 cookieGdpr.init(); 831 832 $('.cookiesplus-displaymodal').on('click', function() { 833 cookieGdpr.displayModal(); 834 }) 835 836 $('.cookiesplus-displaymodaladvanced').on('click', function() { 837 cookieGdpr.displayModalAdvanced(); 838 }) 839 840 $('a[href*="#cookiesplus-displaymodaladvanced"]').click(function(e) { 841 e.preventDefault(); 842 cookieGdpr.displayModalAdvanced(); 843 }); 844 }); 845 } else { 846 // jQuery is not loaded, retry after a delay 847 setTimeout(waitForJqueryAndInitCookies, 100); 848 } 849} 850 851waitForJqueryAndInitCookies();
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.