/* * NOTICE OF LICENSE * * This product is licensed for one customer to use on one installation (test stores and multishop included). * Site developer has the right to modify this module to suit their needs, but can not redistribute the module in * whole or in part. Any other use of this module constitutes a violation of the user agreement. * * DISCLAIMER * * NO WARRANTIES OF DATA SAFETY OR MODULE SECURITY * ARE EXPRESSED OR IMPLIED. USE THIS MODULE IN ACCORDANCE * WITH YOUR MERCHANT AGREEMENT, KNOWING THAT VIOLATIONS OF * PCI COMPLIANCY OR A DATA BREACH CAN COST THOUSANDS OF DOLLARS * IN FINES AND DAMAGE A STORES REPUTATION. USE AT YOUR OWN RISK. * * @author idnovate.com * @copyright 2022 idnovate.com * @license See above */ var cookiesPlusBlockedScripts = cookiesPlusBlockedScripts || []; var cookieGdpr = { init: function () { if (document.cookie.indexOf('cookiesplus=') === -1) { // cookiesplus cookie doesn't exist, initialize it //cookiesplusVars = []; //cookiesplusVars['C_P_DISPLAY_MODAL'] = false; var expireTime = new Date(); expireTime.setDate(expireTime.getDate() + C_P_EXPIRY); var expires = "expires=" + expireTime.toUTCString(); document.cookie = "cookiesplus={};" + expires + ";path=/"; } // mode DIVs before $('.cookiesplus-move').appendTo(document.body); let cookiesplusVars = cookieGdpr.tryParseJSONObject(decodeURIComponent(cookieGdpr.getCookiesPlusCookieValue('cookiesplus'))); // Initialize values cookiesplusFinalities = Object.keys(cookiesplusVars).filter(v => v.startsWith('cookiesplus-finality')); cookiesplusFinalities.forEach(function (key) { if (cookiesplusVars[key] === 'on') { $("label[for='"+key+'-'+cookiesplusVars[key]+"']").click() } }) cookieGdpr.executeScripts(); //Don't display modal in Cookies CMS if ($('body#cms').length) { id = $('body#cms').attr('class').match(/cms-[\w-]*\b/); id = id[0].replace(/[^0-9]/gi, ''); if (typeof cookiesplusVars.C_P_CMS_PAGE !== 'undefined' && (typeof cookiesplusVars.C_P_CMS_PAGE === id)) { return; } } if (typeof cookiesplusVars.C_P_DISPLAY_MODAL === 'undefined' || (typeof cookiesplusVars.C_P_DISPLAY_MODAL !== 'undefined' && cookiesplusVars.C_P_DISPLAY_MODAL == true)) { cookieGdpr.displayModal(); } }, displayModal: function () { if (typeof $.uniform !== "undefined" && typeof $.uniform.update !== "undefined") { $.uniform.update(".cookiesplus-finality-checkbox"); $.uniform.restore(".cookiesplus-finality-checkbox"); } if (typeof C_P_FINALITIES_COUNT === 'undefined' || C_P_FINALITIES_COUNT <= 1) { return; } if (typeof C_P_NOT_AVAILABLE_OUTSIDE_EU !== 'undefined' && C_P_NOT_AVAILABLE_OUTSIDE_EU === 0) { return; } else { this.displayOverlay(); $('#cookiesplus-modal .cookiesplus-close-and-save').show(); $('#cookiesplus-modal .cookiesplus-close').hide(); $('.cookiesplus-more-information').show(); //$('.cookiesplus-reject').hide(); $('.cookiesplus-reject-all-label').hide(); $('.cookiesplus-accept-all-label').hide(); $('#cookiesplus-modal').fadeIn('fast'); } this.checkEvenDimensions('#cookiesplus-modal'); $(window).resize(function () { cookieGdpr.checkEvenDimensions('#cookiesplus-modal'); }); }, displayModalAdvanced: function (fromFirstLayer) { if (typeof $.uniform !== "undefined" && typeof $.uniform.update !== "undefined") { $.uniform.update(".cookiesplus-finality-checkbox"); $.uniform.restore(".cookiesplus-finality-checkbox"); } /*if (C_P_FINALITIES_COUNT === 0) { return; }*/ this.displayOverlay(); if (typeof C_P_NOT_AVAILABLE_OUTSIDE_EU !== 'undefined' && C_P_NOT_AVAILABLE_OUTSIDE_EU === 0) { $('#cookiesplus-modal-not-available').fadeIn('fast'); $('#cookiesplus-overlay').click(function() { cookieGdpr.close(); }) } else { $('#cookiesplus-modal').fadeIn('fast'); $('.cookiesplus-finalities').fadeIn('fast'); this.displaySavePreferencesButton(); if (!fromFirstLayer) { $('#cookiesplus-modal .cookiesplus-close-and-save').hide(); $('#cookiesplus-modal .cookiesplus-close').show(); } } this.checkEvenDimensions('#cookiesplus-modal'); }, save: function () { return cookieGdpr.sendForm(); }, acceptAllCookies: function () { $('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=on]').prop('checked', true); return cookieGdpr.sendForm(); }, rejectAllCookies: function () { $('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=off]').prop('checked', true); return cookieGdpr.sendForm(); }, displayOverlay: function () { if (typeof C_P_OVERLAY !== 'undefined' && C_P_OVERLAY === '1') { $('#cookiesplus-overlay').fadeIn('fast'); $('#cookiesplus-overlay').css('background-color', 'rgba(0, 0, 0, ' + C_P_OVERLAY_OPACITY + ')'); } $('#cookiesplus-overlay').click(function(){ cookieGdpr.shake($('#cookiesplus-modal'), 4, 2, 20); }); }, close: function () { $('#cookiesplus-modal, #cookiesplus-modal-not-available, #cookiesplus-overlay, .cookiesplus-finalities, .cookiesplus-save').fadeOut('fast'); $('.cookiesplus-finality-content').fadeOut('fast'); //$('.cookiesplus-save').prop('disabled', true); }, checkEvenDimensions: function (div) { return; //$(div).css('height', ''); var styleObject = $(div).prop('style'); styleObject.removeProperty('height'); if ($(div).height() % 2 === 1) { $(div).height(2 * Math.round(($(div).height() - 1) / 2)); } styleObject.removeProperty('width'); $(div).css('width', ''); if ($(div).width() % 2 === 1) { $(div).width(2 * Math.round(($(div).width() - 1) / 2)); } }, shake: function (div, shakes, distance, duration) { if (shakes > 0) { div.each(function () { var $el = $(this); var left = $el.css('left'); $el.animate({left: "-=" + distance}, duration, function () { $el.animate({left: "+=" + distance * 2}, duration, function () { $el.animate({left: left}, duration, function () { cookieGdpr.shake($el, shakes - 1, distance, duration); }); }); }); }); } }, displaySavePreferencesButton: function() { $('.cookiesplus-accept-all-label').show(); $('.cookiesplus-accept-label').hide(); $('.cookiesplus-reject-all-label').show(); $('.cookiesplus-reject-label').hide(); $('.cookiesplus-save').show(); $('.cookiesplus-reject').show(); $('.cookiesplus-more-information').hide(); /*if ($('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=on]:checked').length > 0 || $('input:radio:not(:disabled)[name^=cookiesplus-finality-][value=off]:checked').length > 0) { $('.cookiesplus-save').prop('disabled', false); }*/ }, sendForm: function() { // Read cookie value let cookiesplusVars = cookieGdpr.tryParseJSONObject(decodeURIComponent(cookieGdpr.getCookiesPlusCookieValue('cookiesplus'))); if (cookiesplusVars instanceof Array) { cookiesplusVars = Object.assign({}, cookiesplusVars); } // Save new info cookiesplusVars['C_P_DISPLAY_MODAL'] = false; $('#cookiesplus-form input:checked').each(function() { cookiesplusVars[$(this).attr('name')] = $(this).val(); }); cookiesplusVars['consent_date'] = C_P_DATE; var expireTime = new Date(); expireTime.setDate(expireTime.getDate() + C_P_EXPIRY); var expires = "expires=" + expireTime.toUTCString(); document.cookie = "cookiesplus=" + encodeURIComponent(JSON.stringify(cookiesplusVars)) + ";" + expires + ";path=/"; //Remove cookies $('#cookiesplus-form input:checked').each(function() { if ($(this).val() !== 'on') { //Save preferences let finalityId = $(this).data('finality-id'); if (typeof C_P_COOKIES[finalityId] !== 'undefined') { Object.keys(C_P_COOKIES[finalityId]).forEach(function (key) { if (C_P_COOKIES[finalityId][key].name.includes('#')) { console.log('Removing cookies starting with ' + C_P_COOKIES[finalityId][key].name.substr(0, C_P_COOKIES[finalityId][key].name.indexOf('#'))); document.cookie.split(";").forEach(function(cookie) { var cookieName = cookie.trim().split("=")[0]; // If the prefix of the cookie's name matches the one specified, remove it if (cookieName.indexOf(C_P_COOKIES[finalityId][key].name.substr(0, C_P_COOKIES[finalityId][key].name.indexOf('#'))) === 0) { var urlParts = location.hostname.split('.'); for (var i = 2; i < urlParts.length + 1; i++) { console.log('Removing cookie ' + C_P_COOKIES[finalityId][key].name); document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/;'; document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain='+urlParts.slice(-i).join('.'); document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/; domain=.'+urlParts.slice(-i).join('.'); } } }); } else { console.log('Removing cookie ' + C_P_COOKIES[finalityId][key].name); var urlParts = location.hostname.split('.'); for (var i = 2; i < urlParts.length + 1; i++) { document.cookie = C_P_COOKIES[finalityId][key].name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;Max-Age=0; path=/;'; 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('.'); 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('.'); } } }) } } }); if (typeof C_P_REFRESH !== 'undefined' && !C_P_REFRESH) { $.ajax({ type: "POST", cache : false, async : true, url : $('#cookiesplus-form').attr('action'), data: 'saveCookiesPlusPreferences=&ajax=1&'+$('#cookiesplus-form').serialize(), dataType: 'json', headers: { "cache-control": "no-cache" }, success: function(data) { if (data.consent_link && data.consent_hash) { $('.cookiesplus-consent-hash a').attr('href', data.consent_link); $('.cookiesplus-consent-hash a').text(data.consent_hash); $('.cookiesplus-consent-hash').show(); cookiesplusVars['consent_hash'] = data.consent_hash; document.cookie = "cookiesplus=" + encodeURIComponent(JSON.stringify(cookiesplusVars)) + ";" + expires + ";path=/"; } /*var d = new Date(); d.setTime(d.getTime() + (365 * 1000)); var expires = "expires=" + d.toUTCString();*/ //document.cookie = "cookiesplus=" + data.cookie + ";" + expires + ";path=/"; cookieGdpr.executeScripts(); cookieGdpr.fireGTMEvents(); }, error: function(XMLHttpRequest, textStatus, errorThrown) { console.log(errorThrown); } }); cookieGdpr.close(); return false; } else { cookieGdpr.close(); return true; } }, executeScripts : function() { //For each checked finality, execute associated script $('#cookiesplus-form input:checked').each(function() { if ($(this).val() === 'on') { //Execute finality script if (typeof C_P_SCRIPT !== 'undefined' && C_P_SCRIPT[$(this).data('finality-id')]) { //var F = new Function(C_P_SCRIPT[$(this).data('finality-id')]); //F(); $('body').append(''); cookieGdpr.setInnerHTML(document.querySelector('#cookiesplus-scripts-' + $(this).data('finality-id')), C_P_SCRIPT[$(this).data('finality-id')]); //Remove script to avoid execute it more than once C_P_SCRIPT[$(this).data('finality-id')] = []; } } else if ($(this).val() === 'off') { //Execute finality script if (typeof C_P_SCRIPT_NOT !== 'undefined' && C_P_SCRIPT_NOT[$(this).data('finality-id')]) { //var F = new Function(C_P_SCRIPT_NOT[$(this).data('finality-id')]); //F(); $('body').append(''); cookieGdpr.setInnerHTML(document.querySelector('#cookiesplus-scripts-' + $(this).data('finality-id')), C_P_SCRIPT_NOT[$(this).data('finality-id')]); //Remove script to avoid execute it more than once C_P_SCRIPT_NOT[$(this).data('finality-id')] = []; } } }); //Append blocked script, js and css for (var i = 0; i < cookiesPlusBlockedScripts.length; i++) { let cookiesPlusBlockedScript = cookiesPlusBlockedScripts[i]; let finalities = cookiesPlusBlockedScript['finalities'].split(','); let allFinalitiesAccepted = true; for (var j = 0; j < finalities.length; j++) { if (!$('#cookiesplus-form input#cookiesplus-finality-' + finalities[j] + '-on:checked').val()) { allFinalitiesAccepted = false; break; } } if (allFinalitiesAccepted) { $(cookiesPlusBlockedScript['location']).replaceWith(cookiesPlusBlockedScript['script']); cookiesPlusBlockedScripts[i]['script'] = []; //Append JS Object.keys(cookiesPlusBlockedScript['js']).forEach(function(key) { var s = document.createElement( 'script'); s.setAttribute( 'src', cookiesPlusBlockedScript['js'][key] ); document.body.appendChild(s); }) cookiesPlusBlockedScripts[i]['js'] = []; //Append CSS Object.keys(cookiesPlusBlockedScript['css']).forEach(function(key) { var s = document.createElement('link'); s.setAttribute('rel', 'stylesheet'); s.setAttribute('href', cookiesPlusBlockedScript['css'][key] ); document.head.appendChild(s); }) cookiesPlusBlockedScripts[i]['css'] = []; } } return true; }, fireGTMEvents : function() { //For each checked finality, execute associated script $('#cookiesplus-form input:checked').each(function() { if ($(this).val() === 'on') { //Fire GTM events if (typeof C_P_GTM !== 'undefined' && C_P_GTM[$(this).data('finality-id')]) { if (C_P_GTM[$(this).data('finality-id')]['gtmFinality']) { console.log('Granting consent '+[C_P_GTM[$(this).data('finality-id')]['gtmFinality']]); gtag('consent', 'update', { [C_P_GTM[$(this).data('finality-id')]['gtmFinality']]: 'granted' }); } } } }); $('#cookiesplus-form input:checked').each(function() { window.dataLayer = window.dataLayer || []; if ($(this).val() === 'on') { //Fire GTM events if (typeof C_P_GTM !== 'undefined' && C_P_GTM[$(this).data('finality-id')]) { if (C_P_GTM[$(this).data('finality-id')]['firingEvent']) { console.log('Firing event '+[C_P_GTM[$(this).data('finality-id')]['firingEvent']]); dataLayer.push({'event': [C_P_GTM[$(this).data('finality-id')]['firingEvent']]}); } } } dataLayer.push({'event': 'gtm.init_consent'}); }); return true; }, setInnerHTML : function(elm, html) { elm.innerHTML = html; Array.from(elm.querySelectorAll("script")).forEach( function(oldScript) { const newScript = document.createElement("script"); Array.from(oldScript.attributes) .forEach( function(attr) { newScript.setAttribute(attr.name, attr.value) }); newScript.appendChild(document.createTextNode(oldScript.innerHTML)); oldScript.parentNode.replaceChild(newScript, oldScript); }); }, tryParseJSONObject: function(jsonString) { try { var o = JSON.parse(jsonString); // Handle non-exception-throwing cases: // Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking, // but... JSON.parse(null) returns null, and typeof null === "object", // so we must check for that, too. Thankfully, null is falsey, so this suffices: if (o && typeof o === "object") { return o; } } catch (e) { } return {}; }, getCookiesPlusCookieValue: function(name) { //return document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || ''; var match = document.cookie.match(RegExp('(?:^|;\\s*)' + name + '=([^;]*)')); return match ? match[1] : null; } } $(document).ready(function () { cookieGdpr.init(); $('.cookiesplus-displaymodal').on('click', function() { cookieGdpr.displayModal(); }) $('.cookiesplus-displaymodaladvanced').on('click', function() { cookieGdpr.displayModalAdvanced(); }) $('a[href*="#cookiesplus-displaymodaladvanced"]').click(function(e) { e.preventDefault(); cookieGdpr.displayModalAdvanced(); }); });