Changeset 3148281
- Timestamp:
- 09/08/2024 09:29:45 PM (19 months ago)
- Location:
- cookielegit
- Files:
-
- 10 edited
- 1 copied
-
tags/1.0.1 (copied) (copied from cookielegit/trunk)
-
tags/1.0.1/CHANGELOG.md (modified) (1 diff)
-
tags/1.0.1/assets/scripts/public.js (modified) (2 diffs)
-
tags/1.0.1/assets/scripts/public/cookielegit.js (modified) (11 diffs)
-
tags/1.0.1/dist/public.js (modified) (1 diff)
-
tags/1.0.1/src/public/class-cookie-legit-notice.php (modified) (2 diffs)
-
trunk/CHANGELOG.md (modified) (1 diff)
-
trunk/assets/scripts/public.js (modified) (2 diffs)
-
trunk/assets/scripts/public/cookielegit.js (modified) (11 diffs)
-
trunk/dist/public.js (modified) (1 diff)
-
trunk/src/public/class-cookie-legit-notice.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cookielegit/tags/1.0.1/CHANGELOG.md
r3148254 r3148281 1 1 # Changelog 2 3 ## [1.0.1](https://github.com/WebdesignSeolab/cookie-legit/compare/v1.0.0...v1.0.1) (2024-09-08) 4 5 6 ### Features 7 8 * load style async ([#9](https://github.com/WebdesignSeolab/cookie-legit/issues/9)) ([f69861b](https://github.com/WebdesignSeolab/cookie-legit/commit/f69861b3ccbd9cafb11d1fe4e78a2241cc52f088)) 2 9 3 10 ## [1.0.0](https://github.com/WebdesignSeolab/cookie-legit/compare/v1.0.1...v1.0.0) (2024-09-08) -
cookielegit/tags/1.0.1/assets/scripts/public.js
r3148248 r3148281 1 1 import CookieLegitNotice from "./public/cookielegit"; 2 2 3 jQuery(function ($) {3 jQuery(function($) { 4 4 5 5 const updateBlocked = function() { 6 6 console.log('should update screens') 7 $("iframe[data-cl-src]").each(function () {7 $("iframe[data-cl-src]").each(function() { 8 8 $(this).attr("src", $(this).attr("data-cl-src")); 9 9 }); 10 10 11 $("script[type=cookielegitblock]").each(function () {11 $("script[type=cookielegitblock]").each(function() { 12 12 $(this).attr("src", $(this).attr("data-cl-src")); 13 13 $(this).attr("type", $(this).attr("data-cl-type")); … … 21 21 userOpt: cl_config.user_opt !== "", 22 22 baseUrl: cl_config.ajax_url, 23 themeUrl: cl_config.themeUrl 23 24 }); 24 25 }); -
cookielegit/tags/1.0.1/assets/scripts/public/cookielegit.js
r3148248 r3148281 18 18 consentMode: false, 19 19 cookieDuration: 182, 20 themeUrl: null 20 21 }; 21 22 … … 36 37 } 37 38 39 buildStyle(cookieNotice) { 40 const tag = document.createElement('link'); 41 tag.href = this.#settings.themeUrl; 42 tag.rel = 'stylesheet'; 43 tag.id = 'cookielegit-css'; 44 45 tag.onload = () => { 46 cookieNotice.style.display = ''; 47 } 48 49 document.head.append(tag); 50 51 } 52 38 53 checkConsentCookies() { 39 54 LegitCookies.list() … … 44 59 this.updateGTMConsent(); 45 60 } 46 if(this.#consentedTo.length > 0) { 61 62 if (this.#consentedTo.length > 0) { 47 63 CookieLegitNotice.#trigger('consent-given'); 48 64 } … … 58 74 this.#notice.id = "cookie-legit-notice-container"; 59 75 this.#notice.innerHTML = notice.html; 76 this.#notice.style.display = 'none'; 77 78 let screen = this.#consentedTo.length === 0 ? "notice" : "toggle-preferences"; 79 this.#notice.classList.add(screen); 80 60 81 this.#target.appendChild(this.#notice); 61 let screen = 62 this.#consentedTo.length === 0 ? "notice" : "toggle-preferences"; 63 this.changeScreen(screen); 82 // this.changeScreen(screen); 64 83 this.setupEvents(); 65 84 … … 67 86 this.setPrefToggles(); 68 87 } 88 89 this.buildStyle(this.#notice); 69 90 } 70 91 … … 166 187 let scriptsWithPlacement = await scriptReq.json(); 167 188 for (const placement in scriptsWithPlacement) { 168 if (Object.hasOwnProperty.call(scriptsWithPlacement, placement)) { 169 const scripts = scriptsWithPlacement[placement]; 170 Object.values(scripts).forEach(script => { 171 if(!this.isJSON(script)) { 172 let tag = this.buildScript(placement, script); 189 if (Object.hasOwnProperty.call(scriptsWithPlacement, placement)) { 190 const scripts = scriptsWithPlacement[placement]; 191 Object.values(scripts).forEach(script => { 192 if (!this.isJSON(script)) { 193 let tag = this.buildScript(placement, script); 194 document.querySelector(placement).append(tag); 195 } else { 196 script = JSON.parse(script); 197 for (const stype in script) { 198 if (Object.hasOwnProperty.call(script, stype)) { 199 const contents = script[stype]; 200 contents.forEach(content => { 201 let tag = this.buildScript(placement, content, stype === 'srcs'); 173 202 document.querySelector(placement).append(tag); 174 } else { 175 script = JSON.parse(script); 176 for (const stype in script) { 177 if (Object.hasOwnProperty.call(script, stype)) { 178 const contents = script[stype]; 179 contents.forEach(content => { 180 let tag = this.buildScript(placement, content, stype === 'srcs'); 181 document.querySelector(placement).append(tag); 182 }) 183 } 184 } 185 } 186 }); 187 } 203 }) 204 } 205 } 206 } 207 }); 208 } 188 209 } 189 210 } … … 196 217 window.dataLayer = window.dataLayer || []; 197 218 window.dataLayer.push({ 198 0: "consent",199 1: "update",200 2: this.getGTMConsentObject()219 0: "consent", 220 1: "update", 221 2: this.getGTMConsentObject() 201 222 }); 202 223 } … … 204 225 getGTMConsentObject() { 205 226 return { 206 ad_storage:207 LegitCookies.find("cl_marketing")?.value === "true"208 ? "granted"209 : "denied",210 ad_user_data:211 LegitCookies.find("cl_marketing")?.value === "true"212 ? "granted"213 : "denied",214 ad_personalization:215 LegitCookies.find("cl_marketing")?.value === "true"216 ? "granted"217 : "denied",218 analytics_storage:219 LegitCookies.find("cl_tracking")?.value === "true"220 ? "granted"221 : "denied",222 security_storage: "granted",223 }227 ad_storage: 228 LegitCookies.find("cl_marketing")?.value === "true" 229 ? "granted" 230 : "denied", 231 ad_user_data: 232 LegitCookies.find("cl_marketing")?.value === "true" 233 ? "granted" 234 : "denied", 235 ad_personalization: 236 LegitCookies.find("cl_marketing")?.value === "true" 237 ? "granted" 238 : "denied", 239 analytics_storage: 240 LegitCookies.find("cl_tracking")?.value === "true" 241 ? "granted" 242 : "denied", 243 security_storage: "granted", 244 } 224 245 } 225 246 … … 227 248 try { 228 249 let json = JSON.parse(objectString) 229 } catch (e) {250 } catch (e) { 230 251 return false; 231 252 } … … 238 259 let tag = document.createElement(tagName); 239 260 240 if (isSrc) {261 if (isSrc) { 241 262 tag.src = scriptContent; 242 263 return tag; … … 263 284 264 285 if (!callbacks) return console.warn(`Cannot trigger ${event} because it does not exist!`); 265 286 266 287 for (let callback of callbacks) { 267 288 callback(); -
cookielegit/tags/1.0.1/dist/public.js
r3148248 r3148281 1 (()=>{"use strict";var e={};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),(()=>{var t;e.g.importScripts&&(t=e.g.location+"");var n=e.g.document;if(!t&&n&&(n.currentScript&&(t=n.currentScript.src),!t)){var s=n.getElementsByTagName("script");if(s.length)for(var i=s.length-1;i>-1&&!t;)t=s[i--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),e.p=t})(),(()=>{class e{static list(){const e=[],t=document.cookie.split("; ");for(let n=0;n<t.length;n++){const s=t[n].split("="),i=s[0];let c=s.length>1?s[1]:null;e.push({name:i,value:c})}return e}static find(e=""){return this.list().find((t=>t.name===e))||null}static create(e,t,n=1,s="/"){const i=new Date,c=new Date(i.getTime()+24*n*60*60*1e3);return document.cookie=`${e}=${t}; expires=${c}; path=${s}`,this}static delete(e){return document.cookie=`${e}=; Max-Age=-99999999;`,this}}class t{#e=null;#t=null;#n=null;#s=[];screens=["notice","preferences","toggle-preferences"];consentCookieName="cl_consent";cookieNames=["cl_consent","cl_essential","cl_tracking","cl_marketing"];defaultSettings={baseUrl:null,userOpt:!1,consentMode:!1,cookieDuration:182 };static#i={"cookie-legit-init":[],"notice-loaded":[],"consent-given":[],"consent-updated":[]};constructor(e,t){return this.#n=Object.assign({},this.defaultSettings,t),this.#e=this.selectTarget(e),this.checkConsentCookies(),this.insertNotice(),this.maybeInjectScripts(),this}checkConsentCookies(){e.list().filter((e=>e.name.startsWith("cl_"))).forEach((e=>this.#s.push(e))),this.#n.consentMode&&this.#s.length>0&&this.updateGTMConsent(),this.#s.length>0&&t.#c("consent-given")}selectTarget(e){return document.querySelector(e)}async insertNotice(){let e=await this.fetchNotice();this.#t=document.createElement("div"),this.#t.id="cookie-legit-notice-container",this.#t.innerHTML=e.html,this.#e.appendChild(this.#t);let t=0===this.#s.length?"notice":"toggle-preferences";this.changeScreen(t),this.setupEvents(),this.#n.userOpt&&this.setPrefToggles()}async fetchNotice(){const e=await fetch(`${this.#n.baseUrl}?action=get_cookie_notice`);return await e.json()}setupEvents(){this.#n.userOpt?(this.#t.querySelector(".cookie-legit-pref-btn").addEventListener("click",(()=>this.toggleUserPreferences())),this.#t.querySelector(".cookie-legit-save-pref-btn").addEventListener("click",(()=>this.savePreferences())),this.#t.querySelector(".cookie-legit-accept-pref-btn").addEventListener("click",(()=>this.acceptAllCookies()))):this.#t.querySelector(".cookie-legit-deny-btn").addEventListener("click",(()=>this.denyAllCookies())),this.#t.querySelector(".cookie-legit-preferences-change").addEventListener("click",(()=>this.updatePreferences())),this.#t.querySelector(".cookie-legit-accept-btn").addEventListener("click",(()=>this.acceptAllCookies()))}toggleUserPreferences(){this.changeScreen("preferences")}acceptAllCookies(){this.changeScreen("toggle-preferences"),this.cookieNames.forEach((t=>{e.create(t,!0,this.#n.cookieDuration)})),this.checkConsentCookies()}savePreferences(){this.changeScreen("toggle-preferences"),this.cookieNames.forEach((t=>{let n=t===this.consentCookieName||this.#t.querySelector(`input[name=${t}]`).checked;e.create(t,n,this.#n.cookieDuration)})),this.checkConsentCookies()}updatePreferences(){let e=this.#n.userOpt?"preferences":"notice";this.changeScreen(e),this.checkConsentCookies(),t.#c("consent-updated")}denyAllCookies(){this.changeScreen("toggle-preferences"),this.cookieNames.forEach((t=>{let n=t===this.consentCookieName;e.create(t,n,this.#n.cookieDuration)})),this.checkConsentCookies()}changeScreen(e){let t=this.screens.filter((t=>t!==e));this.#t.classList.remove(...t),this.#t.classList.add(e)}setPrefToggles(){this.#s.forEach((e=>{let t=this.#t.querySelector(`input[name=${e.name}]`);t&&(t.checked="true"===e.value)}))}async maybeInjectScripts(){if(!this.#n.userOpt||"true"!==e.find(this.consentCookieName))return;let t=await fetch(`${this.#n.baseUrl}?action=get_tracking_scripts`),n=await t.json();for(const e in n)if(Object.hasOwnProperty.call(n,e)){const t=n[e];Object.values(t).forEach((t=>{if(this.isJSON(t)){t=JSON.parse(t);for(const n in t)Object.hasOwnProperty.call(t,n)&&t[n].forEach((t=>{let s=this.buildScript(e,t,"srcs"===n);document.querySelector(e).append(s)}))}else{let n=this.buildScript(e,t);document.querySelector(e).append(n)}}))}}updateGTMConsent(){if("function"==typeof gtag)return gtag("consent","update",this.getGTMConsentObject());window.dataLayer=window.dataLayer||[],window.dataLayer.push({0:"consent",1:"update",2:this.getGTMConsentObject()})}getGTMConsentObject(){return{ad_storage:"true"===e.find("cl_marketing")?.value?"granted":"denied",ad_user_data:"true"===e.find("cl_marketing")?.value?"granted":"denied",ad_personalization:"true"===e.find("cl_marketing")?.value?"granted":"denied",analytics_storage:"true"===e.find("cl_tracking")?.value?"granted":"denied",security_storage:"granted"}}isJSON(e){try{JSON.parse(e)}catch(e){return!1}return!0}buildScript(e,t,n=!1){let s="head"===e?"script":"noscript",i=document.createElement(s);return n?(i.src=t,i):(i.textContent=t,i)}static subscribe(e,t){return this.#i[e]?"function"!=typeof t?console.warn(`Expected callback for ${e} got ${typeof t}`):void this.#i[e].push(t):console.warn(`Cannot subscribe to ${e} because it does not exist!`)}static#c(e){const t=this.#i[e];if(!t)return console.warn(`Cannot trigger ${e} because it does not exist!`);for(let e of t)e()}}jQuery((function(e){t.subscribe("consent-given",(function(){console.log("should update screens"),e("iframe[data-cl-src]").each((function(){e(this).attr("src",e(this).attr("data-cl-src"))})),e("script[type=cookielegitblock]").each((function(){e(this).attr("src",e(this).attr("data-cl-src")),e(this).attr("type",e(this).attr("data-cl-type"))}))})),window.cookieLegitNotice=new t("body",{consentMode:""!==cl_config.consent_mode,userOpt:""!==cl_config.user_opt,baseUrl:cl_config.ajax_url})}))})(),e.p})();1 (()=>{"use strict";var e={};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),(()=>{var t;e.g.importScripts&&(t=e.g.location+"");var n=e.g.document;if(!t&&n&&(n.currentScript&&(t=n.currentScript.src),!t)){var s=n.getElementsByTagName("script");if(s.length)for(var i=s.length-1;i>-1&&!t;)t=s[i--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),e.p=t})(),(()=>{class e{static list(){const e=[],t=document.cookie.split("; ");for(let n=0;n<t.length;n++){const s=t[n].split("="),i=s[0];let c=s.length>1?s[1]:null;e.push({name:i,value:c})}return e}static find(e=""){return this.list().find((t=>t.name===e))||null}static create(e,t,n=1,s="/"){const i=new Date,c=new Date(i.getTime()+24*n*60*60*1e3);return document.cookie=`${e}=${t}; expires=${c}; path=${s}`,this}static delete(e){return document.cookie=`${e}=; Max-Age=-99999999;`,this}}class t{#e=null;#t=null;#n=null;#s=[];screens=["notice","preferences","toggle-preferences"];consentCookieName="cl_consent";cookieNames=["cl_consent","cl_essential","cl_tracking","cl_marketing"];defaultSettings={baseUrl:null,userOpt:!1,consentMode:!1,cookieDuration:182,themeUrl:null};static#i={"cookie-legit-init":[],"notice-loaded":[],"consent-given":[],"consent-updated":[]};constructor(e,t){return this.#n=Object.assign({},this.defaultSettings,t),this.#e=this.selectTarget(e),this.checkConsentCookies(),this.insertNotice(),this.maybeInjectScripts(),this}buildStyle(e){const t=document.createElement("link");t.href=this.#n.themeUrl,t.rel="stylesheet",t.id="cookielegit-css",t.onload=()=>{e.style.display=""},document.head.append(t)}checkConsentCookies(){e.list().filter((e=>e.name.startsWith("cl_"))).forEach((e=>this.#s.push(e))),this.#n.consentMode&&this.#s.length>0&&this.updateGTMConsent(),this.#s.length>0&&t.#c("consent-given")}selectTarget(e){return document.querySelector(e)}async insertNotice(){let e=await this.fetchNotice();this.#t=document.createElement("div"),this.#t.id="cookie-legit-notice-container",this.#t.innerHTML=e.html,this.#t.style.display="none";let t=0===this.#s.length?"notice":"toggle-preferences";this.#t.classList.add(t),this.#e.appendChild(this.#t),this.setupEvents(),this.#n.userOpt&&this.setPrefToggles(),this.buildStyle(this.#t)}async fetchNotice(){const e=await fetch(`${this.#n.baseUrl}?action=get_cookie_notice`);return await e.json()}setupEvents(){this.#n.userOpt?(this.#t.querySelector(".cookie-legit-pref-btn").addEventListener("click",(()=>this.toggleUserPreferences())),this.#t.querySelector(".cookie-legit-save-pref-btn").addEventListener("click",(()=>this.savePreferences())),this.#t.querySelector(".cookie-legit-accept-pref-btn").addEventListener("click",(()=>this.acceptAllCookies()))):this.#t.querySelector(".cookie-legit-deny-btn").addEventListener("click",(()=>this.denyAllCookies())),this.#t.querySelector(".cookie-legit-preferences-change").addEventListener("click",(()=>this.updatePreferences())),this.#t.querySelector(".cookie-legit-accept-btn").addEventListener("click",(()=>this.acceptAllCookies()))}toggleUserPreferences(){this.changeScreen("preferences")}acceptAllCookies(){this.changeScreen("toggle-preferences"),this.cookieNames.forEach((t=>{e.create(t,!0,this.#n.cookieDuration)})),this.checkConsentCookies()}savePreferences(){this.changeScreen("toggle-preferences"),this.cookieNames.forEach((t=>{let n=t===this.consentCookieName||this.#t.querySelector(`input[name=${t}]`).checked;e.create(t,n,this.#n.cookieDuration)})),this.checkConsentCookies()}updatePreferences(){let e=this.#n.userOpt?"preferences":"notice";this.changeScreen(e),this.checkConsentCookies(),t.#c("consent-updated")}denyAllCookies(){this.changeScreen("toggle-preferences"),this.cookieNames.forEach((t=>{let n=t===this.consentCookieName;e.create(t,n,this.#n.cookieDuration)})),this.checkConsentCookies()}changeScreen(e){let t=this.screens.filter((t=>t!==e));this.#t.classList.remove(...t),this.#t.classList.add(e)}setPrefToggles(){this.#s.forEach((e=>{let t=this.#t.querySelector(`input[name=${e.name}]`);t&&(t.checked="true"===e.value)}))}async maybeInjectScripts(){if(!this.#n.userOpt||"true"!==e.find(this.consentCookieName))return;let t=await fetch(`${this.#n.baseUrl}?action=get_tracking_scripts`),n=await t.json();for(const e in n)if(Object.hasOwnProperty.call(n,e)){const t=n[e];Object.values(t).forEach((t=>{if(this.isJSON(t)){t=JSON.parse(t);for(const n in t)Object.hasOwnProperty.call(t,n)&&t[n].forEach((t=>{let s=this.buildScript(e,t,"srcs"===n);document.querySelector(e).append(s)}))}else{let n=this.buildScript(e,t);document.querySelector(e).append(n)}}))}}updateGTMConsent(){if("function"==typeof gtag)return gtag("consent","update",this.getGTMConsentObject());window.dataLayer=window.dataLayer||[],window.dataLayer.push({0:"consent",1:"update",2:this.getGTMConsentObject()})}getGTMConsentObject(){return{ad_storage:"true"===e.find("cl_marketing")?.value?"granted":"denied",ad_user_data:"true"===e.find("cl_marketing")?.value?"granted":"denied",ad_personalization:"true"===e.find("cl_marketing")?.value?"granted":"denied",analytics_storage:"true"===e.find("cl_tracking")?.value?"granted":"denied",security_storage:"granted"}}isJSON(e){try{JSON.parse(e)}catch(e){return!1}return!0}buildScript(e,t,n=!1){let s="head"===e?"script":"noscript",i=document.createElement(s);return n?(i.src=t,i):(i.textContent=t,i)}static subscribe(e,t){return this.#i[e]?"function"!=typeof t?console.warn(`Expected callback for ${e} got ${typeof t}`):void this.#i[e].push(t):console.warn(`Cannot subscribe to ${e} because it does not exist!`)}static#c(e){const t=this.#i[e];if(!t)return console.warn(`Cannot trigger ${e} because it does not exist!`);for(let e of t)e()}}jQuery((function(e){t.subscribe("consent-given",(function(){console.log("should update screens"),e("iframe[data-cl-src]").each((function(){e(this).attr("src",e(this).attr("data-cl-src"))})),e("script[type=cookielegitblock]").each((function(){e(this).attr("src",e(this).attr("data-cl-src")),e(this).attr("type",e(this).attr("data-cl-type"))}))})),window.cookieLegitNotice=new t("body",{consentMode:""!==cl_config.consent_mode,userOpt:""!==cl_config.user_opt,baseUrl:cl_config.ajax_url,themeUrl:cl_config.themeUrl})}))})(),e.p})(); -
cookielegit/tags/1.0.1/src/public/class-cookie-legit-notice.php
r3148248 r3148281 14 14 public static function enqueue_assets() 15 15 { 16 wp_enqueue_style('cl-main', COOKIE_LEGIT_URL . 'dist/public.css', [], COOKIE_LEGIT_VERSION);16 // wp_enqueue_style('cl-main', COOKIE_LEGIT_URL . 'dist/public.css', [], COOKIE_LEGIT_VERSION); 17 17 wp_enqueue_script('cl-main', COOKIE_LEGIT_URL . 'dist/public.js', ['jquery'], COOKIE_LEGIT_VERSION, true); 18 18 … … 24 24 'user_opt' => (isset($notice_settings['user_opt']) && $notice_settings['user_opt'] === 'on'), 25 25 'ajax_url' => admin_url('admin-ajax.php'), 26 'themeUrl' => COOKIE_LEGIT_URL . 'dist/public.css' 26 27 )); 27 28 } -
cookielegit/trunk/CHANGELOG.md
r3148254 r3148281 1 1 # Changelog 2 3 ## [1.0.1](https://github.com/WebdesignSeolab/cookie-legit/compare/v1.0.0...v1.0.1) (2024-09-08) 4 5 6 ### Features 7 8 * load style async ([#9](https://github.com/WebdesignSeolab/cookie-legit/issues/9)) ([f69861b](https://github.com/WebdesignSeolab/cookie-legit/commit/f69861b3ccbd9cafb11d1fe4e78a2241cc52f088)) 2 9 3 10 ## [1.0.0](https://github.com/WebdesignSeolab/cookie-legit/compare/v1.0.1...v1.0.0) (2024-09-08) -
cookielegit/trunk/assets/scripts/public.js
r3148248 r3148281 1 1 import CookieLegitNotice from "./public/cookielegit"; 2 2 3 jQuery(function ($) {3 jQuery(function($) { 4 4 5 5 const updateBlocked = function() { 6 6 console.log('should update screens') 7 $("iframe[data-cl-src]").each(function () {7 $("iframe[data-cl-src]").each(function() { 8 8 $(this).attr("src", $(this).attr("data-cl-src")); 9 9 }); 10 10 11 $("script[type=cookielegitblock]").each(function () {11 $("script[type=cookielegitblock]").each(function() { 12 12 $(this).attr("src", $(this).attr("data-cl-src")); 13 13 $(this).attr("type", $(this).attr("data-cl-type")); … … 21 21 userOpt: cl_config.user_opt !== "", 22 22 baseUrl: cl_config.ajax_url, 23 themeUrl: cl_config.themeUrl 23 24 }); 24 25 }); -
cookielegit/trunk/assets/scripts/public/cookielegit.js
r3148248 r3148281 18 18 consentMode: false, 19 19 cookieDuration: 182, 20 themeUrl: null 20 21 }; 21 22 … … 36 37 } 37 38 39 buildStyle(cookieNotice) { 40 const tag = document.createElement('link'); 41 tag.href = this.#settings.themeUrl; 42 tag.rel = 'stylesheet'; 43 tag.id = 'cookielegit-css'; 44 45 tag.onload = () => { 46 cookieNotice.style.display = ''; 47 } 48 49 document.head.append(tag); 50 51 } 52 38 53 checkConsentCookies() { 39 54 LegitCookies.list() … … 44 59 this.updateGTMConsent(); 45 60 } 46 if(this.#consentedTo.length > 0) { 61 62 if (this.#consentedTo.length > 0) { 47 63 CookieLegitNotice.#trigger('consent-given'); 48 64 } … … 58 74 this.#notice.id = "cookie-legit-notice-container"; 59 75 this.#notice.innerHTML = notice.html; 76 this.#notice.style.display = 'none'; 77 78 let screen = this.#consentedTo.length === 0 ? "notice" : "toggle-preferences"; 79 this.#notice.classList.add(screen); 80 60 81 this.#target.appendChild(this.#notice); 61 let screen = 62 this.#consentedTo.length === 0 ? "notice" : "toggle-preferences"; 63 this.changeScreen(screen); 82 // this.changeScreen(screen); 64 83 this.setupEvents(); 65 84 … … 67 86 this.setPrefToggles(); 68 87 } 88 89 this.buildStyle(this.#notice); 69 90 } 70 91 … … 166 187 let scriptsWithPlacement = await scriptReq.json(); 167 188 for (const placement in scriptsWithPlacement) { 168 if (Object.hasOwnProperty.call(scriptsWithPlacement, placement)) { 169 const scripts = scriptsWithPlacement[placement]; 170 Object.values(scripts).forEach(script => { 171 if(!this.isJSON(script)) { 172 let tag = this.buildScript(placement, script); 189 if (Object.hasOwnProperty.call(scriptsWithPlacement, placement)) { 190 const scripts = scriptsWithPlacement[placement]; 191 Object.values(scripts).forEach(script => { 192 if (!this.isJSON(script)) { 193 let tag = this.buildScript(placement, script); 194 document.querySelector(placement).append(tag); 195 } else { 196 script = JSON.parse(script); 197 for (const stype in script) { 198 if (Object.hasOwnProperty.call(script, stype)) { 199 const contents = script[stype]; 200 contents.forEach(content => { 201 let tag = this.buildScript(placement, content, stype === 'srcs'); 173 202 document.querySelector(placement).append(tag); 174 } else { 175 script = JSON.parse(script); 176 for (const stype in script) { 177 if (Object.hasOwnProperty.call(script, stype)) { 178 const contents = script[stype]; 179 contents.forEach(content => { 180 let tag = this.buildScript(placement, content, stype === 'srcs'); 181 document.querySelector(placement).append(tag); 182 }) 183 } 184 } 185 } 186 }); 187 } 203 }) 204 } 205 } 206 } 207 }); 208 } 188 209 } 189 210 } … … 196 217 window.dataLayer = window.dataLayer || []; 197 218 window.dataLayer.push({ 198 0: "consent",199 1: "update",200 2: this.getGTMConsentObject()219 0: "consent", 220 1: "update", 221 2: this.getGTMConsentObject() 201 222 }); 202 223 } … … 204 225 getGTMConsentObject() { 205 226 return { 206 ad_storage:207 LegitCookies.find("cl_marketing")?.value === "true"208 ? "granted"209 : "denied",210 ad_user_data:211 LegitCookies.find("cl_marketing")?.value === "true"212 ? "granted"213 : "denied",214 ad_personalization:215 LegitCookies.find("cl_marketing")?.value === "true"216 ? "granted"217 : "denied",218 analytics_storage:219 LegitCookies.find("cl_tracking")?.value === "true"220 ? "granted"221 : "denied",222 security_storage: "granted",223 }227 ad_storage: 228 LegitCookies.find("cl_marketing")?.value === "true" 229 ? "granted" 230 : "denied", 231 ad_user_data: 232 LegitCookies.find("cl_marketing")?.value === "true" 233 ? "granted" 234 : "denied", 235 ad_personalization: 236 LegitCookies.find("cl_marketing")?.value === "true" 237 ? "granted" 238 : "denied", 239 analytics_storage: 240 LegitCookies.find("cl_tracking")?.value === "true" 241 ? "granted" 242 : "denied", 243 security_storage: "granted", 244 } 224 245 } 225 246 … … 227 248 try { 228 249 let json = JSON.parse(objectString) 229 } catch (e) {250 } catch (e) { 230 251 return false; 231 252 } … … 238 259 let tag = document.createElement(tagName); 239 260 240 if (isSrc) {261 if (isSrc) { 241 262 tag.src = scriptContent; 242 263 return tag; … … 263 284 264 285 if (!callbacks) return console.warn(`Cannot trigger ${event} because it does not exist!`); 265 286 266 287 for (let callback of callbacks) { 267 288 callback(); -
cookielegit/trunk/dist/public.js
r3148248 r3148281 1 (()=>{"use strict";var e={};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),(()=>{var t;e.g.importScripts&&(t=e.g.location+"");var n=e.g.document;if(!t&&n&&(n.currentScript&&(t=n.currentScript.src),!t)){var s=n.getElementsByTagName("script");if(s.length)for(var i=s.length-1;i>-1&&!t;)t=s[i--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),e.p=t})(),(()=>{class e{static list(){const e=[],t=document.cookie.split("; ");for(let n=0;n<t.length;n++){const s=t[n].split("="),i=s[0];let c=s.length>1?s[1]:null;e.push({name:i,value:c})}return e}static find(e=""){return this.list().find((t=>t.name===e))||null}static create(e,t,n=1,s="/"){const i=new Date,c=new Date(i.getTime()+24*n*60*60*1e3);return document.cookie=`${e}=${t}; expires=${c}; path=${s}`,this}static delete(e){return document.cookie=`${e}=; Max-Age=-99999999;`,this}}class t{#e=null;#t=null;#n=null;#s=[];screens=["notice","preferences","toggle-preferences"];consentCookieName="cl_consent";cookieNames=["cl_consent","cl_essential","cl_tracking","cl_marketing"];defaultSettings={baseUrl:null,userOpt:!1,consentMode:!1,cookieDuration:182 };static#i={"cookie-legit-init":[],"notice-loaded":[],"consent-given":[],"consent-updated":[]};constructor(e,t){return this.#n=Object.assign({},this.defaultSettings,t),this.#e=this.selectTarget(e),this.checkConsentCookies(),this.insertNotice(),this.maybeInjectScripts(),this}checkConsentCookies(){e.list().filter((e=>e.name.startsWith("cl_"))).forEach((e=>this.#s.push(e))),this.#n.consentMode&&this.#s.length>0&&this.updateGTMConsent(),this.#s.length>0&&t.#c("consent-given")}selectTarget(e){return document.querySelector(e)}async insertNotice(){let e=await this.fetchNotice();this.#t=document.createElement("div"),this.#t.id="cookie-legit-notice-container",this.#t.innerHTML=e.html,this.#e.appendChild(this.#t);let t=0===this.#s.length?"notice":"toggle-preferences";this.changeScreen(t),this.setupEvents(),this.#n.userOpt&&this.setPrefToggles()}async fetchNotice(){const e=await fetch(`${this.#n.baseUrl}?action=get_cookie_notice`);return await e.json()}setupEvents(){this.#n.userOpt?(this.#t.querySelector(".cookie-legit-pref-btn").addEventListener("click",(()=>this.toggleUserPreferences())),this.#t.querySelector(".cookie-legit-save-pref-btn").addEventListener("click",(()=>this.savePreferences())),this.#t.querySelector(".cookie-legit-accept-pref-btn").addEventListener("click",(()=>this.acceptAllCookies()))):this.#t.querySelector(".cookie-legit-deny-btn").addEventListener("click",(()=>this.denyAllCookies())),this.#t.querySelector(".cookie-legit-preferences-change").addEventListener("click",(()=>this.updatePreferences())),this.#t.querySelector(".cookie-legit-accept-btn").addEventListener("click",(()=>this.acceptAllCookies()))}toggleUserPreferences(){this.changeScreen("preferences")}acceptAllCookies(){this.changeScreen("toggle-preferences"),this.cookieNames.forEach((t=>{e.create(t,!0,this.#n.cookieDuration)})),this.checkConsentCookies()}savePreferences(){this.changeScreen("toggle-preferences"),this.cookieNames.forEach((t=>{let n=t===this.consentCookieName||this.#t.querySelector(`input[name=${t}]`).checked;e.create(t,n,this.#n.cookieDuration)})),this.checkConsentCookies()}updatePreferences(){let e=this.#n.userOpt?"preferences":"notice";this.changeScreen(e),this.checkConsentCookies(),t.#c("consent-updated")}denyAllCookies(){this.changeScreen("toggle-preferences"),this.cookieNames.forEach((t=>{let n=t===this.consentCookieName;e.create(t,n,this.#n.cookieDuration)})),this.checkConsentCookies()}changeScreen(e){let t=this.screens.filter((t=>t!==e));this.#t.classList.remove(...t),this.#t.classList.add(e)}setPrefToggles(){this.#s.forEach((e=>{let t=this.#t.querySelector(`input[name=${e.name}]`);t&&(t.checked="true"===e.value)}))}async maybeInjectScripts(){if(!this.#n.userOpt||"true"!==e.find(this.consentCookieName))return;let t=await fetch(`${this.#n.baseUrl}?action=get_tracking_scripts`),n=await t.json();for(const e in n)if(Object.hasOwnProperty.call(n,e)){const t=n[e];Object.values(t).forEach((t=>{if(this.isJSON(t)){t=JSON.parse(t);for(const n in t)Object.hasOwnProperty.call(t,n)&&t[n].forEach((t=>{let s=this.buildScript(e,t,"srcs"===n);document.querySelector(e).append(s)}))}else{let n=this.buildScript(e,t);document.querySelector(e).append(n)}}))}}updateGTMConsent(){if("function"==typeof gtag)return gtag("consent","update",this.getGTMConsentObject());window.dataLayer=window.dataLayer||[],window.dataLayer.push({0:"consent",1:"update",2:this.getGTMConsentObject()})}getGTMConsentObject(){return{ad_storage:"true"===e.find("cl_marketing")?.value?"granted":"denied",ad_user_data:"true"===e.find("cl_marketing")?.value?"granted":"denied",ad_personalization:"true"===e.find("cl_marketing")?.value?"granted":"denied",analytics_storage:"true"===e.find("cl_tracking")?.value?"granted":"denied",security_storage:"granted"}}isJSON(e){try{JSON.parse(e)}catch(e){return!1}return!0}buildScript(e,t,n=!1){let s="head"===e?"script":"noscript",i=document.createElement(s);return n?(i.src=t,i):(i.textContent=t,i)}static subscribe(e,t){return this.#i[e]?"function"!=typeof t?console.warn(`Expected callback for ${e} got ${typeof t}`):void this.#i[e].push(t):console.warn(`Cannot subscribe to ${e} because it does not exist!`)}static#c(e){const t=this.#i[e];if(!t)return console.warn(`Cannot trigger ${e} because it does not exist!`);for(let e of t)e()}}jQuery((function(e){t.subscribe("consent-given",(function(){console.log("should update screens"),e("iframe[data-cl-src]").each((function(){e(this).attr("src",e(this).attr("data-cl-src"))})),e("script[type=cookielegitblock]").each((function(){e(this).attr("src",e(this).attr("data-cl-src")),e(this).attr("type",e(this).attr("data-cl-type"))}))})),window.cookieLegitNotice=new t("body",{consentMode:""!==cl_config.consent_mode,userOpt:""!==cl_config.user_opt,baseUrl:cl_config.ajax_url})}))})(),e.p})();1 (()=>{"use strict";var e={};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),(()=>{var t;e.g.importScripts&&(t=e.g.location+"");var n=e.g.document;if(!t&&n&&(n.currentScript&&(t=n.currentScript.src),!t)){var s=n.getElementsByTagName("script");if(s.length)for(var i=s.length-1;i>-1&&!t;)t=s[i--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),e.p=t})(),(()=>{class e{static list(){const e=[],t=document.cookie.split("; ");for(let n=0;n<t.length;n++){const s=t[n].split("="),i=s[0];let c=s.length>1?s[1]:null;e.push({name:i,value:c})}return e}static find(e=""){return this.list().find((t=>t.name===e))||null}static create(e,t,n=1,s="/"){const i=new Date,c=new Date(i.getTime()+24*n*60*60*1e3);return document.cookie=`${e}=${t}; expires=${c}; path=${s}`,this}static delete(e){return document.cookie=`${e}=; Max-Age=-99999999;`,this}}class t{#e=null;#t=null;#n=null;#s=[];screens=["notice","preferences","toggle-preferences"];consentCookieName="cl_consent";cookieNames=["cl_consent","cl_essential","cl_tracking","cl_marketing"];defaultSettings={baseUrl:null,userOpt:!1,consentMode:!1,cookieDuration:182,themeUrl:null};static#i={"cookie-legit-init":[],"notice-loaded":[],"consent-given":[],"consent-updated":[]};constructor(e,t){return this.#n=Object.assign({},this.defaultSettings,t),this.#e=this.selectTarget(e),this.checkConsentCookies(),this.insertNotice(),this.maybeInjectScripts(),this}buildStyle(e){const t=document.createElement("link");t.href=this.#n.themeUrl,t.rel="stylesheet",t.id="cookielegit-css",t.onload=()=>{e.style.display=""},document.head.append(t)}checkConsentCookies(){e.list().filter((e=>e.name.startsWith("cl_"))).forEach((e=>this.#s.push(e))),this.#n.consentMode&&this.#s.length>0&&this.updateGTMConsent(),this.#s.length>0&&t.#c("consent-given")}selectTarget(e){return document.querySelector(e)}async insertNotice(){let e=await this.fetchNotice();this.#t=document.createElement("div"),this.#t.id="cookie-legit-notice-container",this.#t.innerHTML=e.html,this.#t.style.display="none";let t=0===this.#s.length?"notice":"toggle-preferences";this.#t.classList.add(t),this.#e.appendChild(this.#t),this.setupEvents(),this.#n.userOpt&&this.setPrefToggles(),this.buildStyle(this.#t)}async fetchNotice(){const e=await fetch(`${this.#n.baseUrl}?action=get_cookie_notice`);return await e.json()}setupEvents(){this.#n.userOpt?(this.#t.querySelector(".cookie-legit-pref-btn").addEventListener("click",(()=>this.toggleUserPreferences())),this.#t.querySelector(".cookie-legit-save-pref-btn").addEventListener("click",(()=>this.savePreferences())),this.#t.querySelector(".cookie-legit-accept-pref-btn").addEventListener("click",(()=>this.acceptAllCookies()))):this.#t.querySelector(".cookie-legit-deny-btn").addEventListener("click",(()=>this.denyAllCookies())),this.#t.querySelector(".cookie-legit-preferences-change").addEventListener("click",(()=>this.updatePreferences())),this.#t.querySelector(".cookie-legit-accept-btn").addEventListener("click",(()=>this.acceptAllCookies()))}toggleUserPreferences(){this.changeScreen("preferences")}acceptAllCookies(){this.changeScreen("toggle-preferences"),this.cookieNames.forEach((t=>{e.create(t,!0,this.#n.cookieDuration)})),this.checkConsentCookies()}savePreferences(){this.changeScreen("toggle-preferences"),this.cookieNames.forEach((t=>{let n=t===this.consentCookieName||this.#t.querySelector(`input[name=${t}]`).checked;e.create(t,n,this.#n.cookieDuration)})),this.checkConsentCookies()}updatePreferences(){let e=this.#n.userOpt?"preferences":"notice";this.changeScreen(e),this.checkConsentCookies(),t.#c("consent-updated")}denyAllCookies(){this.changeScreen("toggle-preferences"),this.cookieNames.forEach((t=>{let n=t===this.consentCookieName;e.create(t,n,this.#n.cookieDuration)})),this.checkConsentCookies()}changeScreen(e){let t=this.screens.filter((t=>t!==e));this.#t.classList.remove(...t),this.#t.classList.add(e)}setPrefToggles(){this.#s.forEach((e=>{let t=this.#t.querySelector(`input[name=${e.name}]`);t&&(t.checked="true"===e.value)}))}async maybeInjectScripts(){if(!this.#n.userOpt||"true"!==e.find(this.consentCookieName))return;let t=await fetch(`${this.#n.baseUrl}?action=get_tracking_scripts`),n=await t.json();for(const e in n)if(Object.hasOwnProperty.call(n,e)){const t=n[e];Object.values(t).forEach((t=>{if(this.isJSON(t)){t=JSON.parse(t);for(const n in t)Object.hasOwnProperty.call(t,n)&&t[n].forEach((t=>{let s=this.buildScript(e,t,"srcs"===n);document.querySelector(e).append(s)}))}else{let n=this.buildScript(e,t);document.querySelector(e).append(n)}}))}}updateGTMConsent(){if("function"==typeof gtag)return gtag("consent","update",this.getGTMConsentObject());window.dataLayer=window.dataLayer||[],window.dataLayer.push({0:"consent",1:"update",2:this.getGTMConsentObject()})}getGTMConsentObject(){return{ad_storage:"true"===e.find("cl_marketing")?.value?"granted":"denied",ad_user_data:"true"===e.find("cl_marketing")?.value?"granted":"denied",ad_personalization:"true"===e.find("cl_marketing")?.value?"granted":"denied",analytics_storage:"true"===e.find("cl_tracking")?.value?"granted":"denied",security_storage:"granted"}}isJSON(e){try{JSON.parse(e)}catch(e){return!1}return!0}buildScript(e,t,n=!1){let s="head"===e?"script":"noscript",i=document.createElement(s);return n?(i.src=t,i):(i.textContent=t,i)}static subscribe(e,t){return this.#i[e]?"function"!=typeof t?console.warn(`Expected callback for ${e} got ${typeof t}`):void this.#i[e].push(t):console.warn(`Cannot subscribe to ${e} because it does not exist!`)}static#c(e){const t=this.#i[e];if(!t)return console.warn(`Cannot trigger ${e} because it does not exist!`);for(let e of t)e()}}jQuery((function(e){t.subscribe("consent-given",(function(){console.log("should update screens"),e("iframe[data-cl-src]").each((function(){e(this).attr("src",e(this).attr("data-cl-src"))})),e("script[type=cookielegitblock]").each((function(){e(this).attr("src",e(this).attr("data-cl-src")),e(this).attr("type",e(this).attr("data-cl-type"))}))})),window.cookieLegitNotice=new t("body",{consentMode:""!==cl_config.consent_mode,userOpt:""!==cl_config.user_opt,baseUrl:cl_config.ajax_url,themeUrl:cl_config.themeUrl})}))})(),e.p})(); -
cookielegit/trunk/src/public/class-cookie-legit-notice.php
r3148248 r3148281 14 14 public static function enqueue_assets() 15 15 { 16 wp_enqueue_style('cl-main', COOKIE_LEGIT_URL . 'dist/public.css', [], COOKIE_LEGIT_VERSION);16 // wp_enqueue_style('cl-main', COOKIE_LEGIT_URL . 'dist/public.css', [], COOKIE_LEGIT_VERSION); 17 17 wp_enqueue_script('cl-main', COOKIE_LEGIT_URL . 'dist/public.js', ['jquery'], COOKIE_LEGIT_VERSION, true); 18 18 … … 24 24 'user_opt' => (isset($notice_settings['user_opt']) && $notice_settings['user_opt'] === 'on'), 25 25 'ajax_url' => admin_url('admin-ajax.php'), 26 'themeUrl' => COOKIE_LEGIT_URL . 'dist/public.css' 26 27 )); 27 28 }
Note: See TracChangeset
for help on using the changeset viewer.