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 +42 -45 1.2.4 → 1.2.6 View file →
@@ -233,8 +233,16 @@
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 +
242 +// Cookies already rendered in the modal; must live outside the function or each re-populate duplicates the cards
243 +var cookieadmin_shown = [];
244 +
237 245 function cookieadmin_populate_preference(){
238 246
239 247 consent = cookieadmin_is_consent.action;
240 248
@@ -266,10 +274,8 @@
266 274 }
267 275 });
268 276 }
269 277
270 - var cookieadmin_shown = (typeof cookieadmin_shown !== "undefined") ? cookieadmin_shown : [];
271 -
272 278 if(cookieadmin_allcookies){
273 279
274 280 var cookieadmin_filtrd = Object.keys(cookieadmin_allcookies).filter(e => !cookieadmin_shown.includes(e));
275 281
@@ -305,9 +311,13 @@
305 311 }
306 312 }
307 313 }
308 314
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>';
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>');
310 320 cookieadmin_shown.push(c_info);
311 321 }
312 322 }
313 323
@@ -392,13 +402,9 @@
392 402 //Show notice or re-consent icon as needed
393 403 if(!cookieadmin_is_obj(cookieadmin_is_consent) && !cookieadmin_policy.hide_banner){
394 404
395 405 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 - }
406 + document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
401 407 }else{
402 408 cookieadmin_toggle_overlay();
403 409 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "flex";
404 410 }
@@ -489,11 +495,8 @@
489 495 /*if(cookieadmin_policy.layout == "footer"){
490 496
491 497 }*/
492 498
493 - if(cookieadmin_policy.cookieadmin_modal == "side"){
494 - document.getElementsByClassName("cookieadmin_modal_footer")[0].style.flexDirection = "column";
495 - }
496 499
497 500 // Remove modal close Button
498 501 if(cookieadmin_policy.cookieadmin_layout == "popup"){
499 502 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
@@ -498,10 +501,19 @@
498 501 if(cookieadmin_policy.cookieadmin_layout == "popup"){
499 502 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
500 503 }
501 504
502 - var cookieadmin_modal_el = document.getElementsByClassName("cookieadmin_cookie_modal")[0];
505 + var cookieadmin_modal_opener = null;
503 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 +
504 516 //show preference modal
505 517 cookieadmin_show_modal_elemnts = document.querySelectorAll(".cookieadmin_re_consent, .cookieadmin_customize_btn");
506 518 cookieadmin_show_modal_elemnts.forEach(function(e){
507 519
@@ -529,15 +541,10 @@
529 541 if(cookieadmin_policy["cookieadmin_modal"] == "side"){
530 542 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "grid";
531 543 }
532 544
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();
545 + // Remember what opened the modal so focus can go back to it on close
546 + cookieadmin_modal_opener = e.currentTarget;
540 547 });
541 548 });
542 549
543 550 //Save preference
@@ -582,8 +589,9 @@
582 589 return;
583 590 }
584 591
585 592 cookieadmin_toggle_overlay();
593 + cookieadmin_return_focus();
586 594
587 595 cookieadmin_set_consent(prefer, days);
588 596 });
589 597
@@ -608,8 +616,9 @@
608 616 }
609 617
610 618 if(e.id.includes("modal")){
611 619 cookieadmin_toggle_overlay();
620 + cookieadmin_return_focus();
612 621 }
613 622
614 623 var prefer2 = e.classList.contains("cookieadmin_reject_btn") ? {reject: "true"} : {accept: "true"};
615 624
@@ -616,36 +625,22 @@
616 625 cookieadmin_set_consent(prefer2, days);
617 626 });
618 627 });
619 628
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";
629 + document.querySelectorAll(".cookieadmin_header .cookieadmin_show_pref_cookies").forEach(function(e){
630 + e.addEventListener("click", function(el){
631 +
632 + var tgt = el.currentTarget.id;
633 + tgt = tgt.replace(/-container$/, "");
634 +
635 + if(el.currentTarget.classList.contains("dwn")){
636 + el.currentTarget.classList.remove("dwn");
637 + document.querySelector("."+tgt).style.display = "none";
638 638 }else{
639 - trigger.innerHTML = "&#9660;"; // Down arrow
640 - trigger.classList.add("dwn");
641 - trigger.setAttribute("aria-expanded", "true");
642 - targetEl.style.display = "block";
639 + el.currentTarget.classList.add("dwn");
640 + document.querySelector("."+tgt).style.display = "block";
643 641 }
644 - }
645 -
646 - // 2. Native buttons fire click on mouse, Enter and Space
647 - btn.addEventListener("click", toggleAccordion);
642 + });
648 643 });
649 644
650 645 document.getElementsByClassName("cookieadmin_close_pref")[0].addEventListener("click", function(e){
651 646 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "none";
@@ -660,8 +655,10 @@
660 655 if(cookieadmin_re_consent){
661 656 cookieadmin_re_consent.style.display = "block";
662 657 }
663 658 }
659 +
660 + cookieadmin_return_focus();
664 661 });
665 662
666 663 });
667 664