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 +32 -16 1.2.2 → 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
@@ -485,11 +494,8 @@
485 494 /*if(cookieadmin_policy.layout == "footer"){
486 495
487 496 }*/
488 497
489 - if(cookieadmin_policy.cookieadmin_modal == "side"){
490 - document.getElementsByClassName("cookieadmin_modal_footer")[0].style.flexDirection = "column";
491 - }
492 498
493 499 // Remove modal close Button
494 500 if(cookieadmin_policy.cookieadmin_layout == "popup"){
495 501 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
@@ -494,8 +500,19 @@
494 500 if(cookieadmin_policy.cookieadmin_layout == "popup"){
495 501 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
496 502 }
497 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 +
498 515 //show preference modal
499 516 cookieadmin_show_modal_elemnts = document.querySelectorAll(".cookieadmin_re_consent, .cookieadmin_customize_btn");
500 517 cookieadmin_show_modal_elemnts.forEach(function(e){
501 518
@@ -523,13 +540,10 @@
523 540 if(cookieadmin_policy["cookieadmin_modal"] == "side"){
524 541 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "grid";
525 542 }
526 543
527 - if(e.target.className == "cookieadmin_re_consent"){
528 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_re_consent";
529 - }else{
530 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_law_container";
531 - }
544 + // Remember what opened the modal so focus can go back to it on close
545 + cookieadmin_modal_opener = e.currentTarget;
532 546 });
533 547 });
534 548
535 549 //Save preference
@@ -574,8 +588,9 @@
574 588 return;
575 589 }
576 590
577 591 cookieadmin_toggle_overlay();
592 + cookieadmin_return_focus();
578 593
579 594 cookieadmin_set_consent(prefer, days);
580 595 });
581 596
@@ -600,8 +615,9 @@
600 615 }
601 616
602 617 if(e.id.includes("modal")){
603 618 cookieadmin_toggle_overlay();
619 + cookieadmin_return_focus();
604 620 }
605 621
606 622 var prefer2 = e.classList.contains("cookieadmin_reject_btn") ? {reject: "true"} : {accept: "true"};
607 623
@@ -608,21 +624,19 @@
608 624 cookieadmin_set_consent(prefer2, days);
609 625 });
610 626 });
611 627
612 - document.querySelectorAll(".cookieadmin_show_pref_cookies").forEach(function(e){
628 + document.querySelectorAll(".cookieadmin_header .cookieadmin_show_pref_cookies").forEach(function(e){
613 629 e.addEventListener("click", function(el){
614 630
615 - var tgt = el.target.id;
631 + var tgt = el.currentTarget.id;
616 632 tgt = tgt.replace(/-container$/, "");
617 633
618 - if(el.target.classList.contains("dwn")){
619 - el.target.innerHTML = "&#9658;";
620 - el.target.classList.remove("dwn");
634 + if(el.currentTarget.classList.contains("dwn")){
635 + el.currentTarget.classList.remove("dwn");
621 636 document.querySelector("."+tgt).style.display = "none";
622 637 }else{
623 - el.target.innerHTML = "&#9660;";
624 - el.target.classList.add("dwn");
638 + el.currentTarget.classList.add("dwn");
625 639 document.querySelector("."+tgt).style.display = "block";
626 640 }
627 641 });
628 642 });
@@ -640,8 +654,10 @@
640 654 if(cookieadmin_re_consent){
641 655 cookieadmin_re_consent.style.display = "block";
642 656 }
643 657 }
658 +
659 + cookieadmin_return_focus();
644 660 });
645 661
646 662 });
647 663