PluginProbe
CookieAdmin – Cookie Consent Banner / 1.2.5
CookieAdmin – Cookie Consent Banner v1.2.5
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 1.1.8
← All changes | assets/js/consent.js +252 -130 1.0.8 → 1.2.5 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;
@@ -168,14 +203,23 @@
168 203
169 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=${cookieadmin_policy.base_path};`;
221 + cookieString += ` path=${!domain ? cookieadmin_policy.base_path : '/'};`;
178 222 cookieString += ` SameSite=Lax;`;
179 223 if(cookieadmin_policy.is_ssl || window.location.protocol === 'https:'){
180 224 cookieString += ` Secure;`;
181 225 }
@@ -188,9 +232,14 @@
188 232 document.cookie = cookieString;
189 233 return true;
190 234 }
191 235
192 -//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 +
193 242 function cookieadmin_populate_preference(){
194 243
195 244 consent = cookieadmin_is_consent.action;
196 245
@@ -212,34 +261,62 @@
212 261 btn_ele.checked = true;
213 262 }
214 263 }
215 264 }
265 + //Load as per preloaded categories selected by admin
266 + }else if(cookieadmin_policy['preload'] && cookieadmin_policy['preload'].length > 0){
267 +
268 + cookieadmin_policy['preload'].forEach(function(val){
269 + if(btn_ele = document.querySelector("#cookieadmin-" + val)){
270 + btn_ele.checked = true;
271 + }
272 + });
216 273 }
217 274
218 - cookieadmin_shown = (typeof cookieadmin_shown !== "undefined") ? cookieadmin_shown : [];
275 + var cookieadmin_shown = (typeof cookieadmin_shown !== "undefined") ? cookieadmin_shown : [];
219 276
220 277 if(cookieadmin_allcookies){
221 278
222 - cookieadmin_filtrd = Object.keys(cookieadmin_allcookies).filter(e => !cookieadmin_shown.includes(e));
279 + var cookieadmin_filtrd = Object.keys(cookieadmin_allcookies).filter(e => !cookieadmin_shown.includes(e));
223 280
224 281 for(c_info of cookieadmin_filtrd){
225 282
226 - if(e = document.querySelector(".cookieadmin-" + cookieadmin_allcookies[c_info].category?.toLowerCase())){
227 - e.innerHTML = (e.innerHTML == 'None') ? '' : e.innerHTML;
283 + var category_var = cookieadmin_allcookies[c_info].category;
284 +
285 + if(!category_var){
286 + continue;
287 + }
288 + var card_container = document.querySelector(".cookieadmin-" + category_var.toLowerCase());
289 +
290 + if(!card_container){
291 + continue;
292 + }
293 +
294 + card_container.querySelector(".cookieadmin-nocookie-cat").style.display = 'none';
295 +
296 + var cookieadmin_exp = cookieadmin_policy.lang.session;
228 297
229 - exp = 'Session';
230 -
231 - if(!!cookieadmin_allcookies[c_info].expires){
232 - exp = Math.round((cookieadmin_allcookies[c_info].expires - Date.now())/86400);
233 - if(exp < 1 && !!res['Max-Age']){
234 - exp = res['Max-Age'];
235 - }else{
236 - exp = 'Session';
298 + if(
299 + !!cookieadmin_allcookies[c_info].expires
300 + && cookieadmin_allcookies[c_info].expires !== "0000-00-00 00:00:00"
301 + ){
302 +
303 + var expDate = new Date(cookieadmin_allcookies[c_info].expires.replace(' ', 'T'));
304 +
305 + if (!isNaN(expDate.getTime())) {
306 + var daysLeft = Math.ceil((expDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24));
307 +
308 + if (daysLeft > 0) {
309 + cookieadmin_exp = daysLeft +' '+ cookieadmin_policy.lang.days;
237 310 }
238 311 }
239 -
240 - 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>';
241 312 }
313 +
314 + var cookieadmin_desc = cookieadmin_allcookies[c_info].description;
315 + var cookieadmin_platform = cookieadmin_allcookies[c_info].platform;
316 +
317 + // Empty description/platform rows are skipped so the card has no blank gap or "null" text
318 + 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>');
242 319 cookieadmin_shown.push(c_info);
243 320 }
244 321 }
245 322
@@ -275,9 +352,9 @@
275 352 if(!cookieadmin_is_obj(cookieadmin_chk_cookies)){
276 353 return;
277 354 }
278 355
279 - /* const xhttp2 = new XMLHttpRequest();
356 + /* var xhttp2 = new XMLHttpRequest();
280 357
281 358 var data = 'action=cookieadmin_ajax_handler&cookieadmin_act=categorize_cookies&cookieadmin_security=' + cookieadmin_policy.nonce + "&cookieadmin_cookies=" + JSON.stringify(cookieadmin_chk_cookies);
282 359
283 360 xhttp2.onload = function() {
@@ -303,8 +380,13 @@
303 380 }
304 381
305 382
306 383 document.addEventListener("DOMContentLoaded", function() {
384 +
385 + var cookieadmin_show_reconsent = 0;
386 + if(cookieadmin_policy.is_pro != 0 && cookieadmin_pro_vars !== 'undefined' && cookieadmin_pro_vars.reconsent != 0){
387 + var cookieadmin_show_reconsent = 1;
388 + }
307 389
308 390 //Create overlay
309 391 var cookieadmin_ovrlay = document.createElement("div");
310 392 cookieadmin_ovrlay.className = "cookieadmin_modal_overlay";
@@ -309,13 +391,19 @@
309 391 var cookieadmin_ovrlay = document.createElement("div");
310 392 cookieadmin_ovrlay.className = "cookieadmin_modal_overlay";
311 393 document.body.appendChild(cookieadmin_ovrlay);
312 394
395 + var before_consent_dispaly = new CustomEvent('cookieadmin_before_consent_display');
396 +
397 + // For anything that needs to be done before disaplying consent.
398 + cookieadmin_policy.hide_banner = false; // initializing
399 + window.dispatchEvent(before_consent_dispaly);
400 +
313 401 //Show notice or re-consent icon as needed
314 - if(!cookieadmin_is_obj(cookieadmin_is_consent)){
402 + if(!cookieadmin_is_obj(cookieadmin_is_consent) && !cookieadmin_policy.hide_banner){
315 403
316 404 if(cookieadmin_policy.cookieadmin_layout !== "popup"){
317 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
405 + document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
318 406 }else{
319 407 cookieadmin_toggle_overlay();
320 408 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "flex";
321 409 }
@@ -339,9 +427,8 @@
339 427
340 428 }
341 429
342 430 //Edit Notice and Modal contents
343 - document.getElementsByClassName("cookieadmin_reconsent_img")[0].src = cookieadmin_policy.plugin_url + "/assets/images/cookieadmin_icon.svg";
344 431
345 432 cookieadmin_populate_preference();
346 433
347 434 for(data in cookieadmin_policy){
@@ -386,9 +473,9 @@
386 473 }
387 474 }
388 475
389 476 //Add layout as class
390 - if(!!cookieadmin_policy.cookieadmin_position){
477 + if(!!cookieadmin_policy.cookieadmin_position && cookieadmin_policy.cookieadmin_layout !== "popup"){
391 478 cookieadmin_policy.cookieadmin_position.split("_").forEach(function(clas){
392 479 clas = "cookieadmin_" + clas;
393 480 document.getElementsByClassName("cookieadmin_law_container")[0].classList.add(clas);
394 481 });
@@ -394,9 +481,13 @@
394 481 });
395 482 }
396 483
397 484 // Change consent layout dynamically
398 - document.getElementsByClassName("cookieadmin_law_container")[0].classList.add("cookieadmin_" + cookieadmin_policy.cookieadmin_layout);
485 + // TODO: There is a operator called optional chaining operator ?. something like this users?.[0]?.name; wont use it now just for reference
486 + var cookieadmin_law_container_var = document.getElementsByClassName("cookieadmin_law_container")[0];
487 + if (!!cookieadmin_law_container_var){
488 + cookieadmin_law_container_var.classList.add("cookieadmin_" + cookieadmin_policy.cookieadmin_layout);
489 + }
399 490
400 491 // Change Modal layout dynamically
401 492 document.getElementsByClassName("cookieadmin_cookie_modal")[0].classList.add("cookieadmin_" + cookieadmin_policy.cookieadmin_modal);
402 493
@@ -403,11 +494,8 @@
403 494 /*if(cookieadmin_policy.layout == "footer"){
404 495
405 496 }*/
406 497
407 - if(cookieadmin_policy.cookieadmin_modal == "side"){
408 - document.getElementsByClassName("cookieadmin_modal_footer")[0].style.flexDirection = "column";
409 - }
410 498
411 499 // Remove modal close Button
412 500 if(cookieadmin_policy.cookieadmin_layout == "popup"){
413 501 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
@@ -412,8 +500,19 @@
412 500 if(cookieadmin_policy.cookieadmin_layout == "popup"){
413 501 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
414 502 }
415 503
504 + var cookieadmin_modal_opener = null;
505 +
506 + // Focus goes back to the reconsent/Customize button that opened the modal.
507 + // focus() on a hidden opener is a no-op, which is fine.
508 + function cookieadmin_return_focus(){
509 + if(cookieadmin_modal_opener){
510 + cookieadmin_modal_opener.focus();
511 + cookieadmin_modal_opener = null;
512 + }
513 + }
514 +
416 515 //show preference modal
417 516 cookieadmin_show_modal_elemnts = document.querySelectorAll(".cookieadmin_re_consent, .cookieadmin_customize_btn");
418 517 cookieadmin_show_modal_elemnts.forEach(function(e){
419 518
@@ -427,20 +526,24 @@
427 526 });*/
428 527
429 528 cookieadmin_toggle_overlay();
430 529 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "flex";
431 - document.getElementsByClassName("cookieadmin_re_consent")[0].style.display = "none";
432 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "none";
530 + var cookieadmin_re_consent = document.getElementsByClassName("cookieadmin_re_consent")[0];
531 + if(cookieadmin_re_consent){
532 + cookieadmin_re_consent.style.display = "none";
533 + }
534 +
535 + var cookieadmin_law_container = document.getElementsByClassName("cookieadmin_law_container")[0];
536 + if(cookieadmin_law_container){
537 + cookieadmin_law_container.style.display = "none";
538 + }
433 539
434 540 if(cookieadmin_policy["cookieadmin_modal"] == "side"){
435 541 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "grid";
436 542 }
437 543
438 - if(e.target.className == "cookieadmin_re_consent"){
439 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_re_consent";
440 - }else{
441 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_law_container";
442 - }
544 + // Remember what opened the modal so focus can go back to it on close
545 + cookieadmin_modal_opener = e.currentTarget;
443 546 });
444 547 });
445 548
446 549 //Save preference
@@ -459,26 +562,37 @@
459 562 }
460 563 });
461 564
462 565 if(Object.keys(prefer).length !== 0){
463 - if(Object.keys(prefer).length === 3){
464 - document.querySelectorAll(".cookieadmin_accept_btn")[1].click();
566 + var override_gpc = document.getElementById('cookieadmin-override_gpc');
567 + var is_override_gpc = false;
568 + if(override_gpc && override_gpc.checked){
569 + is_override_gpc = true;
570 + }
571 +
572 + if(Object.keys(prefer).length === 3 && !is_override_gpc){
573 + let accept_btn = document.querySelectorAll(".cookieadmin_accept_btn");
574 +
575 + if(accept_btn.length > 0){
576 + accept_btn[accept_btn.length-1].click();
577 + }
578 +
465 579 return;
466 580 }
467 581 }else{
468 - document.querySelectorAll(".cookieadmin_reject_btn")[1].click();
582 + let reject_btn = document.querySelectorAll(".cookieadmin_reject_btn");
583 +
584 + if(reject_btn.length > 0){
585 + reject_btn[reject_btn.length-1].click();
586 + }
587 +
469 588 return;
470 589 }
471 590
472 591 cookieadmin_toggle_overlay();
592 + cookieadmin_return_focus();
473 593
474 594 cookieadmin_set_consent(prefer, days);
475 -
476 - if(!!cookieadmin_policy.reload_on_consent){
477 - location.reload();
478 - }else{
479 - cookieadmin_restore_cookies(prefer);
480 - }
481 595 });
482 596
483 597
484 598 //Accept or reject all cookies
@@ -489,54 +603,40 @@
489 603 e.addEventListener("click", function(){
490 604 // console.log(e);
491 605
492 606 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "none";
493 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "none";
494 - if(cookieadmin_show_reconsent){
495 - document.getElementsByClassName("cookieadmin_re_consent")[0].style.display = "block";
607 + var cookieadmin_law_container = document.getElementsByClassName("cookieadmin_law_container")[0];
608 + if(cookieadmin_law_container){
609 + cookieadmin_law_container.style.display = "none";
496 610 }
497 611
612 + var cookieadmin_re_consent = document.getElementsByClassName("cookieadmin_re_consent")[0];
613 + if(cookieadmin_re_consent){
614 + cookieadmin_re_consent.style.display = "block";
615 + }
616 +
498 617 if(e.id.includes("modal")){
499 618 cookieadmin_toggle_overlay();
619 + cookieadmin_return_focus();
500 620 }
501 621
502 622 var prefer2 = e.classList.contains("cookieadmin_reject_btn") ? {reject: "true"} : {accept: "true"};
503 -
623 +
504 624 cookieadmin_set_consent(prefer2, days);
505 -
506 - if(!!cookieadmin_policy.reload_on_consent){
507 - location.reload();
508 - }else{
509 - cookieadmin_restore_cookies(prefer2);
510 - }
511 625 });
512 626 });
513 627
514 - //showmore modal btn
515 - document.getElementsByClassName("cookieadmin_showmore")[0]?.addEventListener("click", function(){
516 - if(this.innerHTML.includes("more")){
517 - document.getElementsByClassName("cookieadmin_preference")[0].style.height = "auto";
518 - this.innerHTML = "show less";
519 - }else{
520 - document.getElementsByClassName("cookieadmin_preference")[0].style.height = "";
521 - this.innerHTML = "show more";
522 - }
523 - });
524 -
525 -
526 - document.querySelectorAll(".cookieadmin_show_pref_cookies").forEach(function(e){
628 + document.querySelectorAll(".cookieadmin_header .cookieadmin_show_pref_cookies").forEach(function(e){
527 629 e.addEventListener("click", function(el){
528 630
529 - var tgt = el.target.id;
631 + var tgt = el.currentTarget.id;
530 632 tgt = tgt.replace(/-container$/, "");
531 633
532 - if(el.target.classList.contains("dwn")){
533 - el.target.innerHTML = "&#9658;";
534 - el.target.classList.remove("dwn");
634 + if(el.currentTarget.classList.contains("dwn")){
635 + el.currentTarget.classList.remove("dwn");
535 636 document.querySelector("."+tgt).style.display = "none";
536 637 }else{
537 - el.target.innerHTML = "&#9660;";
538 - el.target.classList.add("dwn");
638 + el.currentTarget.classList.add("dwn");
539 639 document.querySelector("."+tgt).style.display = "block";
540 640 }
541 641 });
542 642 });
@@ -544,12 +644,20 @@
544 644 document.getElementsByClassName("cookieadmin_close_pref")[0].addEventListener("click", function(e){
545 645 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "none";
546 646 cookieadmin_toggle_overlay();
547 647 if(!cookieadmin_is_obj(cookieadmin_is_consent)){
548 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
648 + var cookieadmin_law_container = document.getElementsByClassName("cookieadmin_law_container")[0];
649 + if(cookieadmin_law_container){
650 + cookieadmin_law_container.style.display = "block";
651 + }
549 652 }else if(cookieadmin_show_reconsent){
550 - document.getElementsByClassName("cookieadmin_re_consent")[0].style.display = "block";
653 + var cookieadmin_re_consent = document.getElementsByClassName("cookieadmin_re_consent")[0];
654 + if(cookieadmin_re_consent){
655 + cookieadmin_re_consent.style.display = "block";
656 + }
551 657 }
658 +
659 + cookieadmin_return_focus();
552 660 });
553 661
554 662 });
555 663
@@ -554,17 +662,22 @@
554 662 });
555 663
556 664 function cookieadmin_set_consent(prefrenc, days){
557 665
666 + if (typeof cookieadmin_pro_set_consent === "function") {
667 + return cookieadmin_pro_set_consent(prefrenc, days);
668 + }else{
669 + return cookieadmin_save_consent_cookie(prefrenc, days);
670 + }
671 +}
672 +
673 +function cookieadmin_save_consent_cookie(prefrenc, days, consent_id){
674 +
558 675 var cookieadmin_consent = prefrenc;
559 -
560 - if (typeof cookieadmin_pro_set_consent === "function") {
561 - consent_id = cookieadmin_pro_set_consent(prefrenc, days);
562 676
563 - if(consent_id){
564 - cookieadmin_is_consent.consent = consent_id;
565 - cookieadmin_consent['consent'] = consent_id;
566 - }
677 + if(consent_id){
678 + cookieadmin_is_consent.consent = consent_id;
679 + cookieadmin_consent['consent'] = consent_id;
567 680 }
568 681
569 682 if(!cookieadmin_is_consent.consent){
570 683 cookieadmin_is_consent.consent = "";
@@ -577,7 +690,16 @@
577 690
578 691 if (typeof cookieadmin_update_gcm === "function") {
579 692 cookieadmin_update_gcm(1);
580 693 }
694 +
695 + if (typeof cookieadmin_pro_update_clarity_cookie === "function") {
696 + cookieadmin_pro_update_clarity_cookie();
697 + }
581 698
699 + if(!!cookieadmin_policy.reload_on_consent){
700 + location.reload();
701 + }else{
702 + cookieadmin_restore_cookies(prefrenc);
703 + }
582 704 }
583 705