1function Cookies(settings) 2{ 3 var public = {}; 4 var private = {}; 5 6 private.group = settings.group; 7 private.available = settings.available; 8 private.user = settings.user; 9 private.u_id = settings.u_id; 10 private.g_id = settings.g_id; 11 private.exdays = 10; 12 private.scrollTop = undefined; 13 14 var COOKIE_USER_KEY = 'cp_user_'+private.g_id; 15 16 var $cookiesBanner = $('#cookies-banner'); 17 var $cookiesPreferences = $('#cookies-preferences'); 18 19 private.init = function() 20 { 21 if (private.u_id == 0) { 22 try { 23 private.user = JSON.parse(private.getCookie(COOKIE_USER_KEY)); 24 } catch(err) { 25 private.user = {}; 26 } 27 } 28 if (private.getCookie(COOKIE_USER_KEY) == '') { 29 private.scrollTop = $(window).scrollTop(); 30 document.body.addEventListener('click', private.fn, true); 31 window.addEventListener('scroll', private.handleScroll); 32 } 33 if (LOGGED_IN && (typeof ga_set !== 'undefined') && !ga_set) { 34 35 private.scrollTop = $(window).scrollTop(); 36 document.body.addEventListener('click', private.fn, true); 37 window.addEventListener('scroll', private.handleScroll); 38 } 39 40 if (private.showBanner()) { 41 // console.log('test'); 42 $cookiesBanner.show(); 43 } 44 45 } 46/* when the cookies banner shows, and user scrolls to certain height, or click somewhere in page, we treat as the user accepts and inject the google analytic code if exists */ 47 private.fn = function(){ 48 49 window.removeEventListener('scroll', private.handleScroll); 50 document.body.removeEventListener('click', private.fn, true); 51 if(!LOGGED_IN) 52 { 53 private.continueBrowser(); 54 55 } else { 56 $.post("/"+g_code+"/cookies/preferences", {'options' : {1:1,2:1}}, function(response, status){ 57 }); 58 } 59 if (typeof ga_set !== 'undefined' && (!LOGGED_IN || !ga_set)){ 60 if (typeof ga_code !=="undefined" && ga_code !== 0) { 61 private.createScriptNode('ga', ga_code); 62 } 63 if(typeof g_tag_manager_code !=="undefined" && g_tag_manager_code !== 0){ 64 private.createScriptNode('gtm', g_tag_manager_code); 65 } 66 67 } 68 } 69 70 private.createScriptNode = function(dataType, code){ 71 var script = document.createElement('script'); 72 script.setAttribute('data-type', dataType); 73 var inlineScript = document.createTextNode(code); 74 script.appendChild(inlineScript); 75 document.body.appendChild(script); 76 } 77 78 private.handleScroll = function(){ 79 var scroll = $(window).scrollTop(); 80 if(scroll - private.scrollTop >120){ 81 private.fn(); 82 } 83 } 84 85 private.now = function() 86 { 87 return new Date().toISOString().slice(0, 19).replace('T', ' '); 88 } 89 90 private.showBanner = function() 91 { 92 if (private.hasAcceptedOptions() == false && private.group.length == 0) { 93 return false; 94 } 95 for (var i = 0; i < private.group.length; i++) { 96 if (private.user[private.group[i]] == undefined) { 97 return true; 98 } 99 } 100 101 return false 102 } 103 104 private.continueBrowser = function () { 105 var options = {}; 106 107 for (var i = 0; i < private.group.length; i++) { 108 options[private.group[i]] = 1; 109 } 110 private.setCookie(COOKIE_USER_KEY, JSON.stringify(options)); 111 } 112 113 public.acceptChecked = function() 114 { 115 var options = {}; 116 117 $.each($cookiesPreferences.find('.option input'), function(){ 118 var value = this.checked ? 1 : 0; 119 options = { 120 1:value, 121 2:value 122 } 123 if (options[$(this).val()] == 0) { 124 var length = document.getElementsByTagName('script').length; 125 for (var i = 0; i < length; i++){ 126 if (document.getElementsByTagName('script')[i].getAttribute('data-type') == 'ga') { 127 document.body.removeChild(document.getElementsByTagName('script')[i]); 128 break; 129 } 130 } 131 for (var i = 0; i < length; i++){ 132 if (document.getElementsByTagName('script')[i].getAttribute('data-type') == 'gtm') { 133 document.body.removeChild(document.getElementsByTagName('script')[i]); 134 break; 135 } 136 } 137 } 138 }); 139 140 private.saveOptions(options); 141 } 142 143 public.acceptAll = function() 144 { 145 var options = {}; 146 147 for (var i = 0; i < private.group.length; i++) { 148 options[private.group[i]] = 1; 149 } 150 151 private.saveOptions(options); 152 } 153 154 private.saveOptions = function(options) 155 { 156 if (private.u_id > 0) { 157 $.post("/"+g_code+"/cookies/preferences", {'options' : options}, function(response, status){
158 $cookiesBanner.hide(); 159 $cookiesPreferences.hide(); 160 }); 161 } else { 162 163 private.setCookie(COOKIE_USER_KEY, JSON.stringify(options)); 164 $cookiesBanner.hide(); 165 $cookiesPreferences.hide(); 166 } 167 } 168 169 private.setCookie = function(cname, cvalue) 170 { 171 var d = new Date(); 172 d.setTime(d.getTime() + (private.exdays*24*60*60*1000)); 173 var expires = "expires="+ d.toUTCString(); 174 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; 175 if ( window.self !== window.top) 176 { 177 document.cookie =cname + "=" + cvalue + ";" + expires + ";path=/"+"; SameSite=None; Secure"; 178 // The page is in an iFrames 179 }else{ 180 } 181 } 182 183 private.getCookie = function(cname) 184 { 185 var name = cname + "="; 186 var decodedCookie = decodeURIComponent(document.cookie); 187 var ca = decodedCookie.split(';'); 188 for(var i = 0; i <ca.length; i++) { 189 var c = ca[i]; 190 while (c.charAt(0) == ' ') { 191 c = c.substring(1); 192 } 193 if (c.indexOf(name) == 0) { 194 return c.substring(name.length, c.length); 195 } 196 } 197 return ""; 198 } 199 200 private.hasAcceptedOptions = function(obj) 201 { 202 for(var prop in private.user) { 203 if(private.user.hasOwnProperty(prop)) 204 return true; 205 } 206 207 return false; 208 } 209 210 public.settings = function() 211 { 212 $.each($cookiesPreferences.find('.option input'), function(){ 213 // var id = $(this).val(); 214 var value = Number(settings.google_analytics_checked_default) ? true : false; 215 // var test = private.hasAcceptedOptions() ? private.user[id] != undefined && private.user[id] : value; 216 // console.log(test) 217 $(this).prop('checked', value); 218 }); 219 220 $cookiesPreferences.fadeIn(); 221 } 222 223 private.init(); 224 225 return public; 226}
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.