| @@ -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 | } |
| @@ -266,9 +284,10 @@ | ||
| 266 | 284 | |
| 267 | 285 | if(!card_container){ |
| 268 | 286 | continue; |
| 269 | 287 | } |
| 270 | - card_container.innerHTML = (card_container.innerHTML == 'None') ? '' : card_container.innerHTML; | |
| 288 | + | |
| 289 | + card_container.querySelector(".cookieadmin-nocookie-cat").style.display = 'none'; | |
| 271 | 290 | |
| 272 | 291 | var cookieadmin_exp = cookieadmin_policy.lang.session; |
| 273 | 292 | |
| 274 | 293 | if( |
| @@ -354,9 +373,9 @@ | ||
| 354 | 373 | |
| 355 | 374 | document.addEventListener("DOMContentLoaded", function() { |
| 356 | 375 | |
| 357 | 376 | var cookieadmin_show_reconsent = 0; |
| 358 | - if(cookieadmin_policy.is_pro != 0 && cookieadmin_pro_vars.reconsent != 0){ | |
| 377 | + if(cookieadmin_policy.is_pro != 0 && cookieadmin_pro_vars !== 'undefined' && cookieadmin_pro_vars.reconsent != 0){ | |
| 359 | 378 | var cookieadmin_show_reconsent = 1; |
| 360 | 379 | } |
| 361 | 380 | |
| 362 | 381 | //Create overlay |
| @@ -363,13 +382,23 @@ | ||
| 363 | 382 | var cookieadmin_ovrlay = document.createElement("div"); |
| 364 | 383 | cookieadmin_ovrlay.className = "cookieadmin_modal_overlay"; |
| 365 | 384 | document.body.appendChild(cookieadmin_ovrlay); |
| 366 | 385 | |
| 386 | + var before_consent_dispaly = new CustomEvent('cookieadmin_before_consent_display'); | |
| 387 | + | |
| 388 | + // For anything that needs to be done before disaplying consent. | |
| 389 | + cookieadmin_policy.hide_banner = false; // initializing | |
| 390 | + window.dispatchEvent(before_consent_dispaly); | |
| 391 | + | |
| 367 | 392 | //Show notice or re-consent icon as needed |
| 368 | - if(!cookieadmin_is_obj(cookieadmin_is_consent)){ | |
| 393 | + if(!cookieadmin_is_obj(cookieadmin_is_consent) && !cookieadmin_policy.hide_banner){ | |
| 369 | 394 | |
| 370 | 395 | if(cookieadmin_policy.cookieadmin_layout !== "popup"){ |
| 371 | - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block"; | |
| 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 | + } | |
| 372 | 401 | }else{ |
| 373 | 402 | cookieadmin_toggle_overlay(); |
| 374 | 403 | document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "flex"; |
| 375 | 404 | } |
| @@ -393,9 +422,8 @@ | ||
| 393 | 422 | |
| 394 | 423 | } |
| 395 | 424 | |
| 396 | 425 | //Edit Notice and Modal contents |
| 397 | - document.getElementsByClassName("cookieadmin_reconsent_img")[0].src = cookieadmin_policy.plugin_url + "/assets/images/cookieadmin_icon.svg"; | |
| 398 | 426 | |
| 399 | 427 | cookieadmin_populate_preference(); |
| 400 | 428 | |
| 401 | 429 | for(data in cookieadmin_policy){ |
| @@ -470,8 +498,10 @@ | ||
| 470 | 498 | if(cookieadmin_policy.cookieadmin_layout == "popup"){ |
| 471 | 499 | document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none"; |
| 472 | 500 | } |
| 473 | 501 | |
| 502 | + var cookieadmin_modal_el = document.getElementsByClassName("cookieadmin_cookie_modal")[0]; | |
| 503 | + | |
| 474 | 504 | //show preference modal |
| 475 | 505 | cookieadmin_show_modal_elemnts = document.querySelectorAll(".cookieadmin_re_consent, .cookieadmin_customize_btn"); |
| 476 | 506 | cookieadmin_show_modal_elemnts.forEach(function(e){ |
| 477 | 507 | |
| @@ -485,10 +515,17 @@ | ||
| 485 | 515 | });*/ |
| 486 | 516 | |
| 487 | 517 | cookieadmin_toggle_overlay(); |
| 488 | 518 | 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"; | |
| 519 | + var cookieadmin_re_consent = document.getElementsByClassName("cookieadmin_re_consent")[0]; | |
| 520 | + if(cookieadmin_re_consent){ | |
| 521 | + cookieadmin_re_consent.style.display = "none"; | |
| 522 | + } | |
| 523 | + | |
| 524 | + var cookieadmin_law_container = document.getElementsByClassName("cookieadmin_law_container")[0]; | |
| 525 | + if(cookieadmin_law_container){ | |
| 526 | + cookieadmin_law_container.style.display = "none"; | |
| 527 | + } | |
| 491 | 528 | |
| 492 | 529 | if(cookieadmin_policy["cookieadmin_modal"] == "side"){ |
| 493 | 530 | document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "grid"; |
| 494 | 531 | } |
| @@ -497,8 +534,10 @@ | ||
| 497 | 534 | document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_re_consent"; |
| 498 | 535 | }else{ |
| 499 | 536 | document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_law_container"; |
| 500 | 537 | } |
| 538 | + | |
| 539 | + cookieadmin_modal_el.focus(); | |
| 501 | 540 | }); |
| 502 | 541 | }); |
| 503 | 542 | |
| 504 | 543 | //Save preference |
| @@ -517,14 +556,30 @@ | ||
| 517 | 556 | } |
| 518 | 557 | }); |
| 519 | 558 | |
| 520 | 559 | if(Object.keys(prefer).length !== 0){ |
| 521 | - if(Object.keys(prefer).length === 3){ | |
| 522 | - document.querySelectorAll(".cookieadmin_accept_btn")[1].click(); | |
| 560 | + var override_gpc = document.getElementById('cookieadmin-override_gpc'); | |
| 561 | + var is_override_gpc = false; | |
| 562 | + if(override_gpc && override_gpc.checked){ | |
| 563 | + is_override_gpc = true; | |
| 564 | + } | |
| 565 | + | |
| 566 | + if(Object.keys(prefer).length === 3 && !is_override_gpc){ | |
| 567 | + let accept_btn = document.querySelectorAll(".cookieadmin_accept_btn"); | |
| 568 | + | |
| 569 | + if(accept_btn.length > 0){ | |
| 570 | + accept_btn[accept_btn.length-1].click(); | |
| 571 | + } | |
| 572 | + | |
| 523 | 573 | return; |
| 524 | 574 | } |
| 525 | 575 | }else{ |
| 526 | - document.querySelectorAll(".cookieadmin_reject_btn")[1].click(); | |
| 576 | + let reject_btn = document.querySelectorAll(".cookieadmin_reject_btn"); | |
| 577 | + | |
| 578 | + if(reject_btn.length > 0){ | |
| 579 | + reject_btn[reject_btn.length-1].click(); | |
| 580 | + } | |
| 581 | + | |
| 527 | 582 | return; |
| 528 | 583 | } |
| 529 | 584 | |
| 530 | 585 | cookieadmin_toggle_overlay(); |
| @@ -541,39 +596,56 @@ | ||
| 541 | 596 | e.addEventListener("click", function(){ |
| 542 | 597 | // console.log(e); |
| 543 | 598 | |
| 544 | 599 | 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"; | |
| 600 | + var cookieadmin_law_container = document.getElementsByClassName("cookieadmin_law_container")[0]; | |
| 601 | + if(cookieadmin_law_container){ | |
| 602 | + cookieadmin_law_container.style.display = "none"; | |
| 548 | 603 | } |
| 549 | 604 | |
| 605 | + var cookieadmin_re_consent = document.getElementsByClassName("cookieadmin_re_consent")[0]; | |
| 606 | + if(cookieadmin_re_consent){ | |
| 607 | + cookieadmin_re_consent.style.display = "block"; | |
| 608 | + } | |
| 609 | + | |
| 550 | 610 | if(e.id.includes("modal")){ |
| 551 | 611 | cookieadmin_toggle_overlay(); |
| 552 | 612 | } |
| 553 | 613 | |
| 554 | 614 | var prefer2 = e.classList.contains("cookieadmin_reject_btn") ? {reject: "true"} : {accept: "true"}; |
| 555 | - | |
| 615 | + | |
| 556 | 616 | cookieadmin_set_consent(prefer2, days); |
| 557 | 617 | }); |
| 558 | 618 | }); |
| 559 | 619 | |
| 560 | - document.querySelectorAll(".cookieadmin_show_pref_cookies").forEach(function(e){ | |
| 561 | - e.addEventListener("click", function(el){ | |
| 562 | - | |
| 563 | - var tgt = el.target.id; | |
| 564 | - tgt = tgt.replace(/-container$/, ""); | |
| 565 | - | |
| 566 | - if(el.target.classList.contains("dwn")){ | |
| 567 | - el.target.innerHTML = "►"; | |
| 568 | - el.target.classList.remove("dwn"); | |
| 569 | - document.querySelector("."+tgt).style.display = "none"; | |
| 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 = "►"; // Right arrow | |
| 635 | + trigger.classList.remove("dwn"); | |
| 636 | + trigger.setAttribute("aria-expanded", "false"); | |
| 637 | + targetEl.style.display = "none"; | |
| 570 | 638 | }else{ |
| 571 | - el.target.innerHTML = "▼"; | |
| 572 | - el.target.classList.add("dwn"); | |
| 573 | - document.querySelector("."+tgt).style.display = "block"; | |
| 639 | + trigger.innerHTML = "▼"; // Down arrow | |
| 640 | + trigger.classList.add("dwn"); | |
| 641 | + trigger.setAttribute("aria-expanded", "true"); | |
| 642 | + targetEl.style.display = "block"; | |
| 574 | 643 | } |
| 575 | - }); | |
| 644 | + } | |
| 645 | + | |
| 646 | + // 2. Native buttons fire click on mouse, Enter and Space | |
| 647 | + btn.addEventListener("click", toggleAccordion); | |
| 576 | 648 | }); |
| 577 | 649 | |
| 578 | 650 | document.getElementsByClassName("cookieadmin_close_pref")[0].addEventListener("click", function(e){ |
| 579 | 651 | document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "none"; |
| @@ -578,11 +650,17 @@ | ||
| 578 | 650 | document.getElementsByClassName("cookieadmin_close_pref")[0].addEventListener("click", function(e){ |
| 579 | 651 | document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "none"; |
| 580 | 652 | cookieadmin_toggle_overlay(); |
| 581 | 653 | if(!cookieadmin_is_obj(cookieadmin_is_consent)){ |
| 582 | - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block"; | |
| 654 | + var cookieadmin_law_container = document.getElementsByClassName("cookieadmin_law_container")[0]; | |
| 655 | + if(cookieadmin_law_container){ | |
| 656 | + cookieadmin_law_container.style.display = "block"; | |
| 657 | + } | |
| 583 | 658 | }else if(cookieadmin_show_reconsent){ |
| 584 | - document.getElementsByClassName("cookieadmin_re_consent")[0].style.display = "block"; | |
| 659 | + var cookieadmin_re_consent = document.getElementsByClassName("cookieadmin_re_consent")[0]; | |
| 660 | + if(cookieadmin_re_consent){ | |
| 661 | + cookieadmin_re_consent.style.display = "block"; | |
| 662 | + } | |
| 585 | 663 | } |
| 586 | 664 | }); |
| 587 | 665 | |
| 588 | 666 | }); |
| @@ -615,8 +693,12 @@ | ||
| 615 | 693 | cookieadmin_set_cookie('cookieadmin_consent', cookieadmin_consent, days); |
| 616 | 694 | |
| 617 | 695 | if (typeof cookieadmin_update_gcm === "function") { |
| 618 | 696 | cookieadmin_update_gcm(1); |
| 697 | + } | |
| 698 | + | |
| 699 | + if (typeof cookieadmin_pro_update_clarity_cookie === "function") { | |
| 700 | + cookieadmin_pro_update_clarity_cookie(); | |
| 619 | 701 | } |
| 620 | 702 | |
| 621 | 703 | if(!!cookieadmin_policy.reload_on_consent){ |
| 622 | 704 | location.reload(); |