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 +114 -36 1.1.5 → 1.2.5 View file →
@@ -112,9 +112,19 @@
112 112 var nam = name + "=";
113 113
114 114 for(var i=0; i < coki.length; i++){
115 115 if(coki[i].trim().indexOf(nam) == 0){
116 - return coki[i].trim();
116 + try {
117 + var cookie_value = coki[i].trim().split("=");
118 + if(!cookie_value[1]){
119 + return false;
120 + }
121 +
122 + var decoded = decodeURIComponent(cookie_value[1]);
123 + return JSON.parse(decoded);
124 + } catch {
125 + return false;
126 + }
117 127 }
118 128 }
119 129
120 130 return false;
@@ -120,11 +130,10 @@
120 130 return false;
121 131 }
122 132
123 133 function cookieadmin_check_consent(){
124 - var cookieadmin_cookie = cookieadmin_is_cookie("cookieadmin_consent")
134 + var cookieadmin_cookie = cookieadmin_is_cookie("cookieadmin_consent");
125 135 if(!!cookieadmin_cookie){
126 - cookieadmin_cookie = JSON.parse(cookieadmin_cookie.split("=")[1]);
127 136 if(!!cookieadmin_cookie.consent){
128 137 cookieadmin_is_consent.consent = cookieadmin_cookie.consent;
129 138 delete cookieadmin_cookie.consent;
130 139 }
@@ -194,14 +203,23 @@
194 203
195 204 function cookieadmin_set_cookie(name, value, days = 365, domain = "") {
196 205 if (!name || !value) return false;
197 206
207 + if((cookieadmin_policy.is_pro != 0) && (cookieadmin_pro_vars !== 'undefined')){
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};`;
212 + domain = cookieadmin_pro_vars.base_domain;
213 + }
214 + }
215 +
198 216 var date = new Date();
199 217 date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); // default 1 year
200 218
201 219 var cookieString = `${encodeURIComponent(name)}=${JSON.stringify(value)};`;
202 220 cookieString += ` expires=${date.toUTCString()};`;
203 - cookieString += ` path=${cookieadmin_policy.base_path};`;
221 + cookieString += ` path=${!domain ? cookieadmin_policy.base_path : '/'};`;
204 222 cookieString += ` SameSite=Lax;`;
205 223 if(cookieadmin_policy.is_ssl || window.location.protocol === 'https:'){
206 224 cookieString += ` Secure;`;
207 225 }
@@ -215,8 +233,13 @@
215 233 return true;
216 234 }
217 235
218 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 +
219 242 function cookieadmin_populate_preference(){
220 243
221 244 consent = cookieadmin_is_consent.action;
222 245
@@ -266,9 +289,10 @@
266 289
267 290 if(!card_container){
268 291 continue;
269 292 }
270 - card_container.innerHTML = (card_container.innerHTML == 'None') ? '' : card_container.innerHTML;
293 +
294 + card_container.querySelector(".cookieadmin-nocookie-cat").style.display = 'none';
271 295
272 296 var cookieadmin_exp = cookieadmin_policy.lang.session;
273 297
274 298 if(
@@ -286,9 +310,13 @@
286 310 }
287 311 }
288 312 }
289 313
290 - 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>');
291 319 cookieadmin_shown.push(c_info);
292 320 }
293 321 }
294 322
@@ -354,9 +382,9 @@
354 382
355 383 document.addEventListener("DOMContentLoaded", function() {
356 384
357 385 var cookieadmin_show_reconsent = 0;
358 - if(cookieadmin_policy.is_pro != 0 && cookieadmin_pro_vars.reconsent != 0){
386 + if(cookieadmin_policy.is_pro != 0 && cookieadmin_pro_vars !== 'undefined' && cookieadmin_pro_vars.reconsent != 0){
359 387 var cookieadmin_show_reconsent = 1;
360 388 }
361 389
362 390 //Create overlay
@@ -363,13 +391,19 @@
363 391 var cookieadmin_ovrlay = document.createElement("div");
364 392 cookieadmin_ovrlay.className = "cookieadmin_modal_overlay";
365 393 document.body.appendChild(cookieadmin_ovrlay);
366 394
395 + var before_consent_dispaly = new CustomEvent('cookieadmin_before_consent_display');
396 +
397 + // For anything that needs to be done before disaplying consent.
398 + cookieadmin_policy.hide_banner = false; // initializing
399 + window.dispatchEvent(before_consent_dispaly);
400 +
367 401 //Show notice or re-consent icon as needed
368 - if(!cookieadmin_is_obj(cookieadmin_is_consent)){
402 + if(!cookieadmin_is_obj(cookieadmin_is_consent) && !cookieadmin_policy.hide_banner){
369 403
370 404 if(cookieadmin_policy.cookieadmin_layout !== "popup"){
371 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
405 + document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
372 406 }else{
373 407 cookieadmin_toggle_overlay();
374 408 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "flex";
375 409 }
@@ -393,9 +427,8 @@
393 427
394 428 }
395 429
396 430 //Edit Notice and Modal contents
397 - document.getElementsByClassName("cookieadmin_reconsent_img")[0].src = cookieadmin_policy.plugin_url + "/assets/images/cookieadmin_icon.svg";
398 431
399 432 cookieadmin_populate_preference();
400 433
401 434 for(data in cookieadmin_policy){
@@ -461,11 +494,8 @@
461 494 /*if(cookieadmin_policy.layout == "footer"){
462 495
463 496 }*/
464 497
465 - if(cookieadmin_policy.cookieadmin_modal == "side"){
466 - document.getElementsByClassName("cookieadmin_modal_footer")[0].style.flexDirection = "column";
467 - }
468 498
469 499 // Remove modal close Button
470 500 if(cookieadmin_policy.cookieadmin_layout == "popup"){
471 501 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
@@ -470,8 +500,19 @@
470 500 if(cookieadmin_policy.cookieadmin_layout == "popup"){
471 501 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
472 502 }
473 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 +
474 515 //show preference modal
475 516 cookieadmin_show_modal_elemnts = document.querySelectorAll(".cookieadmin_re_consent, .cookieadmin_customize_btn");
476 517 cookieadmin_show_modal_elemnts.forEach(function(e){
477 518
@@ -485,20 +526,24 @@
485 526 });*/
486 527
487 528 cookieadmin_toggle_overlay();
488 529 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "flex";
489 - document.getElementsByClassName("cookieadmin_re_consent")[0].style.display = "none";
490 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "none";
530 + var cookieadmin_re_consent = document.getElementsByClassName("cookieadmin_re_consent")[0];
531 + if(cookieadmin_re_consent){
532 + cookieadmin_re_consent.style.display = "none";
533 + }
534 +
535 + var cookieadmin_law_container = document.getElementsByClassName("cookieadmin_law_container")[0];
536 + if(cookieadmin_law_container){
537 + cookieadmin_law_container.style.display = "none";
538 + }
491 539
492 540 if(cookieadmin_policy["cookieadmin_modal"] == "side"){
493 541 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "grid";
494 542 }
495 543
496 - if(e.target.className == "cookieadmin_re_consent"){
497 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_re_consent";
498 - }else{
499 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_law_container";
500 - }
544 + // Remember what opened the modal so focus can go back to it on close
545 + cookieadmin_modal_opener = e.currentTarget;
501 546 });
502 547 });
503 548
504 549 //Save preference
@@ -517,18 +562,35 @@
517 562 }
518 563 });
519 564
520 565 if(Object.keys(prefer).length !== 0){
521 - if(Object.keys(prefer).length === 3){
522 - document.querySelectorAll(".cookieadmin_accept_btn")[1].click();
566 + var override_gpc = document.getElementById('cookieadmin-override_gpc');
567 + var is_override_gpc = false;
568 + if(override_gpc && override_gpc.checked){
569 + is_override_gpc = true;
570 + }
571 +
572 + if(Object.keys(prefer).length === 3 && !is_override_gpc){
573 + let accept_btn = document.querySelectorAll(".cookieadmin_accept_btn");
574 +
575 + if(accept_btn.length > 0){
576 + accept_btn[accept_btn.length-1].click();
577 + }
578 +
523 579 return;
524 580 }
525 581 }else{
526 - document.querySelectorAll(".cookieadmin_reject_btn")[1].click();
582 + let reject_btn = document.querySelectorAll(".cookieadmin_reject_btn");
583 +
584 + if(reject_btn.length > 0){
585 + reject_btn[reject_btn.length-1].click();
586 + }
587 +
527 588 return;
528 589 }
529 590
530 591 cookieadmin_toggle_overlay();
592 + cookieadmin_return_focus();
531 593
532 594 cookieadmin_set_consent(prefer, days);
533 595 });
534 596
@@ -541,36 +603,40 @@
541 603 e.addEventListener("click", function(){
542 604 // console.log(e);
543 605
544 606 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "none";
545 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "none";
546 - if(cookieadmin_show_reconsent){
547 - document.getElementsByClassName("cookieadmin_re_consent")[0].style.display = "block";
607 + var cookieadmin_law_container = document.getElementsByClassName("cookieadmin_law_container")[0];
608 + if(cookieadmin_law_container){
609 + cookieadmin_law_container.style.display = "none";
548 610 }
549 611
612 + var cookieadmin_re_consent = document.getElementsByClassName("cookieadmin_re_consent")[0];
613 + if(cookieadmin_re_consent){
614 + cookieadmin_re_consent.style.display = "block";
615 + }
616 +
550 617 if(e.id.includes("modal")){
551 618 cookieadmin_toggle_overlay();
619 + cookieadmin_return_focus();
552 620 }
553 621
554 622 var prefer2 = e.classList.contains("cookieadmin_reject_btn") ? {reject: "true"} : {accept: "true"};
555 -
623 +
556 624 cookieadmin_set_consent(prefer2, days);
557 625 });
558 626 });
559 627
560 - document.querySelectorAll(".cookieadmin_show_pref_cookies").forEach(function(e){
628 + document.querySelectorAll(".cookieadmin_header .cookieadmin_show_pref_cookies").forEach(function(e){
561 629 e.addEventListener("click", function(el){
562 630
563 - var tgt = el.target.id;
631 + var tgt = el.currentTarget.id;
564 632 tgt = tgt.replace(/-container$/, "");
565 633
566 - if(el.target.classList.contains("dwn")){
567 - el.target.innerHTML = "&#9658;";
568 - el.target.classList.remove("dwn");
634 + if(el.currentTarget.classList.contains("dwn")){
635 + el.currentTarget.classList.remove("dwn");
569 636 document.querySelector("."+tgt).style.display = "none";
570 637 }else{
571 - el.target.innerHTML = "&#9660;";
572 - el.target.classList.add("dwn");
638 + el.currentTarget.classList.add("dwn");
573 639 document.querySelector("."+tgt).style.display = "block";
574 640 }
575 641 });
576 642 });
@@ -578,12 +644,20 @@
578 644 document.getElementsByClassName("cookieadmin_close_pref")[0].addEventListener("click", function(e){
579 645 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "none";
580 646 cookieadmin_toggle_overlay();
581 647 if(!cookieadmin_is_obj(cookieadmin_is_consent)){
582 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
648 + var cookieadmin_law_container = document.getElementsByClassName("cookieadmin_law_container")[0];
649 + if(cookieadmin_law_container){
650 + cookieadmin_law_container.style.display = "block";
651 + }
583 652 }else if(cookieadmin_show_reconsent){
584 - document.getElementsByClassName("cookieadmin_re_consent")[0].style.display = "block";
653 + var cookieadmin_re_consent = document.getElementsByClassName("cookieadmin_re_consent")[0];
654 + if(cookieadmin_re_consent){
655 + cookieadmin_re_consent.style.display = "block";
656 + }
585 657 }
658 +
659 + cookieadmin_return_focus();
586 660 });
587 661
588 662 });
589 663
@@ -615,8 +689,12 @@
615 689 cookieadmin_set_cookie('cookieadmin_consent', cookieadmin_consent, days);
616 690
617 691 if (typeof cookieadmin_update_gcm === "function") {
618 692 cookieadmin_update_gcm(1);
693 + }
694 +
695 + if (typeof cookieadmin_pro_update_clarity_cookie === "function") {
696 + cookieadmin_pro_update_clarity_cookie();
619 697 }
620 698
621 699 if(!!cookieadmin_policy.reload_on_consent){
622 700 location.reload();