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 +40 -19 1.1.9 → 1.2.6 View file →
@@ -205,8 +205,11 @@
205 205 if (!name || !value) return false;
206 206
207 207 if((cookieadmin_policy.is_pro != 0) && (cookieadmin_pro_vars !== 'undefined')){
208 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};`;
209 212 domain = cookieadmin_pro_vars.base_domain;
210 213 }
211 214 }
212 215
@@ -230,8 +233,16 @@
230 233 return true;
231 234 }
232 235
233 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 +
234 245 function cookieadmin_populate_preference(){
235 246
236 247 consent = cookieadmin_is_consent.action;
237 248
@@ -263,10 +274,8 @@
263 274 }
264 275 });
265 276 }
266 277
267 - var cookieadmin_shown = (typeof cookieadmin_shown !== "undefined") ? cookieadmin_shown : [];
268 -
269 278 if(cookieadmin_allcookies){
270 279
271 280 var cookieadmin_filtrd = Object.keys(cookieadmin_allcookies).filter(e => !cookieadmin_shown.includes(e));
272 281
@@ -281,9 +290,10 @@
281 290
282 291 if(!card_container){
283 292 continue;
284 293 }
285 - card_container.innerHTML = (card_container.innerHTML == 'None') ? '' : card_container.innerHTML;
294 +
295 + card_container.querySelector(".cookieadmin-nocookie-cat").style.display = 'none';
286 296
287 297 var cookieadmin_exp = cookieadmin_policy.lang.session;
288 298
289 299 if(
@@ -301,9 +311,13 @@
301 311 }
302 312 }
303 313 }
304 314
305 - card_container.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>'+ cookieadmin_policy.lang.duration +':</b> '+ cookieadmin_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>';
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>');
306 320 cookieadmin_shown.push(c_info);
307 321 }
308 322 }
309 323
@@ -481,11 +495,8 @@
481 495 /*if(cookieadmin_policy.layout == "footer"){
482 496
483 497 }*/
484 498
485 - if(cookieadmin_policy.cookieadmin_modal == "side"){
486 - document.getElementsByClassName("cookieadmin_modal_footer")[0].style.flexDirection = "column";
487 - }
488 499
489 500 // Remove modal close Button
490 501 if(cookieadmin_policy.cookieadmin_layout == "popup"){
491 502 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
@@ -490,8 +501,19 @@
490 501 if(cookieadmin_policy.cookieadmin_layout == "popup"){
491 502 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
492 503 }
493 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 +
494 516 //show preference modal
495 517 cookieadmin_show_modal_elemnts = document.querySelectorAll(".cookieadmin_re_consent, .cookieadmin_customize_btn");
496 518 cookieadmin_show_modal_elemnts.forEach(function(e){
497 519
@@ -519,13 +541,10 @@
519 541 if(cookieadmin_policy["cookieadmin_modal"] == "side"){
520 542 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "grid";
521 543 }
522 544
523 - if(e.target.className == "cookieadmin_re_consent"){
524 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_re_consent";
525 - }else{
526 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_law_container";
527 - }
545 + // Remember what opened the modal so focus can go back to it on close
546 + cookieadmin_modal_opener = e.currentTarget;
528 547 });
529 548 });
530 549
531 550 //Save preference
@@ -570,8 +589,9 @@
570 589 return;
571 590 }
572 591
573 592 cookieadmin_toggle_overlay();
593 + cookieadmin_return_focus();
574 594
575 595 cookieadmin_set_consent(prefer, days);
576 596 });
577 597
@@ -596,8 +616,9 @@
596 616 }
597 617
598 618 if(e.id.includes("modal")){
599 619 cookieadmin_toggle_overlay();
620 + cookieadmin_return_focus();
600 621 }
601 622
602 623 var prefer2 = e.classList.contains("cookieadmin_reject_btn") ? {reject: "true"} : {accept: "true"};
603 624
@@ -604,21 +625,19 @@
604 625 cookieadmin_set_consent(prefer2, days);
605 626 });
606 627 });
607 628
608 - document.querySelectorAll(".cookieadmin_show_pref_cookies").forEach(function(e){
629 + document.querySelectorAll(".cookieadmin_header .cookieadmin_show_pref_cookies").forEach(function(e){
609 630 e.addEventListener("click", function(el){
610 631
611 - var tgt = el.target.id;
632 + var tgt = el.currentTarget.id;
612 633 tgt = tgt.replace(/-container$/, "");
613 634
614 - if(el.target.classList.contains("dwn")){
615 - el.target.innerHTML = "&#9658;";
616 - el.target.classList.remove("dwn");
635 + if(el.currentTarget.classList.contains("dwn")){
636 + el.currentTarget.classList.remove("dwn");
617 637 document.querySelector("."+tgt).style.display = "none";
618 638 }else{
619 - el.target.innerHTML = "&#9660;";
620 - el.target.classList.add("dwn");
639 + el.currentTarget.classList.add("dwn");
621 640 document.querySelector("."+tgt).style.display = "block";
622 641 }
623 642 });
624 643 });
@@ -636,8 +655,10 @@
636 655 if(cookieadmin_re_consent){
637 656 cookieadmin_re_consent.style.display = "block";
638 657 }
639 658 }
659 +
660 + cookieadmin_return_focus();
640 661 });
641 662
642 663 });
643 664