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