1/* 2 * ISC License 3 * 4 * Copyright (c) 2024 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 2024 idnovate 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 this.loadedScriptsCount = 0; 28 this.loadedScriptsTotal = 0; 29 this.consentsGiven = 0; 30 31 if (document.cookie.indexOf('cookiesplus=') === -1) { 32 // cookiesplus cookie doesn't exist, initialize it 33 // cookiesplusVars = []; 34 // cookiesplusVars['C_P_DISPLAY_MODAL'] = false; 35 36 if (typeof C_P_EXPIRY === 'undefined') { 37 console.log('%cC_P_EXPIRY is not defined', 'background: red; color: white'); 38 return; 39 } 40 41 var expireTime = new Date(); 42 expireTime.setDate(expireTime.getDate() + C_P_EXPIRY); 43 var expires = "expires=" + expireTime.toUTCString(); 44 45 var cookieString = "cookiesplus={}; " + expires + "; path=/; SameSite=" + PS_COOKIE_SAMESITE + ";"; 46 47 if (PS_COOKIE_SECURE === 1) { 48 cookieString += " Secure;"; 49 } 50 51 document.cookie = cookieString; 52 } 53 54 // mode DIVs before </body> 55 $('.cookiesplus-move').appendTo(document.body); 56 57 let cookiesplusVars = cookieGdpr.tryParseJSONObject(decodeURIComponent(cookieGdpr.getCookiesPlusCookieValue('cookiesplus'))); 58 59 // Initialize values 60 let consentRefused = false; 61 if (typeof cookiesplusVars.consents === 'object' && cookiesplusVars.consents !== null) { 62 cookiesplusFinalities = Object.keys(cookiesplusVars.consents).filter(v => v.startsWith('cookiesplus-finality')); 63 64 this.consentsGiven = false; 65 var self = this; // Store reference to 'this' 66 cookiesplusFinalities.forEach(function (key) { 67 self.consentsGiven = true; 68 if (cookiesplusVars.consents[key] === 'on') { 69 $("label[for='" + key + '-' + cookiesplusVars.consents[key] + "']").click() 70 } else { 71 consentRefused = true; 72 } 73 }) 74 75 if (cookiesplusVars.consent_link && cookiesplusVars.consent_hash) { 76 $('.cookiesplus-consent-hash a').attr('href', C_P_CONSENT_DOWNLOAD + cookiesplusVars.consent_link); 77 $('.cookiesplus-consent-hash a').text(cookiesplusVars.consent_hash); 78 $('.cookiesplus-consent-hash').show(); 79 } 80 } 81 82 cookieGdpr.removeCookies(); 83 84 cookieGdpr.loadJs(); 85 cookieGdpr.executeScriptsAndCss(); 86 //cookieGdpr.executeCustomScripts(); 87 88 // Don't display modal in Cookies CMS 89 if ($('body#cms').length) { 90 id = $('body#cms').attr('class').match(/cms-[\w-]*\b/); 91 if (id) { 92 id = id[0].replace(/[^0-9]/gi, ''); 93 if (typeof cookiesplusVars.C_P_CMS_PAGE !== 'undefined' && 94 (typeof cookiesplusVars.C_P_CMS_PAGE === id)) { 95 return; 96 } 97 } 98 } 99 100 // If the consent is given more than X days before and the user rejected the cookies, display again 101 if (typeof C_P_DISPLAY_AGAIN !== 'undefined' 102 && C_P_DISPLAY_AGAIN > 0 103 && consentRefused) {
104 var dateCookiesAccepted = new Date(cookiesplusVars.consent_date.replace(/\+/g, ' ')); 105 106 // Calculate X days ago 107 var xDaysAgo = new Date(); 108 xDaysAgo.setDate(xDaysAgo.getDate() - C_P_DISPLAY_AGAIN); 109 110 // Compare dates 111 if (dateCookiesAccepted < xDaysAgo) { 112 cookieGdpr.displayModal(); 113 } 114 } 115 116 if (typeof cookiesplusVars.C_P_DISPLAY_MODAL === 'undefined' 117 || (typeof cookiesplusVars.C_P_DISPLAY_MODAL !== 'undefined' 118 && cookiesplusVars.C_P_DISPLAY_MODAL == true)) { 119 cookieGdpr.displayModal(); 120 } 121 }, 122 displayModal: function () { 123 if (typeof $.uniform !== "undefined" && typeof $.uniform.update !== "undefined") { 124 $.uniform.update(".cookiesplus-finality-checkbox"); 125 $.uniform.restore(".cookiesplus-finality-checkbox"); 126 } 127 128 if (typeof C_P_FINALITIES_COUNT === 'undefined' 129 || C_P_FINALITIES_COUNT <= 1) { 130 console.log('%cC_P_FINALITIES_COUNT is empty', 'background: red; color: white'); 131 return; 132 } 133 134 if ($('.cookiesplus-move.container').length == 0) { 135 console.log('%cCookiesplus not found', 'background: red; color: white'); 136 } 137 138 if ($('.cookiesplus-move.container').length > 1) { 139 console.log('%cCookiesplus banner is duplicated', 'background: red; color: white'); 140 } 141 142 143 if (typeof C_P_NOT_AVAILABLE_OUTSIDE_EU !== 'undefined' 144 && C_P_NOT_AVAILABLE_OUTSIDE_EU === 0) { 145 console.log('%cC_P_NOT_AVAILABLE_OUTSIDE_EU', 'background: red; color: white'); 146 return; 147 } 148 149 this.displayOverlay(); 150 151 $('.cookiesplus-actions .first-layer').show(); 152 153 $('.cookiesplus-finalities').hide(); 154 $('.cookiesplus-actions .second-layer').hide(); 155 156 $('#cookiesplus-modal .cookiesplus-close-and-save').show(); 157 $('#cookiesplus-modal .cookiesplus-close').hide(); 158 159 $('#cookiesplus-modal').fadeIn('fast'); 160 161 162 // this.checkEvenDimensions('#cookiesplus-modal'); 163 /*$(window).resize(function () { 164 cookieGdpr.checkEvenDimensions('#cookiesplus-modal'); 165 });*/ 166 }, 167 displayModalAdvanced: function (fromFirstLayer) { 168 if (typeof $.uniform !== "undefined" && typeof $.uniform.update !== "undefined") { 169 $.uniform.update(".cookiesplus-finality-checkbox"); 170 $.uniform.restore(".cookiesplus-finality-checkbox"); 171 } 172 173 /*if (C_P_FINALITIES_COUNT === 0) { 174 return; 175 }*/ 176 this.displayOverlay(); 177 178 if (typeof C_P_NOT_AVAILABLE_OUTSIDE_EU !== 'undefined' 179 && C_P_NOT_AVAILABLE_OUTSIDE_EU === 0) { 180 $('#cookiesplus-modal-not-available').fadeIn('fast'); 181 $('#cookiesplus-overlay').click(function() { 182 cookieGdpr.close(); 183 }) 184 } else { 185 $('#cookiesplus-modal').fadeIn('fast'); 186 187 $('.cookiesplus-actions .first-layer').hide(); 188 189 $('.cookiesplus-finalities').show(); 190 $('.cookiesplus-actions .second-layer').show(); 191 192 if (!fromFirstLayer) { 193 $('#cookiesplus-modal .cookiesplus-close-and-save').hide(); 194 $('#cookiesplus-modal .cookiesplus-close-and-reject').hide(); 195 $('#cookiesplus-modal #cookiesplus-back').hide(); 196 197 $('#cookiesplus-modal .cookiesplus-close').show(); 198 } 199 } 200 201 // this.checkEvenDimensions('#cookiesplus-modal'); 202 }, 203 save: function () { 204 return cookieGdpr.sendForm(); 205 }, 206 acceptAllCookies: function () { 207 $('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=on]').prop('checked', true); 208 209 return cookieGdpr.sendForm(); 210 }, 211 rejectAllCookies: function () { 212 $('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=off]').prop('checked', true); 213 214 return cookieGdpr.sendForm(); 215 }, 216 displayOverlay: function () { 217 if (typeof C_P_OVERLAY !== 'undefined' 218 && C_P_OVERLAY === '1') { 219 $('#cookiesplus-overlay').fadeIn('fast'); 220 $('#cookiesplus-overlay').css('background-color', 'rgba(0, 0, 0, ' + C_P_OVERLAY_OPACITY + ')'); 221 } 222 $('#cookiesplus-overlay').click(function(){ 223 cookieGdpr.shake($('#cookiesplus-modal'), 4, 2, 20); 224 }); 225 }, 226 close: function () { 227 $('#cookiesplus-modal, #cookiesplus-modal-not-available, #cookiesplus-overlay').hide(); 228 // $('.cookiesplus-save').prop('disabled', true); 229 }, 230 checkEvenDimensions: function (div) { 231 // $(div).css('height', ''); 232 var styleObject = $(div).prop('style'); 233 styleObject.removeProperty('height'); 234 if ($(div).height() % 2 === 1) { 235 $(div).height(2 * Math.round(($(div).height() - 1) / 2)); 236 } 237 238 styleObject.removeProperty('width'); 239 $(div).css('width', ''); 240 if ($(div).width() % 2 === 1) { 241 $(div).width(2 * Math.round(($(div).width() - 1) / 2)); 242 } 243 }, 244 shake: function (div, shakes, distance, duration) { 245 if (shakes > 0) { 246 div.each(function () { 247 var $el = $(this); 248 var left = $el.css('left'); 249 $el.animate({left: "-=" + distance}, duration, function () { 250 $el.animate({left: "+=" + distance * 2}, duration, function () { 251 $el.animate({left: left}, duration, function () { 252 cookieGdpr.shake($el, shakes - 1, distance, duration); 253 }); 254 }); 255 }); 256 }); 257 } 258 }, 259 sendForm: function() { 260 this.consentsGiven = true; 261 262 // Read cookie value
263 let cookiesplusVars = cookieGdpr.tryParseJSONObject(decodeURIComponent(cookieGdpr.getCookiesPlusCookieValue('cookiesplus'))); 264 265 if (cookiesplusVars instanceof Array) { 266 cookiesplusVars = Object.assign({}, cookiesplusVars); 267 } 268 269 // Save new info 270 cookiesplusVars['C_P_DISPLAY_MODAL'] = false; 271 272 cookiesplusVars['consents'] = {}; 273 $('#cookiesplus-form input:checked').each(function() { 274 cookiesplusVars['consents'][$(this).attr('name')] = $(this).val(); 275 }); 276 277 cookiesplusVars['consent_date'] = C_P_DATE; 278 279 var expireTime = new Date(); 280 expireTime.setDate(expireTime.getDate() + C_P_EXPIRY); 281 var expires = "expires=" + expireTime.toUTCString(); 282 283 var cookieString = "cookiesplus=" + encodeURIComponent(JSON.stringify(cookiesplusVars)) + "; " + expires + "; path=/; SameSite=" + PS_COOKIE_SAMESITE + ";"; 284 285 if (PS_COOKIE_SECURE === 1) { 286 cookieString += " Secure;"; 287 } 288 289 document.cookie = cookieString; 290 291 cookieGdpr.removeCookies(); 292 293 if (typeof C_P_REFRESH !== 'undefined' 294 && !C_P_REFRESH) { 295 $.ajax({ 296 type: "POST", 297 cache : false, 298 async : true, 299 url : $('#cookiesplus-form').attr('action'), 300 data: 'saveCookiesPlusPreferences=&ajax=1&'+$('#cookiesplus-form').serialize(), 301 dataType: 'json', 302 headers: { 303 "cache-control": "no-cache" 304 }, 305 success: function(data) { 306 if (data.consent_link && data.consent_hash) { 307 $('.cookiesplus-consent-hash a').attr('href', data.consent_link); 308 $('.cookiesplus-consent-hash a').text(data.consent_hash); 309 $('.cookiesplus-consent-hash').show(); 310 311 cookiesplusVars['consent_hash'] = data.consent_hash; 312 313 var cookieString = "cookiesplus=" + encodeURIComponent(JSON.stringify(cookiesplusVars)) + "; " + expires + "; path=/; SameSite=" + PS_COOKIE_SAMESITE + ";"; 314 315 if (PS_COOKIE_SECURE === 1) { 316 cookieString += " Secure;"; 317 } 318 319 document.cookie = cookieString; 320 } 321 322 /*var d = new Date(); 323 d.setTime(d.getTime() + (365 * 1000)); 324 var expires = "expires=" + d.toUTCString();*/ 325 // document.cookie = "cookiesplus=" + data.cookie + "; " + expires + ";path=/"; 326 327 cookieGdpr.loadJs(); 328 cookieGdpr.executeScriptsAndCss(); 329 //cookieGdpr.executeCustomScripts(); 330 cookieGdpr.fireGTMEvents(); 331 //cookieGdpr.fireFBPixel(); 332 }, 333 error: function(XMLHttpRequest, textStatus, errorThrown) { 334 window.cookiesplus_debug === true && console.log(errorThrown); 335 } 336 }); 337 338 cookieGdpr.close(); 339 340 return false; 341 } else { 342 cookieGdpr.close(); 343 344 return true; 345 } 346 }, 347 removeCookies : function() { 348 $('#cookiesplus-form input:checked').each(function() { 349 if ($(this).val() !== 'on') { 350 // Save preferences 351 let finalityId = $(this).data('finality-id'); 352 if (typeof C_P_THEOBJECT[finalityId] !== 'undefined' 353 && typeof C_P_THEOBJECT[finalityId].cookies !== 'undefined') { 354 Object.keys(C_P_THEOBJECT[finalityId].cookies).forEach(function (key) { 355 if (C_P_THEOBJECT[finalityId].cookies[key].name.includes('#')) { 356 let cookieValue = C_P_THEOBJECT[finalityId].cookies[key].name; 357 let hashIndex = cookieValue.indexOf("#"); 358 let prefix = cookieValue.substr(0, hashIndex); 359 let suffix = cookieValue.substr(hashIndex + 1); 360 window.cookiesplus_debug === true && console.log('Removing cookies starting with ' + prefix + ' and ending with ' + suffix); 361 document.cookie.split(";").forEach(function(cookie) { 362 let cookieName = cookie.trim().split("=")[0]; 363 if (cookieName.indexOf(prefix) === 0 && cookieName.endsWith(suffix)) { 364 var urlParts = location.hostname.split('.'); 365 for (var i = 2; i < urlParts.length + 1; i++) { 366 window.cookiesplus_debug === true && console.log('Removing cookie ' + co
366okieName); 367 document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/;'; 368 document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain='+urlParts.slice(-i).join('.'); 369 document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain=.'+urlParts.slice(-i).join('.'); 370 } 371 } 372 }); 373 } else { 374 window.cookiesplus_debug === true && console.log('Removing cookie ' + C_P_THEOBJECT[finalityId].cookies[key].name); 375 var urlParts = location.hostname.split('.'); 376 for (var i = 2; i < urlParts.length + 1; i++) { 377 document.cookie = C_P_THEOBJECT[finalityId].cookies[key].name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/;'; 378 document.cookie = C_P_THEOBJECT[finalityId].cookies[key].name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain='+urlParts.slice(-i).join('.'); 379 document.cookie = C_P_THEOBJECT[finalityId].cookies[key].name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain=.'+urlParts.slice(-i).join('.'); 380 } 381 } 382 }) 383 } 384 } 385 }); 386 }, 387 loadJs : function() { 388 // Don't execute scripts if the user has not given the consent yet 389 if (!self.consentsGiven) { 390 return; 391 } 392 393 // Append blocked script, js and css 394 for (var i = 0; i < cookiesPlusBlockedScripts.length; i++) { 395 let cookiesPlusBlockedScript = cookiesPlusBlockedScripts[i]; 396 let finalities = cookiesPlusBlockedScript['finalities'].split(','); 397 let allFinalitiesAccepted = true; 398 for (var j = 0; j < finalities.length; j++) { 399 if (!$('#cookiesplus-form input#cookiesplus-finality-' + finalities[j] + '-on:checked').val()) { 400 allFinalitiesAccepted = false; 401 break; 402 } 403 } 404 405 if (allFinalitiesAccepted) { 406 // Append JS and scripts 407 // We add JS first because it's possible that the scripts need the JS library 408 if (!$.isEmptyObject(cookiesPlusBlockedScript['js'])) { 409 // Counter to keep track of the loaded scripts 410 411 Object.keys(cookiesPlusBlockedScript['js']).forEach((key) => { 412 this.loadedScriptsTotal += Object.keys(cookiesPlusBlockedScript['js']).length; 413 var s = document.createElement( 'script'); 414 s.setAttribute( 'src', cookiesPlusBlockedScript['js'][key] ); 415 //s.setAttribute('defer', ''); 416 417 s.onload = () => { 418 // Increment the loaded scripts count 419 this.loadedScriptsCount++; 420 }; 421 422 document.body.appendChild(s); 423 }) 424 425 // Reset the js array after all scripts are added 426 cookiesPlusBlockedScripts[i]['js'] = []; 427 } 428 } 429 } 430 431 return true; 432 }, 433 executeScriptsAndCss : function() { 434 // Store reference to 'this' 435 var self = this; 436 437 // Don't execute scripts if the user has not given the consent yet 438 if (!self.consentsGiven) { 439 return; 440 } 441 442 cookieGdpr.tryParseJSONObject(decodeURIComponent(cookieGdpr.getCookiesPlusCookieValue('cookiesplus'))) 443 444 if (self.loadedScriptsCount === self.loadedScriptsTotal) { 445 self.executeScriptsAndCssLoaded(); 446 self.executeCustomScripts(); 447 self.fireFBPixel(); 448 } else { 449 // Check again after a delay 450 setTimeout(function () { 451 self.executeScriptsAndCss(); 452 }, 100); // Adjust the delay as needed 453 } 454 }, 455 executeScriptsAndCssLoaded : function() { 456 // Append blocked script, js and css 457 for (var i = 0; i < cookiesPlusBlockedScripts.length; i++) { 458 let cookiesPlusBlockedScript = cookiesPlusBlockedScripts[i]; 459 let finalities = cookiesPlusBlockedScript['finalities'].split(','); 460 let allFinalitiesAccepted = true; 461 for (var j = 0; j < finalities.length; j++) {
462 if (!$('#cookiesplus-form input#cookiesplus-finality-' + finalities[j] + '-on:checked').val()) { 463 allFinalitiesAccepted = false; 464 break; 465 } 466 } 467 468 if (allFinalitiesAccepted) { 469 if (cookiesPlusBlockedScript['script']) { 470 $(cookiesPlusBlockedScript['location']).replaceWith(cookiesPlusBlockedScript['script']); 471 cookiesPlusBlockedScripts[i]['script'] = []; 472 } 473 474 // Append CSS 475 Object.keys(cookiesPlusBlockedScript['css']).forEach(function(key) { 476 var s = document.createElement('link'); 477 s.setAttribute('rel', 'stylesheet'); 478 s.setAttribute('href', cookiesPlusBlockedScript['css'][key] ); 479 document.head.appendChild(s); 480 }) 481 cookiesPlusBlockedScripts[i]['css'] = []; 482 } 483 } 484 485 return true; 486 }, 487 executeCustomScripts : function() { 488 // For each checked finality, execute associated script 489 $('#cookiesplus-form input:checked').each(function() { 490 if ($(this).val() === 'on') { 491 // Execute finality script 492 if (typeof C_P_THEOBJECT !== 'undefined' 493 && C_P_THEOBJECT[$(this).data('finality-id')] 494 && C_P_THEOBJECT[$(this).data('finality-id')].script) { 495 $('body').append('<div style="display: none;" id="cookiesplus-scripts-' + $(this).data('finality-id') + '"></div>'); 496 cookieGdpr.setInnerHTML(document.querySelector('#cookiesplus-scripts-' + $(this).data('finality-id')), C_P_THEOBJECT[$(this).data('finality-id')].script); 497 498 // Remove script to avoid execute it more than once 499 C_P_THEOBJECT[$(this).data('finality-id')].script = []; 500 } 501 502 // Add code to body 503 if (typeof C_P_THEOBJECT !== 'undefined' && 504 C_P_THEOBJECT[$(this).data('finality-id')] && 505 C_P_THEOBJECT[$(this).data('finality-id')].body_code) { 506 $('body').append('<div style="display: none;" id="cookiesplus-body_code-' + $(this).data('finality-id') + '"></div>'); 507 cookieGdpr.setInnerHTML(document.querySelector('#cookiesplus-body_code-' + $(this).data('finality-id')), C_P_THEOBJECT[$(this).data('finality-id')].body_code); 508 509 C_P_THEOBJECT[$(this).data('finality-id')].body_code = []; 510 } 511 } else if ($(this).val() === 'off') { 512 // Execute finality script 513 if (typeof C_P_THEOBJECT !== 'undefined' 514 && C_P_THEOBJECT[$(this).data('finality-id')] 515 && C_P_THEOBJECT[$(this).data('finality-id')].script_not) { 516 $('body').append('<div style="display: none;" id="cookiesplus-scripts-' + $(this).data('finality-id') + '"></div>'); 517 cookieGdpr.setInnerHTML(document.querySelector('#cookiesplus-scripts-' + $(this).data('finality-id')), C_P_THEOBJECT[$(this).data('finality-id')].script_not); 518 519 // Remove script to avoid execute it more than once 520 C_P_THEOBJECT[$(this).data('finality-id')].script_not = []; 521 } 522 } 523 }); 524 525 return true; 526 }, 527 fireGTMEvents : function() { 528 // For each checked finality, execute associated script 529 let consentUpdateObject = {}; // Create an empty object to accumulate keys and values 530 $('#cookiesplus-form input:checked').each(function () { 531 if (typeof C_P_THEOBJECT !== 'undefined' 532 && C_P_THEOBJECT[$(this).data('finality-id')] 533 && C_P_THEOBJECT[$(this).data('finality-id')].consent_type) { 534 Object.keys(C_P_THEOBJECT[$(this).data('finality-id')].consent_type).forEach(key => { 535 if ($(this).val() === 'on') { 536 // Grant consent 537 window.cookiesplus_debug === true && console.log('Granting consent ' + key);
538 consentUpdateObject[key] = 'granted'; 539 } else { 540 // Deny consent 541 window.cookiesplus_debug === true && console.log('Denying consent ' + key); 542 consentUpdateObject[key] = 'denied'; 543 } 544 }); 545 } 546 }); 547 548 window.dataLayer = window.dataLayer || []; 549 function gtag() { dataLayer.push(arguments); } 550 551 // Send all the accumulated keys and values to gtag 552 window.cookiesplus_debug === true && console.log('Consent update object:', consentUpdateObject); 553 gtag('consent', 'update', consentUpdateObject); 554 555 $('#cookiesplus-form input:checked').each(function() { 556 if ($(this).val() === 'on') { 557 // Fire GTM events 558 if (typeof C_P_THEOBJECT !== 'undefined' 559 && C_P_THEOBJECT[$(this).data('finality-id')] 560 && C_P_THEOBJECT[$(this).data('finality-id')].firingEvent) { 561 window.cookiesplus_debug === true && console.log('Firing event '+[C_P_THEOBJECT[$(this).data('finality-id')].firingEvent]); 562 dataLayer.push({'event': [C_P_THEOBJECT[$(this).data('finality-id')].firingEvent]}); 563 } 564 } 565 }); 566 //dataLayer.push({'event': 'gtm.init_consent'}); 567 568 return true; 569 }, 570 fireFBPixel : function() { 571 if (typeof C_P_THEOBJECT === 'undefined') { 572 return false; 573 } 574 575 let fbAllConsents = false; 576 577 // For each finality, execute associated script 578 $('#cookiesplus-form input:checked').each(function() { 579 // Fire FB Pixel 580 fbAllConsents = true; 581 if ($(this).val() !== 'on' 582 && C_P_THEOBJECT[$(this).data('finality-id')] 583 && C_P_THEOBJECT[$(this).data('finality-id')].fb) { 584 fbAllConsents = false; 585 return false; 586 } 587 }); 588 589 if (fbAllConsents) { 590 window.cookiesplus_debug === true && console.log('Firing FB Pixel'); 591 if (typeof fbq !== 'undefined') { 592 fbq('consent', 'grant'); 593 } 594 } 595 596 return true; 597 }, 598 setInnerHTML : function(elm, html) { 599 elm.innerHTML = html;
600 Array.from(elm.querySelectorAll("script")).forEach( function(oldScript) { 601 const newScript = document.createElement("script"); 602 Array.from(oldScript.attributes) 603 .forEach( function(attr) { 604 newScript.setAttribute(attr.name, attr.value) 605 }); 606 newScript.appendChild(document.createTextNode(oldScript.innerHTML)); 607 oldScript.parentNode.replaceChild(newScript, oldScript); 608 }); 609 }, 610 tryParseJSONObject: function(jsonString) { 611 try { 612 var o = JSON.parse(jsonString); 613 614 // Handle non-exception-throwing cases: 615 // Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking, 616 // but... JSON.parse(null) returns null, and typeof null === "object", 617 // so we must check for that, too. Thankfully, null is falsey, so this suffices: 618 if (o && typeof o === "object") { 619 return o; 620 } 621 } 622 catch (e) { } 623 624 return {}; 625 }, 626 getCookiesPlusCookieValue: function(name) { 627 // return document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || ''; 628 var match = document.cookie.match(RegExp('(?:^|;\\s*)' + name + '=([^;]*)')); 629 return match ? match[1] : null; 630 }, 631} 632 633function waitForJqueryAndInitCookies() { 634 if (typeof jQuery !== 'undefined') { 635 // jQuery is loaded, you can use it here 636 $(document).ready(function() { 637 cookieGdpr.init(); 638 639 $('.cookiesplus-displaymodal').on('click', function() { 640 cookieGdpr.displayModal(); 641 }) 642 643 $('.cookiesplus-displaymodaladvanced').on('click', function() { 644 cookieGdpr.displayModalAdvanced(); 645 }) 646 647 $('a[href*="#cookiesplus-displaymodaladvanced"]').click(function(e) { 648 e.preventDefault(); 649 cookieGdpr.displayModalAdvanced(); 650 }); 651 }); 652 } else { 653 // jQuery is not loaded, retry after a delay 654 setTimeout(waitForJqueryAndInitCookies, 100); 655 } 656} 657 658waitForJqueryAndInitCookies();
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.