1try { 2 var omCookieGroups = JSON.parse(document.getElementById('om-cookie-consent').innerHTML); 3 var omGtmEvents = []; 4} 5catch(err) { 6 console.log('OM Cookie Manager: No Cookie Groups found! Maybe you have forgot to set the page id inside the constants of the extension') 7} 8 9 10document.addEventListener('DOMContentLoaded', function(){ 11 var panelButtons = document.querySelectorAll('[data-omcookie-panel-save]'); 12 var openButtons = document.querySelectorAll('[data-omcookie-panel-show]'); 13 var i; 14 var omCookiePanel = document.querySelectorAll('[data-omcookie-panel]')[0]; 15 if(omCookiePanel === undefined) return; 16 var openCookiePanel = true; 17 18 //Enable stuff by Cookie 19 var cookieConsentData = omCookieUtility.getCookie('omCookieConsent'); 20 if(cookieConsentData !== null && cookieConsentData.length > 0){ 21 //dont open the panel if we have the cookie 22 openCookiePanel = false; 23 var checkboxes = document.querySelectorAll('[data-omcookie-panel-grp]'); 24 var cookieConsentGrps = cookieConsentData.split(','); 25 var cookieConsentActiveGrps = ''; 26 27 for(i = 0; i < cookieConsentGrps.length; i++){ 28 if(cookieConsentGrps[i] !== 'dismiss'){ 29 var grpSettings = cookieConsentGrps[i].split('.'); 30 if(parseInt(grpSettings[1]) === 1){ 31 omCookieEnableCookieGrp(grpSettings[0]); 32 cookieConsentActiveGrps += grpSettings[0] + ','; 33 } 34 } 35 } 36 for(i = 0; i < checkboxes.length; i++){ 37 if(cookieConsentActiveGrps.indexOf(checkboxes[i].value) !== -1){ 38 checkboxes[i].checked = true; 39 } 40 //check if we have a new group 41 if(cookieConsentData.indexOf(checkboxes[i].value) === -1){ 42 openCookiePanel = true; 43 } 44 } 45 //push stored events(sored by omCookieEnableCookieGrp) to gtm. We push this last so we are sure that gtm is loaded 46 pushGtmEvents(omGtmEvents); 47 omTriggerPanelEvent(['cookieconsentscriptsloaded']); 48 } 49 if(openCookiePanel === true){ 50 //timeout, so the user can see the page before he get the nice cookie panel 51 setTimeout(function () { 52 omCookiePanel.classList.toggle('active'); 53 },1000); 54 } 55 56 //check for button click 57 for (i = 0; i < panelButtons.length; i++) { 58 panelButtons[i].addEventListener('click', omCookieSaveAction, false); 59 } 60 for (i = 0; i < openButtons.length; i++) { 61 openButtons[i].addEventListener('click', function () { 62 omCookiePanel.classList.toggle('active'); 63 }, false); 64 } 65 66}); 67 68//activates the groups 69var omCookieSaveAction = function() { 70 action = this.getAttribute('data-omcookie-panel-save'); 71 var checkboxes = document.querySelectorAll('[data-omcookie-panel-grp]'); 72 var i; 73 //check if we have a cookie 74 var cookie = omCookieUtility.getCookie('omCookieConsent'); 75 if(cookie === null || cookie.length <= 0){ 76 //set cookie to empty string when no cookie data was found 77 cookie = ''; 78 }else{ 79 //reset all values inside the cookie which are present in the actual panel 80 for (i = 0; i < checkboxes.length; i++) { 81 cookie = cookie.replace(new RegExp(checkboxes[i].value + '\\S{3}'),''); 82 } 83 } 84 //save the group id (group-x) and the made choice (.0 for group denied and .1 for group accepted) 85 switch (action) { 86 case 'all': 87 for (i = 0; i < checkboxes.length; i++) { 88 omCookieEnableCookieGrp(checkboxes[i].value); 89 cookie += checkboxes[i].value + '.1,'; 90 checkboxes[i].checked = true; 91 } 92 break; 93 case 'save': 94 for (i = 0; i < checkboxes.length; i++) { 95 if(checkboxes[i].checked === true){ 96 omCookieEnableCookieGrp(checkboxes[i].value); 97 cookie += checkboxes[i].value + '.1,'; 98 }else{ 99 cookie += checkboxes[i].value + '.0,'; 100 } 101 } 102 break; 103 case 'min': 104 for (i = 0; i < checkboxes.length; i++) { 105 if(checkboxes[i].getAttribute('data-omcookie-panel-essential') !== null){ 106 omCookieEnableCookieGrp(checkboxes[i].value); 107 cookie += checkboxes[i].value + '.1,'; 108 }else{ 109 cookie += checkboxes[i].value + '.0,'; 110 checkboxes[i].checked = false;
111 } 112 } 113 break; 114 } 115 //replace dismiss to the end of the cookie 116 cookie = cookie.replace('dismiss',''); 117 cookie += 'dismiss'; 118 //cookie = cookie.slice(0, -1); 119 omCookieUtility.setCookie('omCookieConsent',cookie,364); 120 //push stored events to gtm. We push this last so we are sure that gtm is loaded 121 pushGtmEvents(omGtmEvents); 122 omTriggerPanelEvent(['cookieconsentsave','cookieconsentscriptsloaded']); 123 124 setTimeout(function () { 125 document.querySelectorAll('[data-omcookie-panel]')[0].classList.toggle('active'); 126 },350) 127 128}; 129 130var omTriggerPanelEvent = function(events){ 131 events.forEach(function (event) { 132 var eventObj = new CustomEvent(event, {bubbles: true}); 133 document.querySelectorAll('[data-omcookie-panel]')[0].dispatchEvent(eventObj); 134 }) 135}; 136 137var pushGtmEvents = function (events) { 138 window.dataLayer = window.dataLayer || []; 139 events.forEach(function (event) { 140 window.dataLayer.push({ 141 'event': event, 142 }); 143 }); 144}; 145var omCookieEnableCookieGrp = function (groupKey){ 146 if(omCookieGroups[groupKey] !== undefined){ 147 for (var key in omCookieGroups[groupKey]) { 148 // skip loop if the property is from prototype 149 if (!omCookieGroups[groupKey].hasOwnProperty(key)) continue; 150 var obj = omCookieGroups[groupKey][key]; 151 //save gtm event for pushing 152 if(key === 'gtm'){ 153 if(omCookieGroups[groupKey][key]){ 154 omGtmEvents.push(omCookieGroups[groupKey][key]); 155 } 156 continue; 157 } 158 //set the cookie html 159 for (var prop in obj) { 160 // skip loop if the property is from prototype 161 if (!obj.hasOwnProperty(prop)) continue; 162 163 if(Array.isArray(obj[prop])){ 164 var content = ''; 165 //get the html content 166 obj[prop].forEach(function (htmlContent) { 167 content += htmlContent 168 }); 169 var range = document.createRange(); 170 if(prop === 'header'){ 171 // add the html to header 172 range.selectNode(document.getElementsByTagName('head')[0]); 173 var documentFragHead = range.createContextualFragment(content); 174 document.getElementsByTagName('head')[0].appendChild(documentFragHead); 175 }else{ 176 //add the html to body 177 range.selectNode(document.getElementsByTagName('body')[0]); 178 var documentFragBody = range.createContextualFragment(content); 179 document.getElementsByTagName('body')[0].appendChild(documentFragBody); 180 } 181 } 182 } 183 } 184 //remove the group so we don't set it again 185 delete omCookieGroups[groupKey]; 186 } 187}; 188var omCookieUtility = { 189 getCookie: function(name) { 190 var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)'); 191 return v ? v[2] : null; 192 }, 193 setCookie: function(name, value, days) { 194 var d = new Date; 195 d.setTime(d.getTime() + 24*60*60*1000*days); 196 document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString() + ";SameSite=Lax"; 197 }, 198 deleteCookie: function(name){ setCookie(name, '', -1); } 199}; 200 201(function () { 202 203 if ( typeof window.CustomEvent === "function" ) return false; 204 205 function CustomEvent ( event, params ) { 206 params = params || { bubbles: false, cancelable: false, detail: null }; 207 var evt = document.createEvent( 'CustomEvent' ); 208 evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail ); 209 return evt; 210 } 211 212 window.CustomEvent = CustomEvent; 213})(); 214
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.