1// Consent class 2let ConsentApp = new function ConsentController() { 3 //-- global variables --- 4 window.dataLayer = window.dataLayer || []; 5 6 //--- private variables --- 7 var cloneButttonInterval, counter = 0; 8 9 //--- public functions --- 10 /** 11 * Callback function for GoogleTagManager Script to fire the dataLayer trigger 12 * @param bool state 13 * @param object app 14 */ 15 this.consentChanged = function (state, app) { 16 if (state === true) { 17 if (app.name.indexOf('google-tagmanager-service') !== -1) { 18 let tempObj = { 19 event: app.gtm.trigger 20 }; 21 tempObj[app.gtm.variable] = true; 22 window.dataLayer.push(tempObj); 23 24 /* 25 //ES6 - https://stackoverflow.com/questions/11508463/javascript-set-object-key-by-variable 26 window.dataLayer.push({ 27 event: app.name, 28 [app.name]: true 29 }); 30 */ 31 } 32 } 33 34 //Check if the own callback function is allready defined 35 if (typeof window[app.ownCallback] === "function") { 36 window[app.ownCallback](state, app); 37 } else if (app.ownCallback !== '') { 38 console.error('The Callback function ' + app.ownCallback + ' is not yet defined. Please create it first.'); 39 } 40 }; 41 42 /** 43 * Replace the klaro "OK" button with a clone to remove all attached event listeners. 44 * Otherwise our own defined listener gets not fired. 45 */ 46 this.cloneButton = function () { 47 if ($('.cookie-notice .cm-btn-success').length > 0) { 48 let currentButton = $('.cookie-notice .cm-btn-success'); 49 let cloneButton = currentButton.clone(); 50 let configLink = $('.cookie-notice p a'); 51 52 //Replace the original button with the new 53 currentButton.replaceWith(cloneButton); 54 55 //Workaround to link the privacypage inside the consent text https://github.com/KIProtect/klaro/issues/116 56 $('.cn-body p:first').html(function (index, text) { 57 let link = $('<a>', { 58 text: klaroConfig.translations.en.consentModal.privacyPolicy.name, 59 title: klaroConfig.translations.en.consentModal.privacyPolicy.name, 60 href: klaroConfig.privacyPolicy, 61 class: 'privcyPage' 62 }) 63 return text.replace("[privacyPage]", link[0].outerHTML); 64 }); 65 66 clearInterval(cloneButttonInterval); 67 counter = 0; 68 } 69 70 if (counter > 1000) { 71 clearInterval(cloneButttonInterval); 72 } 73 counter++; 74 }; 75 76 //--- constructor --- 77 (function contruct() { 78 $(document).ready(function () { 79 //Listener for the button on the privacy page, to edit the consent 80 $(document).on('click', '.js-showConsentModal', function (event) { 81 event.preventDefault(); 82 klaro.show(); 83 }); 84 85 //Workaround if modal ist closed without save 86 $(document).on('click', 'div.cm-bg, button.hide', function (event) { 87 event.preventDefault(); 88 ConsentApp.cloneButton(); 89 }); 90 91 92 //Only execute, if no decision is made yet (first visit). 93 if (klaro.getManager().confirmed == false) { 94 //Workaround for issue https://github.com/KIProtect/klaro/issues/138 95 $(document).on('click', '.cookie-notice .cm-btn-success', function (event) { 96 klaroConfig.apps.forEach(function (element, index) { 97 klaroConfig.apps[index].default = klaroConfig.apps[index].defaultIfNoConsent; 98 }); 99 klaro.getManager().resetConsent(); 100 klaro.getManager().saveAndApplyConsents(); 101 102 $('.cookie-notice ').remove(); 103 }); 104 105 //Workaround, because there is no klaro callback function 106 cloneButttonInterval = setInterval(ConsentApp.cloneButton, 1); 107 } 108 }); 109 })(); 110};
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.