PluginProbe
CookieAdmin – Cookie Consent Banner / trunk
CookieAdmin – Cookie Consent Banner vtrunk
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 +258 -138 1.0.4 → trunk View file →
@@ -1,10 +1,7 @@
1 -const days = cookieadmin_policy.cookieadmin_days;
1 +// This file handle the cookie banner and stuff related to that.
2 2
3 -var cookieadmin_show_reconsent = 0;
4 -if(cookieadmin_policy.is_pro != 0){
5 - var cookieadmin_show_reconsent = 1;
6 -}
3 +var days = cookieadmin_policy.cookieadmin_days;
7 4
8 5 if(typeof cookieadmin_is_consent === 'undefined'){
9 6 window.cookieadmin_is_consent = {};
10 7 }
@@ -11,15 +8,24 @@
11 8 var cookieadmin_allcookies = cookieadmin_policy.categorized_cookies;
12 9 //setInterval(cookieadmin_categorize_cookies, 5000);
13 10
14 11 function cookieadmin_is_obj(consentObj){
15 - return (Object.keys(consentObj).length !== 0);
12 + try{
13 + return (
14 + consentObj !== null &&
15 + typeof consentObj === 'object' &&
16 + !Array.isArray(consentObj) &&
17 + Object.keys(consentObj).length > 0
18 + );
19 + }catch(e){
20 + return false;
21 + }
16 22 }
17 23
18 24
19 25 // function cookieadmin_cookie_interceptor(){
20 -
21 - const originalCookieDescriptor =
26 +
27 + var originalCookieDescriptor =
22 28 Object.getOwnPropertyDescriptor(Document.prototype, 'cookie') ||
23 29 Object.getOwnPropertyDescriptor(document, 'cookie');
24 30 var allowed_cookies = '';
25 31
@@ -30,48 +36,62 @@
30 36 get: function(){
31 37 return originalCookieDescriptor.get.call(document);
32 38 },
33 39 set: function(val){
40 +
41 + if (!val) return;
42 +
43 + var separatorIndex = val.indexOf('=');
44 + if(separatorIndex === -1) {
45 + return;
46 + }
34 47
35 - val_name = val.split("=")[0].trim();
36 - rm_val = val_name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
48 + var cookieName = val.substring(0, separatorIndex).trim();
49 + var cookieValue = val.substring(separatorIndex + 1).trim();
50 +
51 + if(cookieName === "cookieadmin_consent"){
52 + originalCookieDescriptor.set.call(document, val);
53 + return;
54 + }
37 55
38 - if(val_name === "cookieadmin_consent"){
39 - return originalCookieDescriptor.set.call(document, val);
56 + // Set cookies which are meant to be deleted
57 + if(val.includes('expires=Thu, 01 Jan 1970') || cookieValue.startsWith("deleted;")){
58 + originalCookieDescriptor.set.call(document, val);
59 + return;
40 60 }
61 +
62 + var cookieInfo = cookieadmin_allcookies[cookieName] || {};
63 + var category = (cookieInfo.category || 'uncategorized').toLowerCase();
41 64
42 - if(cookieadmin_is_obj(cookieadmin_is_consent) && (val_name in cookieadmin_allcookies) ){
65 + // Set necessary cookies
66 + if(category == "necessary"){
67 + originalCookieDescriptor.set.call(document, val);
68 + return;
69 + }
70 +
71 + if(cookieadmin_is_obj(cookieadmin_is_consent) || (Array.isArray(cookieadmin_policy['preload']) && cookieadmin_policy['preload'].length > 0)){
72 +
73 + var consentAction = cookieadmin_is_consent.action;
43 74
44 - switch(cookieadmin_is_consent.action){
75 + if(!consentAction){
76 + consentAction = cookieadmin_policy['preload'].reduce((a, val) => {a[val] = ''; return a;}, {});
77 + }
78 +
79 + if(consentAction.accept || consentAction[category]){
80 + originalCookieDescriptor.set.call(document, val);
81 + }else{
45 82
46 - case "reject":
47 - if(cookieadmin_allcookies[val_name].sync){
48 - cookieadmin_allcookies[val_name].sync = false;
49 - return originalCookieDescriptor.set.call(document, rm_val);
50 - }
51 - return true;
52 -
53 - case "accept":
54 - if(!cookieadmin_allcookies[val_name].sync){
55 - cookieadmin_allcookies[val_name].sync = true;
56 - return originalCookieDescriptor.set.call(document, val);
57 - }
58 - return true;
59 -
60 - default:
61 - if(cookieadmin_is_consent.action[cookieadmin_allcookies[val_name].category] && !cookieadmin_allcookies[val_name].sync){
62 - cookieadmin_allcookies[val_name].sync = true;
63 - return originalCookieDescriptor.set.call(document, val);
64 - }
65 - else if(!(cookieadmin_is_consent.action[cookieadmin_allcookies[val_name].category]) && cookieadmin_allcookies[val_name].sync){
66 - cookieadmin_allcookies[val_name].sync = false;
67 - return originalCookieDescriptor.set.call(document, rm_val);
68 - }
69 - return true;
70 - }
83 + var pathMatch = val.match(/path=([^;]+)/i);
84 + var domainMatch = val.match(/domain=([^;]+)/i);
85 + var path = pathMatch ? pathMatch[1].trim() : '/';
86 + var domain = domainMatch ? `domain=${domainMatch[1].trim()};` : '';
87 +
88 + var deleteString = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; ${domain}`;
89 + originalCookieDescriptor.set.call(document, deleteString.trim());
90 + }
71 91
72 92 }else{
73 - (cookieadmin_allcookies[val_name] = cookieadmin_allcookies[val_name] || {}).string = val.trim();
93 + (cookieadmin_allcookies[cookieName] = cookieadmin_allcookies[cookieName] || {}).string = val.trim();
74 94 return false;
75 95 }
76 96
77 97 }
@@ -83,18 +103,28 @@
83 103 function cookieadmin_is_cookie(name){
84 104
85 105 if(!document.cookie) return false;
86 106
87 - let coki = document.cookie.split(";") ;
107 + var coki = document.cookie.split(";") ;
88 108
89 109 if(name == "all"){
90 110 return coki ? coki : [];
91 111 }
92 - let nam = name + "=";
112 + var nam = name + "=";
93 113
94 - for(let i=0; i < coki.length; i++){
114 + for(var i=0; i < coki.length; i++){
95 115 if(coki[i].trim().indexOf(nam) == 0){
96 - 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 + }
97 127 }
98 128 }
99 129
100 130 return false;
@@ -100,15 +130,15 @@
100 130 return false;
101 131 }
102 132
103 133 function cookieadmin_check_consent(){
104 -
105 - if(cookieadmin_cookie = cookieadmin_is_cookie("cookieadmin_consent")){
106 - cookieadmin_cookie = JSON.parse(cookieadmin_cookie.split("=")[1]);
134 + var cookieadmin_cookie = cookieadmin_is_cookie("cookieadmin_consent");
135 + if(!!cookieadmin_cookie){
107 136 if(!!cookieadmin_cookie.consent){
108 137 cookieadmin_is_consent.consent = cookieadmin_cookie.consent;
109 138 delete cookieadmin_cookie.consent;
110 139 }
140 +
111 141 cookieadmin_is_consent.action = cookieadmin_cookie;
112 142 }
113 143 }
114 144 cookieadmin_check_consent();
@@ -129,9 +159,9 @@
129 159
130 160 }else if(update.reject && update.reject == "true"){
131 161 return true;
132 162 }else{
133 - for (const [key, value] of Object.entries(update)) {
163 + for (var [key, value] of Object.entries(update)) {
134 164 if(key != "consent"){
135 165 cookieadmin_accepted_categories.push(key);
136 166 }
137 167 }
@@ -136,14 +166,19 @@
136 166 }
137 167 }
138 168 }
139 169
170 +
171 + for(cookie in cookieadmin_allcookies){
172 + document.cookie = cookieadmin_allcookies[cookie].string;
173 + };
174 +
140 175 cookieadmin_accepted_categories.forEach(function(category) {
141 176
142 177 document.querySelectorAll(
143 178 'script[type="text/plain"][data-cookieadmin-category="' + category + '"]'
144 179 ).forEach(function(el) {
145 - const newScript = document.createElement('script');
180 + var newScript = document.createElement('script');
146 181
147 182 // Copy attributes
148 183 if (el.src) {
149 184 newScript.src = el.src;
@@ -165,19 +200,30 @@
165 200 });
166 201 });
167 202 }
168 203
169 -function cookieadmin_set_cookie(name, value, days = 365, domain = "", path = cookieadmin_get_base_path()) {
204 +function cookieadmin_set_cookie(name, value, days = 365, domain = "") {
170 205 if (!name || !value) return false;
171 206
172 - const date = new Date();
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 +
216 + var date = new Date();
173 217 date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); // default 1 year
174 218
175 - let cookieString = `${encodeURIComponent(name)}=${JSON.stringify(value)};`;
219 + var cookieString = `${encodeURIComponent(name)}=${JSON.stringify(value)};`;
176 220 cookieString += ` expires=${date.toUTCString()};`;
177 - cookieString += ` path=${path};`;
221 + cookieString += ` path=${!domain ? cookieadmin_policy.base_path : '/'};`;
178 222 cookieString += ` SameSite=Lax;`;
179 - cookieString += ` Secure;`; // Only sent over HTTPS
223 + if(cookieadmin_policy.is_ssl || window.location.protocol === 'https:'){
224 + cookieString += ` Secure;`;
225 + }
180 226
181 227 // Add domain if explicitly passed
182 228 if (domain) {
183 229 cookieString += ` domain=${domain};`;
@@ -186,9 +232,14 @@
186 232 document.cookie = cookieString;
187 233 return true;
188 234 }
189 235
190 -//Populates modal with consent if selected
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 +
191 242 function cookieadmin_populate_preference(){
192 243
193 244 consent = cookieadmin_is_consent.action;
194 245
@@ -210,34 +261,62 @@
210 261 btn_ele.checked = true;
211 262 }
212 263 }
213 264 }
265 + //Load as per preloaded categories selected by admin
266 + }else if(cookieadmin_policy['preload'] && cookieadmin_policy['preload'].length > 0){
267 +
268 + cookieadmin_policy['preload'].forEach(function(val){
269 + if(btn_ele = document.querySelector("#cookieadmin-" + val)){
270 + btn_ele.checked = true;
271 + }
272 + });
214 273 }
215 274
216 - cookieadmin_shown = (typeof cookieadmin_shown !== "undefined") ? cookieadmin_shown : [];
275 + var cookieadmin_shown = (typeof cookieadmin_shown !== "undefined") ? cookieadmin_shown : [];
217 276
218 277 if(cookieadmin_allcookies){
219 278
220 - cookieadmin_filtrd = Object.keys(cookieadmin_allcookies).filter(e => !cookieadmin_shown.includes(e));
279 + var cookieadmin_filtrd = Object.keys(cookieadmin_allcookies).filter(e => !cookieadmin_shown.includes(e));
221 280
222 281 for(c_info of cookieadmin_filtrd){
223 282
224 - if(e = document.querySelector(".cookieadmin-" + cookieadmin_allcookies[c_info].category?.toLowerCase())){
225 - e.innerHTML = (e.innerHTML == 'None') ? '' : e.innerHTML;
283 + var category_var = cookieadmin_allcookies[c_info].category;
284 +
285 + if(!category_var){
286 + continue;
287 + }
288 + var card_container = document.querySelector(".cookieadmin-" + category_var.toLowerCase());
289 +
290 + if(!card_container){
291 + continue;
292 + }
293 +
294 + card_container.querySelector(".cookieadmin-nocookie-cat").style.display = 'none';
295 +
296 + var cookieadmin_exp = cookieadmin_policy.lang.session;
226 297
227 - exp = 'Session';
228 -
229 - if(!!cookieadmin_allcookies[c_info].expires){
230 - exp = Math.round((cookieadmin_allcookies[c_info].expires - Date.now())/86400);
231 - if(exp < 1 && !!res['Max-Age']){
232 - exp = res['Max-Age'];
233 - }else{
234 - exp = 'Session';
298 + if(
299 + !!cookieadmin_allcookies[c_info].expires
300 + && cookieadmin_allcookies[c_info].expires !== "0000-00-00 00:00:00"
301 + ){
302 +
303 + var expDate = new Date(cookieadmin_allcookies[c_info].expires.replace(' ', 'T'));
304 +
305 + if (!isNaN(expDate.getTime())) {
306 + var daysLeft = Math.ceil((expDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24));
307 +
308 + if (daysLeft > 0) {
309 + cookieadmin_exp = daysLeft +' '+ cookieadmin_policy.lang.days;
235 310 }
236 311 }
237 -
238 - e.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>Duration:</b> '+ 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>';
239 312 }
313 +
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>');
240 319 cookieadmin_shown.push(c_info);
241 320 }
242 321 }
243 322
@@ -273,9 +352,9 @@
273 352 if(!cookieadmin_is_obj(cookieadmin_chk_cookies)){
274 353 return;
275 354 }
276 355
277 - /* const xhttp2 = new XMLHttpRequest();
356 + /* var xhttp2 = new XMLHttpRequest();
278 357
279 358 var data = 'action=cookieadmin_ajax_handler&cookieadmin_act=categorize_cookies&cookieadmin_security=' + cookieadmin_policy.nonce + "&cookieadmin_cookies=" + JSON.stringify(cookieadmin_chk_cookies);
280 359
281 360 xhttp2.onload = function() {
@@ -301,8 +380,13 @@
301 380 }
302 381
303 382
304 383 document.addEventListener("DOMContentLoaded", function() {
384 +
385 + var cookieadmin_show_reconsent = 0;
386 + if(cookieadmin_policy.is_pro != 0 && cookieadmin_pro_vars !== 'undefined' && cookieadmin_pro_vars.reconsent != 0){
387 + var cookieadmin_show_reconsent = 1;
388 + }
305 389
306 390 //Create overlay
307 391 var cookieadmin_ovrlay = document.createElement("div");
308 392 cookieadmin_ovrlay.className = "cookieadmin_modal_overlay";
@@ -307,13 +391,19 @@
307 391 var cookieadmin_ovrlay = document.createElement("div");
308 392 cookieadmin_ovrlay.className = "cookieadmin_modal_overlay";
309 393 document.body.appendChild(cookieadmin_ovrlay);
310 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 +
311 401 //Show notice or re-consent icon as needed
312 - if(!cookieadmin_is_obj(cookieadmin_is_consent)){
402 + if(!cookieadmin_is_obj(cookieadmin_is_consent) && !cookieadmin_policy.hide_banner){
313 403
314 404 if(cookieadmin_policy.cookieadmin_layout !== "popup"){
315 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
405 + document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "block";
316 406 }else{
317 407 cookieadmin_toggle_overlay();
318 408 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "flex";
319 409 }
@@ -337,9 +427,8 @@
337 427
338 428 }
339 429
340 430 //Edit Notice and Modal contents
341 - document.getElementsByClassName("cookieadmin_reconsent_img")[0].src = cookieadmin_policy.plugin_url + "/assets/images/cookieadmin_icon.svg";
342 431
343 432 cookieadmin_populate_preference();
344 433
345 434 for(data in cookieadmin_policy){
@@ -384,9 +473,9 @@
384 473 }
385 474 }
386 475
387 476 //Add layout as class
388 - if(!!cookieadmin_policy.cookieadmin_position){
477 + if(!!cookieadmin_policy.cookieadmin_position && cookieadmin_policy.cookieadmin_layout !== "popup"){
389 478 cookieadmin_policy.cookieadmin_position.split("_").forEach(function(clas){
390 479 clas = "cookieadmin_" + clas;
391 480 document.getElementsByClassName("cookieadmin_law_container")[0].classList.add(clas);
392 481 });
@@ -392,9 +481,13 @@
392 481 });
393 482 }
394 483
395 484 // Change consent layout dynamically
396 - document.getElementsByClassName("cookieadmin_law_container")[0].classList.add("cookieadmin_" + cookieadmin_policy.cookieadmin_layout);
485 + // TODO: There is a operator called optional chaining operator ?. something like this users?.[0]?.name; wont use it now just for reference
486 + var cookieadmin_law_container_var = document.getElementsByClassName("cookieadmin_law_container")[0];
487 + if (!!cookieadmin_law_container_var){
488 + cookieadmin_law_container_var.classList.add("cookieadmin_" + cookieadmin_policy.cookieadmin_layout);
489 + }
397 490
398 491 // Change Modal layout dynamically
399 492 document.getElementsByClassName("cookieadmin_cookie_modal")[0].classList.add("cookieadmin_" + cookieadmin_policy.cookieadmin_modal);
400 493
@@ -401,11 +494,8 @@
401 494 /*if(cookieadmin_policy.layout == "footer"){
402 495
403 496 }*/
404 497
405 - if(cookieadmin_policy.cookieadmin_modal == "side"){
406 - document.getElementsByClassName("cookieadmin_footer")[0].style.flexDirection = "column";
407 - }
408 498
409 499 // Remove modal close Button
410 500 if(cookieadmin_policy.cookieadmin_layout == "popup"){
411 501 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
@@ -410,8 +500,19 @@
410 500 if(cookieadmin_policy.cookieadmin_layout == "popup"){
411 501 document.getElementsByClassName("cookieadmin_close_pref")[0].style.display = "none";
412 502 }
413 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 +
414 515 //show preference modal
415 516 cookieadmin_show_modal_elemnts = document.querySelectorAll(".cookieadmin_re_consent, .cookieadmin_customize_btn");
416 517 cookieadmin_show_modal_elemnts.forEach(function(e){
417 518
@@ -425,20 +526,24 @@
425 526 });*/
426 527
427 528 cookieadmin_toggle_overlay();
428 529 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "flex";
429 - document.getElementsByClassName("cookieadmin_re_consent")[0].style.display = "none";
430 - 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 + }
431 539
432 540 if(cookieadmin_policy["cookieadmin_modal"] == "side"){
433 541 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "grid";
434 542 }
435 543
436 - if(e.target.className == "cookieadmin_re_consent"){
437 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_re_consent";
438 - }else{
439 - document.getElementsByClassName("cookieadmin_close_pref")[0].id = "cookieadmin_law_container";
440 - }
544 + // Remember what opened the modal so focus can go back to it on close
545 + cookieadmin_modal_opener = e.currentTarget;
441 546 });
442 547 });
443 548
444 549 //Save preference
@@ -457,26 +562,37 @@
457 562 }
458 563 });
459 564
460 565 if(Object.keys(prefer).length !== 0){
461 - if(Object.keys(prefer).length === 3){
462 - 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 +
463 579 return;
464 580 }
465 581 }else{
466 - 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 +
467 588 return;
468 589 }
469 590
470 591 cookieadmin_toggle_overlay();
592 + cookieadmin_return_focus();
471 593
472 594 cookieadmin_set_consent(prefer, days);
473 -
474 - if(!!cookieadmin_policy.reload_on_consent){
475 - location.reload();
476 - }else{
477 - cookieadmin_restore_cookies(prefer);
478 - }
479 595 });
480 596
481 597
482 598 //Accept or reject all cookies
@@ -487,54 +603,40 @@
487 603 e.addEventListener("click", function(){
488 604 // console.log(e);
489 605
490 606 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "none";
491 - document.getElementsByClassName("cookieadmin_law_container")[0].style.display = "none";
492 - if(cookieadmin_show_reconsent){
493 - 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";
494 610 }
495 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 +
496 617 if(e.id.includes("modal")){
497 618 cookieadmin_toggle_overlay();
619 + cookieadmin_return_focus();
498 620 }
499 621
500 622 var prefer2 = e.classList.contains("cookieadmin_reject_btn") ? {reject: "true"} : {accept: "true"};
501 -
623 +
502 624 cookieadmin_set_consent(prefer2, days);
503 -
504 - if(!!cookieadmin_policy.reload_on_consent){
505 - location.reload();
506 - }else{
507 - cookieadmin_restore_cookies(prefer2);
508 - }
509 625 });
510 626 });
511 627
512 - //showmore modal btn
513 - document.getElementsByClassName("cookieadmin_showmore")[0]?.addEventListener("click", function(){
514 - if(this.innerHTML.includes("more")){
515 - document.getElementsByClassName("cookieadmin_preference")[0].style.height = "auto";
516 - this.innerHTML = "show less";
517 - }else{
518 - document.getElementsByClassName("cookieadmin_preference")[0].style.height = "";
519 - this.innerHTML = "show more";
520 - }
521 - });
522 -
523 -
524 - document.querySelectorAll(".show_pref_cookies").forEach(function(e){
628 + document.querySelectorAll(".cookieadmin_header .cookieadmin_show_pref_cookies").forEach(function(e){
525 629 e.addEventListener("click", function(el){
526 630
527 - var tgt = el.target.id;
631 + var tgt = el.currentTarget.id;
528 632 tgt = tgt.replace(/-container$/, "");
529 633
530 - if(el.target.classList.contains("dwn")){
531 - el.target.innerHTML = "&#9658;";
532 - el.target.classList.remove("dwn");
634 + if(el.currentTarget.classList.contains("dwn")){
635 + el.currentTarget.classList.remove("dwn");
533 636 document.querySelector("."+tgt).style.display = "none";
534 637 }else{
535 - el.target.innerHTML = "&#9660;";
536 - el.target.classList.add("dwn");
638 + el.currentTarget.classList.add("dwn");
537 639 document.querySelector("."+tgt).style.display = "block";
538 640 }
539 641 });
540 642 });
@@ -542,12 +644,20 @@
542 644 document.getElementsByClassName("cookieadmin_close_pref")[0].addEventListener("click", function(e){
543 645 document.getElementsByClassName("cookieadmin_cookie_modal")[0].style.display = "none";
544 646 cookieadmin_toggle_overlay();
545 647 if(!cookieadmin_is_obj(cookieadmin_is_consent)){
546 - document.getElementsByClassName(e.target.id)[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 + }
547 652 }else if(cookieadmin_show_reconsent){
548 - 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 + }
549 657 }
658 +
659 + cookieadmin_return_focus();
550 660 });
551 661
552 662 });
553 663
@@ -552,17 +662,22 @@
552 662 });
553 663
554 664 function cookieadmin_set_consent(prefrenc, days){
555 665
666 + if (typeof cookieadmin_pro_set_consent === "function") {
667 + return cookieadmin_pro_set_consent(prefrenc, days);
668 + }else{
669 + return cookieadmin_save_consent_cookie(prefrenc, days);
670 + }
671 +}
672 +
673 +function cookieadmin_save_consent_cookie(prefrenc, days, consent_id){
674 +
556 675 var cookieadmin_consent = prefrenc;
557 -
558 - if (typeof cookieadmin_pro_set_consent === "function") {
559 - consent_id = cookieadmin_pro_set_consent(prefrenc, days);
560 676
561 - if(consent_id){
562 - cookieadmin_is_consent.consent = consent_id;
563 - cookieadmin_consent['consent'] = consent_id;
564 - }
677 + if(consent_id){
678 + cookieadmin_is_consent.consent = consent_id;
679 + cookieadmin_consent['consent'] = consent_id;
565 680 }
566 681
567 682 if(!cookieadmin_is_consent.consent){
568 683 cookieadmin_is_consent.consent = "";
@@ -572,14 +687,19 @@
572 687 cookieadmin_is_consent.action = prefrenc;
573 688 cookieadmin_populate_preference();
574 689 cookieadmin_set_cookie('cookieadmin_consent', cookieadmin_consent, days);
575 690
576 -}
691 + if (typeof cookieadmin_update_gcm === "function") {
692 + cookieadmin_update_gcm(1);
693 + }
577 694
578 -function cookieadmin_get_base_path() {
695 + if (typeof cookieadmin_pro_update_clarity_cookie === "function") {
696 + cookieadmin_pro_update_clarity_cookie();
697 + }
579 698
580 - if(window.location.pathname.trim() != '/'){
581 - const parts = window.location.pathname.split('/');
582 - return '/' + (parts[1] || '') + '/';
699 + if(!!cookieadmin_policy.reload_on_consent){
700 + location.reload();
701 + }else{
702 + cookieadmin_restore_cookies(prefrenc);
583 703 }
584 - return '/';
585 704 }
705 +