1/* 2 * NOTICE OF LICENSE 3 * 4 * This product is licensed for one customer to use on one installation (test stores and multishop included). 5 * Site developer has the right to modify this module to suit their needs, but can not redistribute the module in 6 * whole or in part. Any other use of this module constitutes a violation of the user agreement. 7 * 8 * DISCLAIMER 9 * 10 * NO WARRANTIES OF DATA SAFETY OR MODULE SECURITY 11 * ARE EXPRESSED OR IMPLIED. USE THIS MODULE IN ACCORDANCE 12 * WITH YOUR MERCHANT AGREEMENT, KNOWING THAT VIOLATIONS OF 13 * PCI COMPLIANCY OR A DATA BREACH CAN COST THOUSANDS OF DOLLARS 14 * IN FINES AND DAMAGE A STORES REPUTATION. USE AT YOUR OWN RISK. 15 * 16 * @author idnovate.com <[email protected]> 17 * @copyright 2022 idnovate.com 18 * @license See above 19 */ 20 21var cookiesPlusBlockedScripts = cookiesPlusBlockedScripts || []; 22 23const getCookiesPlusCookieValue = (name) => ( 24 document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || '' 25) 26 27const getValueFromCookieKey = (cookieName, cookieKey) => { 28 const decodedCookie = decodeURIComponent(getCookiesPlusCookieValue(cookieName)); 29 const parsedCookie = JSON.parse(decodedCookie); 30 return parsedCookie[cookieKey]; 31} 32 33const isCookiePlusStatisticOptionAccepted = () => { 34 return getValueFromCookieKey('cookiesplus', 'cookiesplus-finality-3') === 'on'; 35} 36 37const isCookiePlusMarketingOptionAccepted = () => { 38 return getValueFromCookieKey('cookiesplus', 'cookiesplus-finality-4') === 'on'; 39} 40 41var cookieGdpr = { 42 scrollLockState: null, 43 init: function () { 44 if (document.cookie.indexOf('cookiesplus=') === -1) { 45 // cookiesplus cookie doesn't exist, initialize it 46 //cookiesplusVars = []; 47 //cookiesplusVars['C_P_DISPLAY_MODAL'] = false; 48 49 var expireTime = new Date(); 50 expireTime.setDate(expireTime.getDate() + C_P_EXPIRY); 51 var expires = "expires=" + expireTime.toUTCString(); 52 53 document.cookie = "cookiesplus={};" + expires + ";path=/"; 54 } 55 56 // mode DIVs before </body> 57 $('.cookiesplus-move').appendTo(document.body); 58 59 let cookiesplusVars = cookieGdpr.tryParseJSONObject(decodeURIComponent(getCookiesPlusCookieValue('cookiesplus'))); 60 61 // Initialize values 62 cookiesplusFinalities = Object.keys(cookiesplusVars).filter(v => v.startsWith('cookiesplus-finality')); 63 cookiesplusFinalities.forEach(function (key) { 64 if (cookiesplusVars[key] === 'on') { 65 $("label[for='" + key + '-' + cookiesplusVars[key] + "']").click() 66 } 67 }) 68 69 cookieGdpr.executeScripts(); 70 71 //Don't display modal in Cookies CMS 72 if ($('body#cms').length) { 73 id = $('body#cms').attr('class').match(/cms-[\w-]*\b/); 74 id = id[0].replace(/[^0-9]/gi, ''); 75 if (typeof cookiesplusVars.C_P_CMS_PAGE !== 'undefined' 76 && (typeof cookiesplusVars.C_P_CMS_PAGE === id)) { 77 return; 78 } 79 } 80 81 if (typeof cookiesplusVars.C_P_DISPLAY_MODAL === 'undefined' 82 || (typeof cookiesplusVars.C_P_DISPLAY_MODAL !== 'undefined' 83 && cookiesplusVars.C_P_DISPLAY_MODAL == true)) { 84 cookieGdpr.displayModal(); 85 } 86 87 }, 88 displayModal: function () { 89 if (typeof $.uniform !== "undefined" && typeof $.uniform.update !== "undefined") { 90 $.uniform.update(".cookiesplus-finality-checkbox"); 91 $.uniform.restore(".cookiesplus-finality-checkbox"); 92 } 93 94 if (typeof C_P_FINALITIES_COUNT === 'undefined' 95 || C_P_FINALITIES_COUNT <= 1) { 96 return; 97 } 98 99 if (typeof C_P_NOT_AVAILABLE_OUTSIDE_EU !== 'undefined' 100 && C_P_NOT_AVAILABLE_OUTSIDE_EU === 0) { 101 return; 102 } else { 103 this.displayOverlay(); 104 $('#cookiesplus-modal').removeClass('cookiesplus-advanced-active'); 105 $('#cookiesplus-modal .cookiesplus-close-and-save').show(); 106 $('#cookiesplus-modal .cookiesplus-close').hide(); 107 $('.cookiesplus-more-information').show(); 108 //$('.cookiesplus-reject').hide(); 109 $('.cookiesplus-reject-all-label').show(); 110 $('.cookiesplus-accept-all-label').hide(); 111 $('#cookiesplus-modal').fadeIn('fast'); 112 } 113 114 this.checkEvenDimensions('#cookiesplus-modal'); 115 $(window).resize(function () { 116 cookieGdpr.checkEvenDimensions('#cookiesplus-modal'); 117 }); 118 }, 119 displayModalAdvanced: function (fromFirstLayer) { 120 if (typeof $.uniform !== "undefined" && typeof $.uniform.update !== "undefined") { 121 $.uniform.update(".cookiesplus-finality-checkbox"); 122 $.uniform.restore(".cookiesplus-finality-checkbox"); 123 } 124 125 /*if (C_P_FINALITIES_COUNT === 0) { 126 return; 127 }*/ 128 129 this.displayOverlay(); 130 131 if (typeof C_P_NOT_AVAILABLE_OUTSIDE_EU !== 'undefined' 132 && C_P_NOT_AVAILABLE_OUTSIDE_EU === 0) { 133 $('#cookiesplus-modal-not-available').fadeIn('fast'); 134 $('#cookiesplus-overlay').click(function () { 135 cookieGdpr.close(); 136 }) 137 } else { 138 $('#cookiesplus-modal').fadeIn('fast'); 139 $('#cookiesplus-modal').addClass('cookiesplus-advanced-active'); 140 $('.cookiesplus-finalities').fadeIn('fast'); 141 this.displaySavePreferencesButton(); 142 143 if (!fromFirstLayer) { 144 $('#cookiesplus-modal .cookiesplus-close-and-save').hide(); 145 $('#cookiesplus-modal .cookiesplus-close').show(); 146 } 147 } 148 149 this.checkEvenDimensions('#cookiesplus-modal'); 150 }, 151 save: function () { 152 return cookieGdpr.sendForm(); 153 }, 154 acceptAllCookies: function () { 155 $('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=on]').prop('checked', true); 156 157 return cookieGdpr.sendForm(); 158 }, 159 rejectAllCookies: function () { 160 $('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=off]').prop('checked', true); 161 162 return cookieGdpr.sendForm(); 163 }, 164 displayOverlay: function () { 165 this.lockScroll(); 166 167 if (typeof C_P_OVERLAY !== 'undefined' 168 && C_P_OVERLAY === '1') { 169 $('#cookiesplus-overlay').fadeIn('fast'); 170 $('#cookiesplus-overlay').css('background-color', 'rgba(0, 0, 0, ' + C_P_OVERLAY_OPACITY + ')'); 171 } 172 $('#cookiesplus-overlay').click(function () { 173 cookieGdpr.shake($('#cookiesplus-modal'), 4, 2, 20); 174 }); 175 }, 176 lockScroll: function () { 177 var html = document.documentElement; 178 var body = document.body; 179 180 if (!html || !body || this.scrollLockState) { 181 return; 182 } 183 184 this.scrollLockState = { 185 htmlOverflow: html.style.overflow, 186 htmlOverflowY: html.style.overflowY, 187 bodyOverflow: body.style.overflow, 188 bodyOverflowY: body.style.overflowY 189 }; 190 191 html.style.overflow = 'hidden'; 192 html.style.overflowY = 'hidden'; 193 body.style.overflow = 'hidden'; 194 body.style.overflowY = 'hidden'; 195 }, 196 unlockScroll: function () { 197 var html = document.documentElement; 198 var body = document.body; 199 var scrollLockState = this.scrollLockState; 200 201 if (!html || !body || !scrollLockState) { 202 return; 203 } 204 205 html.style.overflow = scrollLockState.htmlOverflow; 206 html.style.overflowY = scrollLockState.htmlOverflowY; 207 body.style.overflow = scrollLockState.bodyOverflow; 208 body.style.overflowY = scrollLockState.bodyOverflowY; 209 210 this.scrollLockState = null; 211 }, 212 close: function () { 213 $('#cookiesplus-modal').removeClass('cookiesplus-advanced-active'); 214 $('#cookiesplus-modal, #cookiesplus-modal-not-available, #cookiesplus-overlay, .cookiesplus-finalities, .cookiesplus-save').fadeOut('fast'); 215 $('.cookiesplus-finality-content').fadeOut('fast'); 216 this.unlockScroll(); 217 //$('.cookiesplus-save').prop('disabled', true); 218 }, 219 checkEvenDimensions: function (div) { 220 return; 221 //$(div).css('height', ''); 222 var styleObject = $(div).prop('style'); 223 styleObject.removeProperty('height'); 224 if ($(div).height() % 2 === 1) { 225 $(div).height(2 * Math.round(($(div).height() - 1) / 2)); 226 } 227 228 styleObject.removeProperty('width'); 229 $(div).css('width', ''); 230 if ($(div).width() % 2 === 1) { 231 $(div).width(2 * Math.round(($(div).width() - 1) / 2)); 232 } 233 }, 234 shake: function (div, shakes, distance, duration) { 235 if (shakes > 0) { 236 div.each(function () { 237 var $el = $(this); 238 var left = $el.css('left'); 239 $el.animate({left: "-=" + distance}, duration, function () { 240 $el.animate({left: "+=" + distance * 2}, duration, function () { 241 $el.animate({left: left}, duration, function () { 242 cookieGdpr.shake($el, shakes - 1, distance, duration); 243 }); 244 }); 245 }); 246 }); 247 } 248 }, 249 displaySavePreferencesButton: function () { 250 $('.cookiesplus-accept-all-label').show(); 251 $('.cookiesplus-accept-label').hide(); 252 $('.cookiesplus-reject-all-label').show(); 253 $('.cookiesplus-reject-label').hide(); 254 $('.cookiesplus-save').show(); 255 $('.cookiesplus-reject').show(); 256 $('.cookiesplus-more-information').hide(); 257 258 /*if ($('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=on]:checked').length > 0 259 || $('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=off]:checked').length > 0) { 260 $('.cookiesplus-save').prop('disabled', false); 261 }*/ 262 }, 263 sendForm: function () { 264 // Read cookie value
265 let cookiesplusVars = cookieGdpr.tryParseJSONObject(decodeURIComponent(getCookiesPlusCookieValue('cookiesplus'))); 266 267 if (cookiesplusVars instanceof Array) { 268 cookiesplusVars = Object.assign({}, cookiesplusVars); 269 } 270 271 // Save new info 272 cookiesplusVars['C_P_DISPLAY_MODAL'] = false; 273 274 $('#cookiesplus-form input:checked').each(function () { 275 const inputValue = $(this).val() === 'off' ? 'off' : 'on' 276 cookiesplusVars[$(this).attr('name')] = inputValue; 277 }); 278 279 cookiesplusVars['consent_date'] = C_P_DATE; 280 281 var expireTime = new Date(); 282 expireTime.setDate(expireTime.getDate() + C_P_EXPIRY); 283 var expires = "expires=" + expireTime.toUTCString(); 284 285 document.cookie = "cookiesplus=" + encodeURIComponent(JSON.stringify(cookiesplusVars)) + ";" + expires + ";path=/"; 286 287 //Remove cookies 288 $('#cookiesplus-form input:checked').each(function () { 289 if ($(this).val() === 'off') { 290 //Save preferences 291 let finalityId = $(this).data('finality-id'); 292 if (typeof C_P_COOKIES[finalityId] !== 'undefined') { 293 Object.keys(C_P_COOKIES[finalityId]).forEach(function (key) { 294 if (C_P_COOKIES[finalityId][key].name.includes('#')) { 295 console.log('Removing cookies starting with ' + C_P_COOKIES[finalityId][key].name.substr(0, C_P_COOKIES[finalityId][key].name.indexOf('#'))); 296 document.cookie.split(";").forEach(function (cookie) { 297 var cookieName = cookie.trim().split("=")[0]; 298 299 // If the prefix of the cookie's name matches the one specified, remove it 300 if (cookieName.indexOf(C_P_COOKIES[finalityId][key].name.substr(0, C_P_COOKIES[finalityId][key].name.indexOf('#'))) === 0) { 301 var urlParts = location.hostname.split('.'); 302 for (var i = 2; i < urlParts.length + 1; i++) { 303 console.log('Removing cookie ' + C_P_COOKIES[finalityId][key].name); 304 document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/;'; 305 document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain=' + urlParts.slice(-i).join('.'); 306 document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain=.' + urlParts.slice(-i).join('.'); 307 } 308 } 309 }); 310 } else { 311 console.log('Removing cookie ' + C_P_COOKIES[finalityId][key].name); 312 var urlParts = location.hostname.split('.'); 313 for (var i = 2; i < urlParts.length + 1; i++) { 314 document.cookie = C_P_COOKIES[finalityId][key].name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/;'; 315 document.cookie = C_P_COOKIES[finalityId][key].name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain=' + urlParts.slice(-i).join('.'); 316 document.cookie = C_P_COOKIES[finalityId][key].name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain=.' + urlParts.slice(-i).join('.'); 317 } 318 } 319 }) 320 } 321 } 322 }); 323 324 if (typeof C_P_REFRESH !== 'undefined' 325 && !C_P_REFRESH) { 326 $.ajax({ 327 type: "POST", 328 cache: false, 329 async: true, 330 url: $('#cookiesplus-form').attr('action'), 331 data: 'saveCookiesPlusPreferences=&ajax=1&' + $('#cookiesplus-form').serialize(), 332 dataType: 'json', 333 headers: { 334 "cache-control": "no-cache" 335 }, 336 success: function (data) { 337 if (data.consent_link && data.consent_hash) { 338 $('.cookiesplus-consent-hash a').attr('href', data.consent_link); 339 $('.cookiesplus-consent-hash a').text(data.consent_hash); 340 $('.cookiesplus-consent-hash').show(); 341 342 cookiesplusVars['consent_hash'] = data.consent_hash; 343 document.cookie = "cookiesplus=" + encodeURIComponent(JSON.stringify(cookiesplusVars)) + ";" + expires + ";path=/"; 344 } 345 346 /*var d = new Date(); 347 d.setTime(d.getTime() + (365 * 1000)); 348 var expires = "expires=" + d.toUTCString();*/ 349 350 //document.cookie = "cookiesplus=" + data.cookie + ";" + expires + ";path=/"; 351 352 cookieGdpr.executeScripts(); 353 cookieGdpr.fireGTMEvents(); 354 }, 355 error: function (XMLHttpRequest, textStatus, errorThrown) { 356 console.log(errorThrown); 357 } 358 }); 359 360 cookieGdpr.close(); 361 362 return false;
363 } else { 364 cookieGdpr.close(); 365 366 return true; 367 } 368 }, 369 executeScripts: function () { 370 //For each checked finality, execute associated script 371 $('#cookiesplus-form input:checked').each(function () { 372 if ($(this).val() === 'on') { 373 //Execute finality script 374 if (typeof C_P_SCRIPT !== 'undefined' && C_P_SCRIPT[$(this).data('finality-id')]) { 375 //var F = new Function(C_P_SCRIPT[$(this).data('finality-id')]); 376 //F(); 377 378 $('body').append('<div style="display: none;" id="cookiesplus-scripts-' + $(this).data('finality-id') + '"></div>'); 379 cookieGdpr.setInnerHTML(document.querySelector('#cookiesplus-scripts-' + $(this).data('finality-id')), C_P_SCRIPT[$(this).data('finality-id')]); 380 381 //Remove script to avoid execute it more than once 382 C_P_SCRIPT[$(this).data('finality-id')] = []; 383 } 384 } else if ($(this).val() === 'off') { 385 //Execute finality script 386 if (typeof C_P_SCRIPT_NOT !== 'undefined' && C_P_SCRIPT_NOT[$(this).data('finality-id')]) { 387 //var F = new Function(C_P_SCRIPT_NOT[$(this).data('finality-id')]); 388 //F(); 389 390 $('body').append('<div style="display: none;" id="cookiesplus-scripts-' + $(this).data('finality-id') + '"></div>'); 391 cookieGdpr.setInnerHTML(document.querySelector('#cookiesplus-scripts-' + $(this).data('finality-id')), C_P_SCRIPT_NOT[$(this).data('finality-id')]); 392 393 //Remove script to avoid execute it more than once 394 C_P_SCRIPT_NOT[$(this).data('finality-id')] = []; 395 } 396 } 397 }); 398 399 //Append blocked script, js and css 400 for (var i = 0; i < cookiesPlusBlockedScripts.length; i++) { 401 let cookiesPlusBlockedScript = cookiesPlusBlockedScripts[i]; 402 let finalities = cookiesPlusBlockedScript['finalities'].split(','); 403 let allFinalitiesAccepted = true; 404 for (var j = 0; j < finalities.length; j++) { 405 if (!$('#cookiesplus-form input#cookiesplus-finality-' + finalities[j] + '-on:checked').val()) { 406 allFinalitiesAccepted = false; 407 break; 408 } 409 } 410 411 if (allFinalitiesAccepted) { 412 $(cookiesPlusBlockedScript['location']).replaceWith(cookiesPlusBlockedScript['script']); 413 cookiesPlusBlockedScripts[i]['script'] = []; 414 415 //Append JS 416 Object.keys(cookiesPlusBlockedScript['js']).forEach(function (key) { 417 var s = document.createElement('script'); 418 s.setAttribute('src', cookiesPlusBlockedScript['js'][key]); 419 document.body.appendChild(s); 420 }) 421 cookiesPlusBlockedScripts[i]['js'] = []; 422 423 //Append CSS 424 Object.keys(cookiesPlusBlockedScript['css']).forEach(function (key) { 425 var s = document.createElement('link'); 426 s.setAttribute('rel', 'stylesheet'); 427 s.setAttribute('href', cookiesPlusBlockedScript['css'][key]); 428 document.head.appendChild(s); 429 }) 430 cookiesPlusBlockedScripts[i]['css'] = []; 431 } 432 } 433 434 return true; 435 }, 436 fireGTMEvents: function () { 437 //For each checked finality, execute associated script 438 $('#cookiesplus-form input:checked').each(function () { 439 if ($(this).val() === 'on') { 440 //Fire GTM events 441 if (typeof C_P_GTM !== 'undefined' && C_P_GTM[$(this).data('finality-id')]) { 442 if (C_P_GTM[$(this).data('finality-id')]['gtmFinality']) { 443 console.log('Granting consent ' + [C_P_GTM[$(this).data('finality-id')]['gtmFinality']]); 444 gtag('consent', 'update', { 445 [C_P_GTM[$(this).data('finality-id')]['gtmFinality']]: 'granted' 446 }); 447 } 448 } 449 } 450 }); 451 452 $('#cookiesplus-form input:checked').each(function () { 453 window.dataLayer = window.dataLayer || []; 454 if ($(this).val() === 'on') { 455 //Fire GTM events 456 if (typeof C_P_GTM !== 'undefined' && C_P_GTM[$(this).data('finality-id')]) { 457 if (C_P_GTM[$(this).data('finality-id')]['firingEvent']) { 458 console.log('Firing event ' + [C_P_GTM[$(this).data('finality-id')]['firingEvent']]); 459 dataLayer.push({'event': [C_P_GTM[$(this).data('finality-id')]['firingEvent']]}); 460 } 461 } 462 } 463 464 dataLayer.push({'event': 'gtm.init_consent'}); 465 }); 466 467 return true; 468 }, 469 setInnerHTML: function (elm, html) { 470 elm.innerHTML = html;
471 Array.from(elm.querySelectorAll("script")).forEach(function (oldScript) { 472 const newScript = document.createElement("script"); 473 Array.from(oldScript.attributes) 474 .forEach(function (attr) { 475 newScript.setAttribute(attr.name, attr.value) 476 }); 477 newScript.appendChild(document.createTextNode(oldScript.innerHTML)); 478 oldScript.parentNode.replaceChild(newScript, oldScript); 479 }); 480 }, 481 tryParseJSONObject: function (jsonString) { 482 try { 483 var o = JSON.parse(jsonString); 484 485 // Handle non-exception-throwing cases: 486 // Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking, 487 // but... JSON.parse(null) returns null, and typeof null === "object", 488 // so we must check for that, too. Thankfully, null is falsey, so this suffices: 489 if (o && typeof o === "object") { 490 return o; 491 } 492 } catch (e) { 493 } 494 495 return {}; 496 } 497} 498 499$(document).ready(function () { 500 cookieGdpr.init(); 501 $('.cookiesplus-displaymodal').on('click', function () { 502 cookieGdpr.displayModal(); 503 }) 504 505 $('.cookiesplus-displaymodaladvanced').on('click', function () { 506 cookieGdpr.displayModalAdvanced(); 507 }) 508 509 $('a[href*="#cookiesplus-displaymodaladvanced"]').click(function (e) { 510 e.preventDefault(); 511 cookieGdpr.displayModalAdvanced(); 512 }); 513});
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.