Plugin Directory

Changeset 3148281


Ignore:
Timestamp:
09/08/2024 09:29:45 PM (19 months ago)
Author:
cookielegit
Message:

Update to version 1.0.1 from GitHub

Location:
cookielegit
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • cookielegit/tags/1.0.1/CHANGELOG.md

    r3148254 r3148281  
    11# 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))
    29
    310## [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  
    11import CookieLegitNotice from "./public/cookielegit";
    22
    3 jQuery(function ($) {
     3jQuery(function($) {
    44
    55  const updateBlocked = function() {
    66    console.log('should update screens')
    7     $("iframe[data-cl-src]").each(function () {
     7    $("iframe[data-cl-src]").each(function() {
    88      $(this).attr("src", $(this).attr("data-cl-src"));
    99    });
    1010
    11     $("script[type=cookielegitblock]").each(function () {
     11    $("script[type=cookielegitblock]").each(function() {
    1212      $(this).attr("src", $(this).attr("data-cl-src"));
    1313      $(this).attr("type", $(this).attr("data-cl-type"));
     
    2121    userOpt: cl_config.user_opt !== "",
    2222    baseUrl: cl_config.ajax_url,
     23    themeUrl: cl_config.themeUrl
    2324  });
    2425});
  • cookielegit/tags/1.0.1/assets/scripts/public/cookielegit.js

    r3148248 r3148281  
    1818    consentMode: false,
    1919    cookieDuration: 182,
     20    themeUrl: null
    2021  };
    2122
     
    3637  }
    3738
     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
    3853  checkConsentCookies() {
    3954    LegitCookies.list()
     
    4459      this.updateGTMConsent();
    4560    }
    46     if(this.#consentedTo.length > 0) {
     61
     62    if (this.#consentedTo.length > 0) {
    4763      CookieLegitNotice.#trigger('consent-given');
    4864    }
     
    5874    this.#notice.id = "cookie-legit-notice-container";
    5975    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
    6081    this.#target.appendChild(this.#notice);
    61     let screen =
    62       this.#consentedTo.length === 0 ? "notice" : "toggle-preferences";
    63     this.changeScreen(screen);
     82    // this.changeScreen(screen);
    6483    this.setupEvents();
    6584
     
    6786      this.setPrefToggles();
    6887    }
     88
     89    this.buildStyle(this.#notice);
    6990  }
    7091
     
    166187    let scriptsWithPlacement = await scriptReq.json();
    167188    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');
    173202                  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      }
    188209    }
    189210  }
     
    196217    window.dataLayer = window.dataLayer || [];
    197218    window.dataLayer.push({
    198         0: "consent",
    199         1: "update",
    200         2: this.getGTMConsentObject()
     219      0: "consent",
     220      1: "update",
     221      2: this.getGTMConsentObject()
    201222    });
    202223  }
     
    204225  getGTMConsentObject() {
    205226    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    }
    224245  }
    225246
     
    227248    try {
    228249      let json = JSON.parse(objectString)
    229     } catch(e) {
     250    } catch (e) {
    230251      return false;
    231252    }
     
    238259    let tag = document.createElement(tagName);
    239260
    240     if(isSrc) {
     261    if (isSrc) {
    241262      tag.src = scriptContent;
    242263      return tag;
     
    263284
    264285    if (!callbacks) return console.warn(`Cannot trigger ${event} because it does not exist!`);
    265    
     286
    266287    for (let callback of callbacks) {
    267288      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  
    1414    public static function enqueue_assets()
    1515    {
    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);
    1717        wp_enqueue_script('cl-main', COOKIE_LEGIT_URL . 'dist/public.js', ['jquery'], COOKIE_LEGIT_VERSION, true);
    1818
     
    2424            'user_opt' => (isset($notice_settings['user_opt']) && $notice_settings['user_opt'] === 'on'),
    2525            'ajax_url' => admin_url('admin-ajax.php'),
     26            'themeUrl' => COOKIE_LEGIT_URL . 'dist/public.css'
    2627        ));
    2728    }
  • cookielegit/trunk/CHANGELOG.md

    r3148254 r3148281  
    11# 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))
    29
    310## [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  
    11import CookieLegitNotice from "./public/cookielegit";
    22
    3 jQuery(function ($) {
     3jQuery(function($) {
    44
    55  const updateBlocked = function() {
    66    console.log('should update screens')
    7     $("iframe[data-cl-src]").each(function () {
     7    $("iframe[data-cl-src]").each(function() {
    88      $(this).attr("src", $(this).attr("data-cl-src"));
    99    });
    1010
    11     $("script[type=cookielegitblock]").each(function () {
     11    $("script[type=cookielegitblock]").each(function() {
    1212      $(this).attr("src", $(this).attr("data-cl-src"));
    1313      $(this).attr("type", $(this).attr("data-cl-type"));
     
    2121    userOpt: cl_config.user_opt !== "",
    2222    baseUrl: cl_config.ajax_url,
     23    themeUrl: cl_config.themeUrl
    2324  });
    2425});
  • cookielegit/trunk/assets/scripts/public/cookielegit.js

    r3148248 r3148281  
    1818    consentMode: false,
    1919    cookieDuration: 182,
     20    themeUrl: null
    2021  };
    2122
     
    3637  }
    3738
     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
    3853  checkConsentCookies() {
    3954    LegitCookies.list()
     
    4459      this.updateGTMConsent();
    4560    }
    46     if(this.#consentedTo.length > 0) {
     61
     62    if (this.#consentedTo.length > 0) {
    4763      CookieLegitNotice.#trigger('consent-given');
    4864    }
     
    5874    this.#notice.id = "cookie-legit-notice-container";
    5975    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
    6081    this.#target.appendChild(this.#notice);
    61     let screen =
    62       this.#consentedTo.length === 0 ? "notice" : "toggle-preferences";
    63     this.changeScreen(screen);
     82    // this.changeScreen(screen);
    6483    this.setupEvents();
    6584
     
    6786      this.setPrefToggles();
    6887    }
     88
     89    this.buildStyle(this.#notice);
    6990  }
    7091
     
    166187    let scriptsWithPlacement = await scriptReq.json();
    167188    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');
    173202                  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      }
    188209    }
    189210  }
     
    196217    window.dataLayer = window.dataLayer || [];
    197218    window.dataLayer.push({
    198         0: "consent",
    199         1: "update",
    200         2: this.getGTMConsentObject()
     219      0: "consent",
     220      1: "update",
     221      2: this.getGTMConsentObject()
    201222    });
    202223  }
     
    204225  getGTMConsentObject() {
    205226    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    }
    224245  }
    225246
     
    227248    try {
    228249      let json = JSON.parse(objectString)
    229     } catch(e) {
     250    } catch (e) {
    230251      return false;
    231252    }
     
    238259    let tag = document.createElement(tagName);
    239260
    240     if(isSrc) {
     261    if (isSrc) {
    241262      tag.src = scriptContent;
    242263      return tag;
     
    263284
    264285    if (!callbacks) return console.warn(`Cannot trigger ${event} because it does not exist!`);
    265    
     286
    266287    for (let callback of callbacks) {
    267288      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  
    1414    public static function enqueue_assets()
    1515    {
    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);
    1717        wp_enqueue_script('cl-main', COOKIE_LEGIT_URL . 'dist/public.js', ['jquery'], COOKIE_LEGIT_VERSION, true);
    1818
     
    2424            'user_opt' => (isset($notice_settings['user_opt']) && $notice_settings['user_opt'] === 'on'),
    2525            'ajax_url' => admin_url('admin-ajax.php'),
     26            'themeUrl' => COOKIE_LEGIT_URL . 'dist/public.css'
    2627        ));
    2728    }
Note: See TracChangeset for help on using the changeset viewer.