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 +39 -43 1.2.4 → 1.2.5 View file →
@@ -233,8 +233,13 @@
233 233 return true;
234 234 }
235 235
236 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 +
237 242 function cookieadmin_populate_preference(){
238 243
239 244 consent = cookieadmin_is_consent.action;
240 245
@@ -305,9 +310,13 @@
305 310 }
306 311 }
307 312 }
308 313
309 - 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>';
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>');
310 319 cookieadmin_shown.push(c_info);
311 320 }
312 321 }
313 322
@@ -392,13 +401,9 @@
392 401 //Show notice or re-consent icon as needed
393 402 if(!cookieadmin_is_obj(cookieadmin_is_consent) && !cookieadmin_policy.hide_banner){
394 403
395 404 if(cookieadmin_policy.cookieadmin_layout !== "popup"){
396 - var cookieadmin_banner_el = document.getElementsByClassName("cookieadmin_law_container")[0];
397 - if(cookieadmin_banner_el){
398 - cookieadmin_banner_el.style.display = "block";
399 - cookieadmin_banner_el.focus();
400 - }
405 + document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
401 406 }else{
402 407 cookieadmin_toggle_overlay();
403 408 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "flex";
404 409 }
@@ -489,11 +494,8 @@
489 494 /*if(cookieadmin_policy.layout == "footer"){
490 495
491 496 }*/
492 497
493 - if(cookieadmin_policy.cookieadmin_modal == "side"){
494 - document.getElementsByClassName("cookieadmin_modal_footer")[0].style.flexDirection = "column";
495 - }
496 498
497 499 // Remove modal close Button
498 500 if(cookieadmin_policy.cookieadmin_layout == "popup"){
499 501 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
@@ -498,10 +500,19 @@
498 500 if(cookieadmin_policy.cookieadmin_layout == "popup"){
499 501 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
500 502 }
501 503
502 - var cookieadmin_modal_el = document.getElementsByClassName("cookieadmin_cookie_modal")[0];
504 + var cookieadmin_modal_opener = null;
503 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 +
504 515 //show preference modal
505 516 cookieadmin_show_modal_elemnts = document.querySelectorAll(".cookieadmin_re_consent, .cookieadmin_customize_btn");
506 517 cookieadmin_show_modal_elemnts.forEach(function(e){
507 518
@@ -529,15 +540,10 @@
529 540 if(cookieadmin_policy["cookieadmin_modal"] == "side"){
530 541 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "grid";
531 542 }
532 543
533 - if(e.target.className == "cookieadmin_re_consent"){
534 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_re_consent";
535 - }else{
536 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_law_container";
537 - }
538 -
539 - cookieadmin_modal_el.focus();
544 + // Remember what opened the modal so focus can go back to it on close
545 + cookieadmin_modal_opener = e.currentTarget;
540 546 });
541 547 });
542 548
543 549 //Save preference
@@ -582,8 +588,9 @@
582 588 return;
583 589 }
584 590
585 591 cookieadmin_toggle_overlay();
592 + cookieadmin_return_focus();
586 593
587 594 cookieadmin_set_consent(prefer, days);
588 595 });
589 596
@@ -608,8 +615,9 @@
608 615 }
609 616
610 617 if(e.id.includes("modal")){
611 618 cookieadmin_toggle_overlay();
619 + cookieadmin_return_focus();
612 620 }
613 621
614 622 var prefer2 = e.classList.contains("cookieadmin_reject_btn") ? {reject: "true"} : {accept: "true"};
615 623
@@ -616,36 +624,22 @@
616 624 cookieadmin_set_consent(prefer2, days);
617 625 });
618 626 });
619 627
620 - document.querySelectorAll(".cookieadmin_show_pref_cookies").forEach(function(btn){
621 -
622 - // Shared toggle function
623 - function toggleAccordion(event){
624 - // Use currentTarget to target the element with the listener, even if child nodes are clicked
625 - var trigger = event.currentTarget;
626 - var tgt = trigger.id.replace(/-container$/, "");
627 - var targetEl = document.querySelector("." + tgt);
628 -
629 - if (!targetEl){
630 - return;
631 - };
632 -
633 - if(trigger.classList.contains("dwn")){
634 - trigger.innerHTML = "&#9658;"; // Right arrow
635 - trigger.classList.remove("dwn");
636 - trigger.setAttribute("aria-expanded", "false");
637 - targetEl.style.display = "none";
628 + document.querySelectorAll(".cookieadmin_header .cookieadmin_show_pref_cookies").forEach(function(e){
629 + e.addEventListener("click", function(el){
630 +
631 + var tgt = el.currentTarget.id;
632 + tgt = tgt.replace(/-container$/, "");
633 +
634 + if(el.currentTarget.classList.contains("dwn")){
635 + el.currentTarget.classList.remove("dwn");
636 + document.querySelector("."+tgt).style.display = "none";
638 637 }else{
639 - trigger.innerHTML = "&#9660;"; // Down arrow
640 - trigger.classList.add("dwn");
641 - trigger.setAttribute("aria-expanded", "true");
642 - targetEl.style.display = "block";
638 + el.currentTarget.classList.add("dwn");
639 + document.querySelector("."+tgt).style.display = "block";
643 640 }
644 - }
645 -
646 - // 2. Native buttons fire click on mouse, Enter and Space
647 - btn.addEventListener("click", toggleAccordion);
641 + });
648 642 });
649 643
650 644 document.getElementsByClassName("cookieadmin_close_pref")[0].addEventListener("click", function(e){
651 645 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "none";
@@ -660,8 +654,10 @@
660 654 if(cookieadmin_re_consent){
661 655 cookieadmin_re_consent.style.display = "block";
662 656 }
663 657 }
658 +
659 + cookieadmin_return_focus();
664 660 });
665 661
666 662 });
667 663