PluginProbe
CookieAdmin – Cookie Consent Banner / 1.2.6
CookieAdmin – Cookie Consent Banner v1.2.6
1.2.6 1.2.5 1.2.4 1.2.3 1.2.2 1.2.1 1.2.0 1.1.9 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 26 releases
← All changes | assets/js/consent.js +257 -140 1.0.6 → 1.2.6 View file →
@@ -1,10 +1,7 @@
1 -const days = cookieadmin_policy.cookieadmin_days;
1 +// This file handle the cookie banner and stuff related to that.
2 2
3 -var cookieadmin_show_reconsent = 0;
4 -if(cookieadmin_policy.is_pro != 0){
5 - var cookieadmin_show_reconsent = 1;
6 -}
3 +var days = cookieadmin_policy.cookieadmin_days;
7 4
8 5 if(typeof cookieadmin_is_consent === 'undefined'){
9 6 window.cookieadmin_is_consent = {};
10 7 }
@@ -11,15 +8,24 @@
11 8 var cookieadmin_allcookies = cookieadmin_policy.categorized_cookies;
12 9 //setInterval(cookieadmin_categorize_cookies, 5000);
13 10
14 11 function cookieadmin_is_obj(consentObj){
15 - return (Object.keys(consentObj).length !== 0);
12 + try{
13 + return (
14 + consentObj !== null &&
15 + typeof consentObj === 'object' &&
16 + !Array.isArray(consentObj) &&
17 + Object.keys(consentObj).length > 0
18 + );
19 + }catch(e){
20 + return false;
21 + }
16 22 }
17 23
18 24
19 25 // function cookieadmin_cookie_interceptor(){
20 -
21 - const originalCookieDescriptor =
26 +
27 + var originalCookieDescriptor =
22 28 Object.getOwnPropertyDescriptor(Document.prototype, 'cookie') ||
23 29 Object.getOwnPropertyDescriptor(document, 'cookie');
24 30 var allowed_cookies = '';
25 31
@@ -30,48 +36,62 @@
30 36 get: function(){
31 37 return originalCookieDescriptor.get.call(document);
32 38 },
33 39 set: function(val){
40 +
41 + if (!val) return;
42 +
43 + var separatorIndex = val.indexOf('=');
44 + if(separatorIndex === -1) {
45 + return;
46 + }
34 47
35 - val_name = val.split("=")[0].trim();
36 - rm_val = val_name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
48 + var cookieName = val.substring(0, separatorIndex).trim();
49 + var cookieValue = val.substring(separatorIndex + 1).trim();
50 +
51 + if(cookieName === "cookieadmin_consent"){
52 + originalCookieDescriptor.set.call(document, val);
53 + return;
54 + }
37 55
38 - if(val_name === "cookieadmin_consent"){
39 - return originalCookieDescriptor.set.call(document, val);
56 + // Set cookies which are meant to be deleted
57 + if(val.includes('expires=Thu, 01 Jan 1970') || cookieValue.startsWith("deleted;")){
58 + originalCookieDescriptor.set.call(document, val);
59 + return;
40 60 }
61 +
62 + var cookieInfo = cookieadmin_allcookies[cookieName] || {};
63 + var category = (cookieInfo.category || 'uncategorized').toLowerCase();
41 64
42 - if(cookieadmin_is_obj(cookieadmin_is_consent) && (val_name in cookieadmin_allcookies) ){
65 + // Set necessary cookies
66 + if(category == "necessary"){
67 + originalCookieDescriptor.set.call(document, val);
68 + return;
69 + }
70 +
71 + if(cookieadmin_is_obj(cookieadmin_is_consent) || (Array.isArray(cookieadmin_policy['preload']) && cookieadmin_policy['preload'].length > 0)){
72 +
73 + var consentAction = cookieadmin_is_consent.action;
43 74
44 - switch(cookieadmin_is_consent.action){
75 + if(!consentAction){
76 + consentAction = cookieadmin_policy['preload'].reduce((a, val) => {a[val] = ''; return a;}, {});
77 + }
78 +
79 + if(consentAction.accept || consentAction[category]){
80 + originalCookieDescriptor.set.call(document, val);
81 + }else{
45 82
46 - case "reject":
47 - if(cookieadmin_allcookies[val_name].sync){
48 - cookieadmin_allcookies[val_name].sync = false;
49 - return originalCookieDescriptor.set.call(document, rm_val);
50 - }
51 - return true;
52 -
53 - case "accept":
54 - if(!cookieadmin_allcookies[val_name].sync){
55 - cookieadmin_allcookies[val_name].sync = true;
56 - return originalCookieDescriptor.set.call(document, val);
57 - }
58 - return true;
59 -
60 - default:
61 - if(cookieadmin_is_consent.action[cookieadmin_allcookies[val_name].category] && !cookieadmin_allcookies[val_name].sync){
62 - cookieadmin_allcookies[val_name].sync = true;
63 - return originalCookieDescriptor.set.call(document, val);
64 - }
65 - else if(!(cookieadmin_is_consent.action[cookieadmin_allcookies[val_name].category]) && cookieadmin_allcookies[val_name].sync){
66 - cookieadmin_allcookies[val_name].sync = false;
67 - return originalCookieDescriptor.set.call(document, rm_val);
68 - }
69 - return true;
70 - }
83 + var pathMatch = val.match(/path=([^;]+)/i);
84 + var domainMatch = val.match(/domain=([^;]+)/i);
85 + var path = pathMatch ? pathMatch[1].trim() : '/';
86 + var domain = domainMatch ? `domain=${domainMatch[1].trim()};` : '';
87 +
88 + var deleteString = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; ${domain}`;
89 + originalCookieDescriptor.set.call(document, deleteString.trim());
90 + }
71 91
72 92 }else{
73 - (cookieadmin_allcookies[val_name] = cookieadmin_allcookies[val_name] || {}).string = val.trim();
93 + (cookieadmin_allcookies[cookieName] = cookieadmin_allcookies[cookieName] || {}).string = val.trim();
74 94 return false;
75 95 }
76 96
77 97 }
@@ -83,18 +103,28 @@
83 103 function cookieadmin_is_cookie(name){
84 104
85 105 if(!document.cookie) return false;
86 106
87 - let coki = document.cookie.split(";") ;
107 + var coki = document.cookie.split(";") ;
88 108
89 109 if(name == "all"){
90 110 return coki ? coki : [];
91 111 }
92 - let nam = name + "=";
112 + var nam = name + "=";
93 113
94 - for(let i=0; i < coki.length; i++){
114 + for(var i=0; i < coki.length; i++){
95 115 if(coki[i].trim().indexOf(nam) == 0){
96 - return coki[i].trim();
116 + try {
117 + var cookie_value = coki[i].trim().split("=");
118 + if(!cookie_value[1]){
119 + return false;
120 + }
121 +
122 + var decoded = decodeURIComponent(cookie_value[1]);
123 + return JSON.parse(decoded);
124 + } catch {
125 + return false;
126 + }
97 127 }
98 128 }
99 129
100 130 return false;
@@ -100,15 +130,15 @@
100 130 return false;
101 131 }
102 132
103 133 function cookieadmin_check_consent(){
104 -
105 - if(cookieadmin_cookie = cookieadmin_is_cookie("cookieadmin_consent")){
106 - cookieadmin_cookie = JSON.parse(cookieadmin_cookie.split("=")[1]);
134 + var cookieadmin_cookie = cookieadmin_is_cookie("cookieadmin_consent");
135 + if(!!cookieadmin_cookie){
107 136 if(!!cookieadmin_cookie.consent){
108 137 cookieadmin_is_consent.consent = cookieadmin_cookie.consent;
109 138 delete cookieadmin_cookie.consent;
110 139 }
140 +
111 141 cookieadmin_is_consent.action = cookieadmin_cookie;
112 142 }
113 143 }
114 144 cookieadmin_check_consent();
@@ -129,9 +159,9 @@
129 159
130 160 }else if(update.reject && update.reject == "true"){
131 161 return true;
132 162 }else{
133 - for (const [key, value] of Object.entries(update)) {
163 + for (var [key, value] of Object.entries(update)) {
134 164 if(key != "consent"){
135 165 cookieadmin_accepted_categories.push(key);
136 166 }
137 167 }
@@ -136,14 +166,19 @@
136 166 }
137 167 }
138 168 }
139 169
170 +
171 + for(cookie in cookieadmin_allcookies){
172 + document.cookie = cookieadmin_allcookies[cookie].string;
173 + };
174 +
140 175 cookieadmin_accepted_categories.forEach(function(category) {
141 176
142 177 document.querySelectorAll(
143 178 'script[type="text/plain"][data-cookieadmin-category="' + category + '"]'
144 179 ).forEach(function(el) {
145 - const newScript = document.createElement('script');
180 + var newScript = document.createElement('script');
146 181
147 182 // Copy attributes
148 183 if (el.src) {
149 184 newScript.src = el.src;
@@ -165,19 +200,30 @@
165 200 });
166 201 });
167 202 }
168 203
169 -function cookieadmin_set_cookie(name, value, days = 365, domain = "", path = cookieadmin_get_base_path()) {
204 +function cookieadmin_set_cookie(name, value, days = 365, domain = "") {
170 205 if (!name || !value) return false;
171 206
172 - const date = new Date();
207 + if((cookieadmin_policy.is_pro != 0) && (cookieadmin_pro_vars !== 'undefined')){
208 + if(cookieadmin_pro_vars.shared_subdomain_consent && cookieadmin_pro_vars.base_domain){
209 + // Delete the cookie if exist with the subdomin
210 + // Previously, cookie was set without specifying domain name, we'll not specify domain while deleting.
211 + document.cookie = `cookieadmin_consent=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${cookieadmin_policy.base_path};`;
212 + domain = cookieadmin_pro_vars.base_domain;
213 + }
214 + }
215 +
216 + var date = new Date();
173 217 date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); // default 1 year
174 218
175 - let cookieString = `${encodeURIComponent(name)}=${JSON.stringify(value)};`;
219 + var cookieString = `${encodeURIComponent(name)}=${JSON.stringify(value)};`;
176 220 cookieString += ` expires=${date.toUTCString()};`;
177 - cookieString += ` path=${path};`;
221 + cookieString += ` path=${!domain ? cookieadmin_policy.base_path : '/'};`;
178 222 cookieString += ` SameSite=Lax;`;
179 - cookieString += ` Secure;`; // Only sent over HTTPS
223 + if(cookieadmin_policy.is_ssl || window.location.protocol === 'https:'){
224 + cookieString += ` Secure;`;
225 + }
180 226
181 227 // Add domain if explicitly passed
182 228 if (domain) {
183 229 cookieString += ` domain=${domain};`;
@@ -186,9 +232,17 @@
186 232 document.cookie = cookieString;
187 233 return true;
188 234 }
189 235
190 -//Populates modal with consent if selected
236 +//Populates modal with consent if selected & adds found cookies
237 +// Only < and > are escaped: stored values pass sanitize_text_field, which can keep entities like &lt; that must still render
238 +function cookieadmin_esc(str){
239 + return String(str).replace(/</g, '&lt;').replace(/>/g, '&gt;');
240 +}
241 +
242 +// Cookies already rendered in the modal; must live outside the function or each re-populate duplicates the cards
243 +var cookieadmin_shown = [];
244 +
191 245 function cookieadmin_populate_preference(){
192 246
193 247 consent = cookieadmin_is_consent.action;
194 248
@@ -210,34 +264,60 @@
210 264 btn_ele.checked = true;
211 265 }
212 266 }
213 267 }
268 + //Load as per preloaded categories selected by admin
269 + }else if(cookieadmin_policy['preload'] && cookieadmin_policy['preload'].length > 0){
270 +
271 + cookieadmin_policy['preload'].forEach(function(val){
272 + if(btn_ele = document.querySelector("#cookieadmin-" + val)){
273 + btn_ele.checked = true;
274 + }
275 + });
214 276 }
215 277
216 - cookieadmin_shown = (typeof cookieadmin_shown !== "undefined") ? cookieadmin_shown : [];
217 -
218 278 if(cookieadmin_allcookies){
219 279
220 - cookieadmin_filtrd = Object.keys(cookieadmin_allcookies).filter(e => !cookieadmin_shown.includes(e));
280 + var cookieadmin_filtrd = Object.keys(cookieadmin_allcookies).filter(e => !cookieadmin_shown.includes(e));
221 281
222 282 for(c_info of cookieadmin_filtrd){
223 283
224 - if(e = document.querySelector(".cookieadmin-" + cookieadmin_allcookies[c_info].category?.toLowerCase())){
225 - e.innerHTML = (e.innerHTML == 'None') ? '' : e.innerHTML;
284 + var category_var = cookieadmin_allcookies[c_info].category;
285 +
286 + if(!category_var){
287 + continue;
288 + }
289 + var card_container = document.querySelector(".cookieadmin-" + category_var.toLowerCase());
290 +
291 + if(!card_container){
292 + continue;
293 + }
294 +
295 + card_container.querySelector(".cookieadmin-nocookie-cat").style.display = 'none';
296 +
297 + var cookieadmin_exp = cookieadmin_policy.lang.session;
226 298
227 - exp = 'Session';
228 -
229 - if(!!cookieadmin_allcookies[c_info].expires){
230 - exp = Math.round((cookieadmin_allcookies[c_info].expires - Date.now())/86400);
231 - if(exp < 1 && !!res['Max-Age']){
232 - exp = res['Max-Age'];
233 - }else{
234 - exp = 'Session';
299 + if(
300 + !!cookieadmin_allcookies[c_info].expires
301 + && cookieadmin_allcookies[c_info].expires !== "0000-00-00 00:00:00"
302 + ){
303 +
304 + var expDate = new Date(cookieadmin_allcookies[c_info].expires.replace(' ', 'T'));
305 +
306 + if (!isNaN(expDate.getTime())) {
307 + var daysLeft = Math.ceil((expDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24));
308 +
309 + if (daysLeft > 0) {
310 + cookieadmin_exp = daysLeft +' '+ cookieadmin_policy.lang.days;
235 311 }
236 312 }
237 -
238 - e.innerHTML += '<div class="cookieadmin-cookie-card"> <div class="cookieadmin-cookie-header"> <strong class="cookieadmin-cookie-name">'+ c_info.replace(/_+$/, "") +'</strong> <span class="cookieadmin-cookie-duration"><b>Duration:</b> '+ exp +'</span> </div> <p class="cookieadmin-cookie-description">'+ cookieadmin_allcookies[c_info].description +'</p> <div class="cookieadmin-cookie-tags"> ' + (cookieadmin_allcookies[c_info].platform ? '<span class="cookieadmin-tag">' + cookieadmin_allcookies[c_info].platform + '</span>' : "") + ' </div> </div>';
239 313 }
314 +
315 + var cookieadmin_desc = cookieadmin_allcookies[c_info].description;
316 + var cookieadmin_platform = cookieadmin_allcookies[c_info].platform;
317 +
318 + // Empty description/platform rows are skipped so the card has no blank gap or "null" text
319 + card_container.insertAdjacentHTML('beforeend', '<div class="cookieadmin-cookie-card"><div class="cookieadmin-cookie-header"><strong class="cookieadmin-cookie-name">'+ cookieadmin_esc(c_info.replace(/_+$/, "")) +'</strong> <span class="cookieadmin-cookie-duration"><b>'+ cookieadmin_policy.lang.duration +':</b> '+ cookieadmin_exp +'</span></div>' + (cookieadmin_desc ? '<p class="cookieadmin-cookie-description">'+ cookieadmin_esc(cookieadmin_desc) +'</p>' : '') + (cookieadmin_platform ? '<div class="cookieadmin-cookie-tags"><span class="cookieadmin-tag">' + cookieadmin_esc(cookieadmin_platform) + '</span></div>' : '') + '</div>');
240 320 cookieadmin_shown.push(c_info);
241 321 }
242 322 }
243 323
@@ -273,9 +353,9 @@
273 353 if(!cookieadmin_is_obj(cookieadmin_chk_cookies)){
274 354 return;
275 355 }
276 356
277 - /* const xhttp2 = new XMLHttpRequest();
357 + /* var xhttp2 = new XMLHttpRequest();
278 358
279 359 var data = 'action=cookieadmin_ajax_handler&cookieadmin_act=categorize_cookies&cookieadmin_security=' + cookieadmin_policy.nonce + "&cookieadmin_cookies=" + JSON.stringify(cookieadmin_chk_cookies);
280 360
281 361 xhttp2.onload = function() {
@@ -301,8 +381,13 @@
301 381 }
302 382
303 383
304 384 document.addEventListener("DOMContentLoaded", function() {
385 +
386 + var cookieadmin_show_reconsent = 0;
387 + if(cookieadmin_policy.is_pro != 0 && cookieadmin_pro_vars !== 'undefined' && cookieadmin_pro_vars.reconsent != 0){
388 + var cookieadmin_show_reconsent = 1;
389 + }
305 390
306 391 //Create overlay
307 392 var cookieadmin_ovrlay = document.createElement("div");
308 393 cookieadmin_ovrlay.className = "cookieadmin_modal_overlay";
@@ -307,13 +392,19 @@
307 392 var cookieadmin_ovrlay = document.createElement("div");
308 393 cookieadmin_ovrlay.className = "cookieadmin_modal_overlay";
309 394 document.body.appendChild(cookieadmin_ovrlay);
310 395
396 + var before_consent_dispaly = new CustomEvent('cookieadmin_before_consent_display');
397 +
398 + // For anything that needs to be done before disaplying consent.
399 + cookieadmin_policy.hide_banner = false; // initializing
400 + window.dispatchEvent(before_consent_dispaly);
401 +
311 402 //Show notice or re-consent icon as needed
312 - if(!cookieadmin_is_obj(cookieadmin_is_consent)){
403 + if(!cookieadmin_is_obj(cookieadmin_is_consent) && !cookieadmin_policy.hide_banner){
313 404
314 405 if(cookieadmin_policy.cookieadmin_layout !== "popup"){
315 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
406 + document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
316 407 }else{
317 408 cookieadmin_toggle_overlay();
318 409 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "flex";
319 410 }
@@ -337,9 +428,8 @@
337 428
338 429 }
339 430
340 431 //Edit Notice and Modal contents
341 - document.getElementsByClassName("cookieadmin_reconsent_img")[0].src = cookieadmin_policy.plugin_url + "/assets/images/cookieadmin_icon.svg";
342 432
343 433 cookieadmin_populate_preference();
344 434
345 435 for(data in cookieadmin_policy){
@@ -384,9 +474,9 @@
384 474 }
385 475 }
386 476
387 477 //Add layout as class
388 - if(!!cookieadmin_policy.cookieadmin_position){
478 + if(!!cookieadmin_policy.cookieadmin_position && cookieadmin_policy.cookieadmin_layout !== "popup"){
389 479 cookieadmin_policy.cookieadmin_position.split("_").forEach(function(clas){
390 480 clas = "cookieadmin_" + clas;
391 481 document.getElementsByClassName("cookieadmin_law_container")[0].classList.add(clas);
392 482 });
@@ -392,9 +482,13 @@
392 482 });
393 483 }
394 484
395 485 // Change consent layout dynamically
396 - document.getElementsByClassName("cookieadmin_law_container")[0].classList.add("cookieadmin_" + cookieadmin_policy.cookieadmin_layout);
486 + // TODO: There is a operator called optional chaining operator ?. something like this users?.[0]?.name; wont use it now just for reference
487 + var cookieadmin_law_container_var = document.getElementsByClassName("cookieadmin_law_container")[0];
488 + if (!!cookieadmin_law_container_var){
489 + cookieadmin_law_container_var.classList.add("cookieadmin_" + cookieadmin_policy.cookieadmin_layout);
490 + }
397 491
398 492 // Change Modal layout dynamically
399 493 document.getElementsByClassName("cookieadmin_cookie_modal")[0].classList.add("cookieadmin_" + cookieadmin_policy.cookieadmin_modal);
400 494
@@ -401,11 +495,8 @@
401 495 /*if(cookieadmin_policy.layout == "footer"){
402 496
403 497 }*/
404 498
405 - if(cookieadmin_policy.cookieadmin_modal == "side"){
406 - document.getElementsByClassName("cookieadmin_footer")[0].style.flexDirection = "column";
407 - }
408 499
409 500 // Remove modal close Button
410 501 if(cookieadmin_policy.cookieadmin_layout == "popup"){
411 502 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
@@ -410,8 +501,19 @@
410 501 if(cookieadmin_policy.cookieadmin_layout == "popup"){
411 502 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
412 503 }
413 504
505 + var cookieadmin_modal_opener = null;
506 +
507 + // Focus goes back to the reconsent/Customize button that opened the modal.
508 + // focus() on a hidden opener is a no-op, which is fine.
509 + function cookieadmin_return_focus(){
510 + if(cookieadmin_modal_opener){
511 + cookieadmin_modal_opener.focus();
512 + cookieadmin_modal_opener = null;
513 + }
514 + }
515 +
414 516 //show preference modal
415 517 cookieadmin_show_modal_elemnts = document.querySelectorAll(".cookieadmin_re_consent, .cookieadmin_customize_btn");
416 518 cookieadmin_show_modal_elemnts.forEach(function(e){
417 519
@@ -425,20 +527,24 @@
425 527 });*/
426 528
427 529 cookieadmin_toggle_overlay();
428 530 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "flex";
429 - document.getElementsByClassName("cookieadmin_re_consent")[0].style.display = "none";
430 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "none";
531 + var cookieadmin_re_consent = document.getElementsByClassName("cookieadmin_re_consent")[0];
532 + if(cookieadmin_re_consent){
533 + cookieadmin_re_consent.style.display = "none";
534 + }
535 +
536 + var cookieadmin_law_container = document.getElementsByClassName("cookieadmin_law_container")[0];
537 + if(cookieadmin_law_container){
538 + cookieadmin_law_container.style.display = "none";
539 + }
431 540
432 541 if(cookieadmin_policy["cookieadmin_modal"] == "side"){
433 542 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "grid";
434 543 }
435 544
436 - if(e.target.className == "cookieadmin_re_consent"){
437 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_re_consent";
438 - }else{
439 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_law_container";
440 - }
545 + // Remember what opened the modal so focus can go back to it on close
546 + cookieadmin_modal_opener = e.currentTarget;
441 547 });
442 548 });
443 549
444 550 //Save preference
@@ -457,26 +563,37 @@
457 563 }
458 564 });
459 565
460 566 if(Object.keys(prefer).length !== 0){
461 - if(Object.keys(prefer).length === 3){
462 - document.querySelectorAll(".cookieadmin_accept_btn")[1].click();
567 + var override_gpc = document.getElementById('cookieadmin-override_gpc');
568 + var is_override_gpc = false;
569 + if(override_gpc && override_gpc.checked){
570 + is_override_gpc = true;
571 + }
572 +
573 + if(Object.keys(prefer).length === 3 && !is_override_gpc){
574 + let accept_btn = document.querySelectorAll(".cookieadmin_accept_btn");
575 +
576 + if(accept_btn.length > 0){
577 + accept_btn[accept_btn.length-1].click();
578 + }
579 +
463 580 return;
464 581 }
465 582 }else{
466 - document.querySelectorAll(".cookieadmin_reject_btn")[1].click();
583 + let reject_btn = document.querySelectorAll(".cookieadmin_reject_btn");
584 +
585 + if(reject_btn.length > 0){
586 + reject_btn[reject_btn.length-1].click();
587 + }
588 +
467 589 return;
468 590 }
469 591
470 592 cookieadmin_toggle_overlay();
593 + cookieadmin_return_focus();
471 594
472 595 cookieadmin_set_consent(prefer, days);
473 -
474 - if(!!cookieadmin_policy.reload_on_consent){
475 - location.reload();
476 - }else{
477 - cookieadmin_restore_cookies(prefer);
478 - }
479 596 });
480 597
481 598
482 599 //Accept or reject all cookies
@@ -487,54 +604,40 @@
487 604 e.addEventListener("click", function(){
488 605 // console.log(e);
489 606
490 607 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "none";
491 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "none";
492 - if(cookieadmin_show_reconsent){
493 - document.getElementsByClassName("cookieadmin_re_consent")[0].style.display = "block";
608 + var cookieadmin_law_container = document.getElementsByClassName("cookieadmin_law_container")[0];
609 + if(cookieadmin_law_container){
610 + cookieadmin_law_container.style.display = "none";
494 611 }
495 612
613 + var cookieadmin_re_consent = document.getElementsByClassName("cookieadmin_re_consent")[0];
614 + if(cookieadmin_re_consent){
615 + cookieadmin_re_consent.style.display = "block";
616 + }
617 +
496 618 if(e.id.includes("modal")){
497 619 cookieadmin_toggle_overlay();
620 + cookieadmin_return_focus();
498 621 }
499 622
500 623 var prefer2 = e.classList.contains("cookieadmin_reject_btn") ? {reject: "true"} : {accept: "true"};
501 -
624 +
502 625 cookieadmin_set_consent(prefer2, days);
503 -
504 - if(!!cookieadmin_policy.reload_on_consent){
505 - location.reload();
506 - }else{
507 - cookieadmin_restore_cookies(prefer2);
508 - }
509 626 });
510 627 });
511 628
512 - //showmore modal btn
513 - document.getElementsByClassName("cookieadmin_showmore")[0]?.addEventListener("click", function(){
514 - if(this.innerHTML.includes("more")){
515 - document.getElementsByClassName("cookieadmin_preference")[0].style.height = "auto";
516 - this.innerHTML = "show less";
517 - }else{
518 - document.getElementsByClassName("cookieadmin_preference")[0].style.height = "";
519 - this.innerHTML = "show more";
520 - }
521 - });
522 -
523 -
524 - document.querySelectorAll(".show_pref_cookies").forEach(function(e){
629 + document.querySelectorAll(".cookieadmin_header .cookieadmin_show_pref_cookies").forEach(function(e){
525 630 e.addEventListener("click", function(el){
526 631
527 - var tgt = el.target.id;
632 + var tgt = el.currentTarget.id;
528 633 tgt = tgt.replace(/-container$/, "");
529 634
530 - if(el.target.classList.contains("dwn")){
531 - el.target.innerHTML = "&#9658;";
532 - el.target.classList.remove("dwn");
635 + if(el.currentTarget.classList.contains("dwn")){
636 + el.currentTarget.classList.remove("dwn");
533 637 document.querySelector("."+tgt).style.display = "none";
534 638 }else{
535 - el.target.innerHTML = "&#9660;";
536 - el.target.classList.add("dwn");
639 + el.currentTarget.classList.add("dwn");
537 640 document.querySelector("."+tgt).style.display = "block";
538 641 }
539 642 });
540 643 });
@@ -542,12 +645,20 @@
542 645 document.getElementsByClassName("cookieadmin_close_pref")[0].addEventListener("click", function(e){
543 646 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "none";
544 647 cookieadmin_toggle_overlay();
545 648 if(!cookieadmin_is_obj(cookieadmin_is_consent)){
546 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
649 + var cookieadmin_law_container = document.getElementsByClassName("cookieadmin_law_container")[0];
650 + if(cookieadmin_law_container){
651 + cookieadmin_law_container.style.display = "block";
652 + }
547 653 }else if(cookieadmin_show_reconsent){
548 - document.getElementsByClassName("cookieadmin_re_consent")[0].style.display = "block";
654 + var cookieadmin_re_consent = document.getElementsByClassName("cookieadmin_re_consent")[0];
655 + if(cookieadmin_re_consent){
656 + cookieadmin_re_consent.style.display = "block";
657 + }
549 658 }
659 +
660 + cookieadmin_return_focus();
550 661 });
551 662
552 663 });
553 664
@@ -552,17 +663,22 @@
552 663 });
553 664
554 665 function cookieadmin_set_consent(prefrenc, days){
555 666
667 + if (typeof cookieadmin_pro_set_consent === "function") {
668 + return cookieadmin_pro_set_consent(prefrenc, days);
669 + }else{
670 + return cookieadmin_save_consent_cookie(prefrenc, days);
671 + }
672 +}
673 +
674 +function cookieadmin_save_consent_cookie(prefrenc, days, consent_id){
675 +
556 676 var cookieadmin_consent = prefrenc;
557 -
558 - if (typeof cookieadmin_pro_set_consent === "function") {
559 - consent_id = cookieadmin_pro_set_consent(prefrenc, days);
560 677
561 - if(consent_id){
562 - cookieadmin_is_consent.consent = consent_id;
563 - cookieadmin_consent['consent'] = consent_id;
564 - }
678 + if(consent_id){
679 + cookieadmin_is_consent.consent = consent_id;
680 + cookieadmin_consent['consent'] = consent_id;
565 681 }
566 682
567 683 if(!cookieadmin_is_consent.consent){
568 684 cookieadmin_is_consent.consent = "";
@@ -575,15 +691,16 @@
575 691
576 692 if (typeof cookieadmin_update_gcm === "function") {
577 693 cookieadmin_update_gcm(1);
578 694 }
579 -
580 -}
581 695
582 -function cookieadmin_get_base_path() {
696 + if (typeof cookieadmin_pro_update_clarity_cookie === "function") {
697 + cookieadmin_pro_update_clarity_cookie();
698 + }
583 699
584 - if(window.location.pathname.trim() != '/'){
585 - const parts = window.location.pathname.split('/');
586 - return '/' + (parts[1] || '') + '/';
700 + if(!!cookieadmin_policy.reload_on_consent){
701 + location.reload();
702 + }else{
703 + cookieadmin_restore_cookies(prefrenc);
587 704 }
588 - return '/';
589 705 }
706 +