vanilla-cookieconsent
Advanced tools
Comparing version 2.4.7 to 2.5.0
@@ -32,9 +32,9 @@ /* | ||
consent_modal : { | ||
layout : 'cloud', // box(default),cloud,bar | ||
position : 'bottom center', // bottom(default),top + left,right,center:=> examples: 'bottom' or 'top right' | ||
transition : 'slide' // zoom(default),slide | ||
layout : 'cloud', // box(default),cloud,bar | ||
position : 'bottom center', // bottom(default),top + left,right,center:=> examples: 'bottom' or 'top right' | ||
transition : 'slide' // zoom(default),slide | ||
}, | ||
settings_modal : { | ||
layout : 'box', // box(default),bar | ||
// position: 'left', // right(default),left (available only if bar layout selected) | ||
layout : 'bar', // box(default),bar | ||
position: 'left', // right(default),left (available only if bar layout selected) | ||
transition : 'slide' // zoom(default),slide | ||
@@ -55,6 +55,22 @@ } | ||
onChange: function(cookie){ | ||
onChange: function(cookie, changed_preferences){ | ||
console.log("onChange fired ..."); | ||
// do something ... | ||
// If analytics category's status was changed ... | ||
if(changed_preferences.indexOf('analytics') > -1){ | ||
// If analytics category is disabled ... | ||
if(!cc.allowedCategory('analytics')){ | ||
// Disable gtag ... | ||
console.log("disabling gtag") | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag() { dataLayer.push(arguments); } | ||
gtag('consent', 'default', { | ||
'ad_storage': 'denied', | ||
'analytics_storage': 'denied' | ||
}); | ||
} | ||
} | ||
// Delete line below | ||
@@ -67,3 +83,3 @@ document.getElementById("cookie_val").innerHTML = JSON.stringify(cookie, null, 2); | ||
consent_modal : { | ||
title : "👋 It's time for some nice cookies", | ||
title : "Hello traveler, it's cookie time!", | ||
description : 'Hi, this website uses essential cookies to ensure its proper operation and tracking cookies to understand how you interact with it. The latter will be set only after consent. <a href="#privacy-policy" class="cc-link">Privacy policy</a>', | ||
@@ -75,10 +91,12 @@ primary_btn: { | ||
secondary_btn: { | ||
text : 'Manage preferences', | ||
text : 'Preferences', | ||
role : 'settings' //'settings' or 'accept_necessary' | ||
} | ||
}, | ||
revision_message: "<br><br> Dear user, terms and conditions have changed since the last time you visisted!" | ||
}, | ||
settings_modal : { | ||
title : '<div>Cookie preferences</div><div aria-hidden="true" style="font-size: .8em; font-weight: 200; color: #687278; margin-top: 5px;">Powered by <a tabindex="-1" aria-hidden="true" href="https://github.com/orestbida/cookieconsent/" style="text-decoration: underline;">cookie-consent</a></div>', | ||
title : '<div>Cookie preferences</div><div aria-hidden="true" style="font-size: .8em; font-weight: 400; color: #687278; margin-top: 3px;">Powered by <a tabindex="-1" aria-hidden="true" href="https://github.com/orestbida/cookieconsent/">cookie-consent</a></div>', | ||
save_settings_btn : "Save current selection", | ||
accept_all_btn : "Accept all", | ||
reject_all_btn: "Reject all", | ||
close_btn_label: "Close", | ||
@@ -104,3 +122,3 @@ cookie_table_headers : [ | ||
title : "Analytics & Performance cookies", | ||
description: getLoremIpsum()+getLoremIpsum(), | ||
description: getLoremIpsum(), | ||
toggle : { | ||
@@ -113,17 +131,8 @@ value : 'analytics', | ||
{ | ||
col1: '_ga', | ||
col1: '^_ga', | ||
col2: 'yourdomain.com', | ||
col3: getLoremIpsum(), | ||
col3: "description ...", | ||
is_regex: true | ||
}, | ||
{ | ||
col1: '_gat', | ||
col2: 'yourdomain.com', | ||
col3: getLoremIpsum(), | ||
}, | ||
{ | ||
col1: '_gat_UA-46747204-9', | ||
col2: 'yourdomain.com', | ||
col3: getLoremIpsum(), | ||
}, | ||
{ | ||
col1: '_gid', | ||
@@ -168,2 +177,3 @@ col2: 'yourdomain.com', | ||
function getLoremIpsum(){ | ||
@@ -170,0 +180,0 @@ return 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; |
/* | ||
CookieConsent v2.4.7 | ||
CookieConsent v2.5.0 | ||
https://www.github.com/orestbida/cookieconsent | ||
@@ -7,28 +7,30 @@ Author Orest Bida | ||
*/ | ||
(function(){function na(za){function oa(a,b){return a.classList?a.classList.contains(b):!!a.className.match(new RegExp("(\\s|^)"+b+"(\\s|$)"))}function ha(a,b){a.classList?a.classList.remove(b):a.className=a.className.replace(new RegExp("(\\s|^)"+b+"(\\s|$)")," ")}function C(a,b){a.classList?a.classList.add(b):oa(a,b)||(a.className+=" "+b)}function Z(a){if("object"===typeof a){var b=[],c=0;for(b[c++]in a);return b}}function I(a,b,c,d){a.addEventListener?d?a.addEventListener(b,c,{passive:!0}):a.addEventListener(b, | ||
c,!1):a.attachEvent("on"+b,c)}function ca(a,b,c){if("one"===b)var d=(d=document.cookie.match("(^|;)\\s*"+a+"\\s*=\\s*([^;]+)"))?c?d.pop():a:"";else if("all"===b)for(a=document.cookie.split(/;\s*/),d=[],b=0;b<a.length;b++)d.push(a[b].split("=")[0]);return d}function pa(){if(qa){var a=document.querySelectorAll("script[data-cookiecategory]"),b=ra,c=JSON.parse(J).level||[],d=function(f,h){if(h<f.length){var k=f[h],l=k.getAttribute("data-cookiecategory");if(-1<M(c,l)){k.type="text/javascript";k.removeAttribute("data-cookiecategory"); | ||
l=k.getAttribute("data-src");var g=e("script");g.textContent=k.innerHTML;(function(m,r){for(var w=r.attributes,B=w.length,N=0;N<B;N++)r=w[N],m.setAttribute(r.nodeName,r.nodeValue)})(g,k);l?g.src=l:l=k.src;l&&(b?g.readyState?g.onreadystatechange=function(){if("loaded"===g.readyState||"complete"===g.readyState)g.onreadystatechange=null,d(f,++h)}:g.onload=function(){g.onload=null;d(f,++h)}:l=!1);k.parentNode.replaceChild(g,k);if(l)return}d(f,++h)}};d(a,0)}}function Aa(a){function b(d,f,h,k,l,g,m){g= | ||
g&&g.split(" ")||[];if(-1<M(f,l)&&(C(d,l),-1<M(h,g[0])))for(f=0;f<g.length;f++)C(d,g[f]);-1<M(k,m)&&C(d,m)}if("object"===typeof a){var c=a.consent_modal;a=a.settings_modal;Q&&c&&b(z,["box","bar","cloud"],["top","bottom"],["zoom","slide"],c.layout,c.position,c.transition);a&&b(D,["bar"],["left","right"],["zoom","slide"],a.layout,a.position,a.transition)}}function Ba(){var a=!1,b=!1;I(document,"keydown",function(c){c=c||window.event;"Tab"===c.key&&(u&&(c.shiftKey?document.activeElement===u[0]&&(u[1].focus(), | ||
c.preventDefault()):document.activeElement===u[1]&&(u[0].focus(),c.preventDefault()),b||aa||(b=!0,!a&&c.preventDefault(),c.shiftKey?u[3]?u[2]?u[2].focus():u[0].focus():u[1].focus():u[3]?u[3].focus():u[0].focus())),!b&&(a=!0))});document.contains&&I(L,"click",function(c){c=c||window.event;ia?O.contains(c.target)?aa=!0:(t.hideSettings(0),aa=!1):ba&&z.contains(c.target)&&(aa=!0)},!0)}function e(a){var b=document.createElement(a);"button"===a&&b.setAttribute("type",a);return b}function M(a,b){for(var c= | ||
a.length,d=0;d<c;d++)if(a[d]==b)return d;return-1}function Ca(a,b){if("string"!==typeof a||""==a||document.getElementById("cc--style"))b();else{var c=e("style");c.id="cc--style";var d=new XMLHttpRequest;d.onreadystatechange=function(){4==this.readyState&&200==this.status&&(c.setAttribute("type","text/css"),c.styleSheet?c.styleSheet.cssText=this.responseText:c.appendChild(document.createTextNode(this.responseText)),document.getElementsByTagName("head")[0].appendChild(c),b())};d.open("GET",a);d.send()}} | ||
function da(a,b){var c=document.querySelectorAll(".c-tgl")||[],d="",f=[],h=!1;if(0<c.length){switch(b){case -1:for(b=0;b<c.length;b++)c[b].checked?(d+='"'+c[b].value+'",',E[b]||(f.push(c[b].value),E[b]=!0)):E[b]&&(f.push(c[b].value),E[b]=!1);break;case 0:for(b=0;b<c.length;b++)c[b].disabled?(d+='"'+c[b].value+'",',E[b]=!0):(c[b].checked=!1,E[b]&&(f.push(c[b].value),E[b]=!1));break;case 1:for(b=0;b<c.length;b++)c[b].checked=!0,d+='"'+c[b].value+'",',E[b]||f.push(c[b].value),E[b]=!0}d=d.slice(0,-1); | ||
if(a.autoclear_cookies&&R&&0<f.length){c=a.languages[F].settings_modal.blocks;b=c.length;var k=-1,l=ca("","all"),g=[S,"."+S];if("www."===S.slice(0,4)){var m=S.substr(4);g.push(m);g.push("."+m)}for(m=0;m<b;m++){var r=c[m];if(r.hasOwnProperty("toggle")&&!E[++k]&&r.hasOwnProperty("cookie_table")&&-1<M(f,r.toggle.value)){var w=r.cookie_table,B=Z(a.languages[F].settings_modal.cookie_table_headers[0])[0],N=w.length;"on_disable"===r.toggle.reload&&(h=!0);for(var K=0;K<N;K++){var n=w[K],G=[],v=n[B],q=n.is_regex|| | ||
!1,p=n.domain||null;n=n.path||!1;p&&(g=[p,"."+p]);if(q)for(q=0;q<l.length;q++)l[q].match(v)&&G.push(l[q]);else v=M(l,v),-1<v&&G.push(l[v]);if(0<G.length){v=g;n=n?n:"/";for(q=0;q<G.length;q++)for(p=0;p<v.length;p++)document.cookie=G[q]+"=; Path="+n+"; Domain="+v[p]+"; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";"on_clear"===r.toggle.reload&&(h=!0)}}}}}}J='{"level": ['+d+"]}";if(!R||0<f.length)d=ea,c=J,b=new Date,b.setTime(b.getTime()+864E5*sa),d=d+"="+(c||"")+("; expires="+b.toUTCString())+"; Path="+ta+ | ||
";",d+=" SameSite="+ua+";",-1<location.hostname.indexOf(".")&&(d+=" Domain="+S+";"),"https:"===location.protocol&&(d+=" Secure;"),document.cookie=d;pa();if("function"===typeof a.onAccept&&!R)return R=!0,a.onAccept(JSON.parse(J));if("function"===typeof a.onChange&&0<f.length)a.onChange(JSON.parse(J));h&&window.location.reload()}function Da(a,b){L=e("div");L.id="cc--main";L.style.position="fixed";L.style.zIndex="1000000";L.innerHTML='\x3c!--[if lt IE 9 ]><div id="cc_div" class="cc_div ie"></div><![endif]--\x3e\x3c!--[if (gt IE 8)|!(IE)]>\x3c!--\x3e<div id="cc_div" class="cc_div"></div>\x3c!--<![endif]--\x3e'; | ||
var c=L.children[0],d=F,f="string"===typeof T.textContent?"textContent":"innerText";if(!a){z=e("div");var h=e("div"),k=e("div"),l=e("div"),g=e("div"),m=e("div"),r=e("button"),w=e("button"),B=e("div");z.id="cm";h.id="c-inr";k.id="c-inr-i";l.id="c-ttl";g.id="c-txt";m.id="c-bns";r.id="c-p-bn";w.id="c-s-bn";B.id="cm-ov";r.className="c-bn";w.className="c-bn c_link";l.setAttribute("role","heading");l.setAttribute("aria-level","2");z.setAttribute("role","dialog");z.setAttribute("aria-modal","true");z.setAttribute("aria-hidden", | ||
"false");z.setAttribute("aria-labelledby","c-ttl");z.setAttribute("aria-describedby","c-txt");z.style.visibility=B.style.visibility="hidden";B.style.opacity=0;l.insertAdjacentHTML("beforeend",b.languages[d].consent_modal.title);g.insertAdjacentHTML("beforeend",b.languages[d].consent_modal.description);r[f]=b.languages[d].consent_modal.primary_btn.text;w[f]=b.languages[d].consent_modal.secondary_btn.text;var N=-1;"accept_all"==b.languages[d].consent_modal.primary_btn.role&&(N=1);I(r,"click",function(){t.hide(); | ||
da(b,N)});"accept_necessary"==b.languages[d].consent_modal.secondary_btn.role?I(w,"click",function(){t.hide();da(b,0)}):I(w,"click",function(){t.showSettings(0)});k.appendChild(l);k.appendChild(g);m.appendChild(r);m.appendChild(w);h.appendChild(k);h.appendChild(m);z.appendChild(h);c.appendChild(z);c.appendChild(B)}D=e("div");h=e("div");k=e("div");l=e("div");O=e("div");g=e("div");m=e("div");var K=e("button");r=e("div");w=e("div");B=e("div");D.id="s-cnt";h.id="c-vln";l.id="c-s-in";k.id="cs";g.id="s-ttl"; | ||
O.id="s-inr";m.id="s-hdr";w.id="s-bl";K.id="s-c-bn";B.id="cs-ov";r.id="s-c-bnc";K.className="c-bn";K.setAttribute("aria-label",b.languages[d].settings_modal.close_btn_label||"Close");D.setAttribute("role","dialog");D.setAttribute("aria-modal","true");D.setAttribute("aria-hidden","true");D.setAttribute("aria-labelledby","s-ttl");g.setAttribute("role","heading");D.style.visibility=B.style.visibility="hidden";B.style.opacity=0;r.appendChild(K);I(h,"keydown",function(U){U=U||window.event;27==U.keyCode&& | ||
t.hideSettings(0)},!0);I(K,"click",function(){t.hideSettings(0)});d=b.languages[F].settings_modal.blocks;K=d.length;g.insertAdjacentHTML("beforeend",b.languages[F].settings_modal.title);for(var n=0;n<K;++n){var G=e("div"),v=e("div"),q=e("div"),p=e("div");G.className="c-bl";v.className="desc";q.className="p";p.className="title";q.insertAdjacentHTML("beforeend",d[n].description);if("undefined"!==typeof d[n].toggle){var x="c-ac-"+n,P=e("button"),H=e("label"),y=e("input"),A=e("span"),V=e("span"),W=e("span"), | ||
X=e("span");P.className="b-tl";H.className="b-tg";y.className="c-tgl";W.className="on-i";X.className="off-i";A.className="c-tg";V.className="t-lb";P.setAttribute("aria-expanded","false");P.setAttribute("aria-controls",x);y.type="checkbox";A.setAttribute("aria-hidden","true");var va=d[n].toggle.value;y.value=va;V[f]=d[n].title;P.insertAdjacentHTML("beforeend",d[n].title);p.appendChild(P);A.appendChild(W);A.appendChild(X);a?-1<M(JSON.parse(J).level,va)?(y.checked=!0,E.push(!0)):E.push(!1):d[n].toggle.enabled&& | ||
(y.checked=!0);d[n].toggle.readonly&&(y.disabled=!0,y.setAttribute("aria-readonly","true"),C(A,"c-ro"));C(v,"b-acc");C(p,"b-bn");C(G,"b-ex");v.id=x;v.setAttribute("aria-hidden","true");H.appendChild(y);H.appendChild(A);H.appendChild(V);p.appendChild(H);(function(U,ja,wa){I(P,"click",function(){oa(ja,"act")?(ha(ja,"act"),wa.setAttribute("aria-expanded","false"),U.setAttribute("aria-hidden","true")):(C(ja,"act"),wa.setAttribute("aria-expanded","true"),U.setAttribute("aria-hidden","false"))},!1)})(v, | ||
G,P)}else x=e("div"),x.className="b-tl",x.setAttribute("role","heading"),x.setAttribute("aria-level","3"),x.insertAdjacentHTML("beforeend",d[n].title),p.appendChild(x);G.appendChild(p);v.appendChild(q);if(!0!==b.remove_cookie_tables&&"undefined"!==typeof d[n].cookie_table){H=document.createDocumentFragment();q=b.languages[F].settings_modal.cookie_table_headers;for(y=0;y<q.length;++y)A=e("th"),p=q[y],A.setAttribute("scope","col"),p&&(x=p&&Z(p)[0],A[f]=q[y][x],H.appendChild(A));p=e("tr");p.appendChild(H); | ||
x=e("thead");x.appendChild(p);H=e("table");H.appendChild(x);y=document.createDocumentFragment();for(A=0;A<d[n].cookie_table.length;A++){V=e("tr");for(W=0;W<q.length;++W)if(p=q[W])x=Z(p)[0],X=e("td"),X.insertAdjacentHTML("beforeend",d[n].cookie_table[A][x]),X.setAttribute("data-column",p[x]),V.appendChild(X);y.appendChild(V)}q=e("tbody");q.appendChild(y);H.appendChild(q);v.appendChild(H)}G.appendChild(v);w.appendChild(G)}a=e("div");f=e("button");d=e("button");a.id="s-bns";f.id="s-sv-bn";d.id="s-all-bn"; | ||
f.className="c-bn";d.className="c-bn";f.insertAdjacentHTML("beforeend",b.languages[F].settings_modal.save_settings_btn);d.insertAdjacentHTML("beforeend",b.languages[F].settings_modal.accept_all_btn);a.appendChild(d);a.appendChild(f);I(f,"click",function(){t.hideSettings();t.hide();da(b,-1)});I(d,"click",function(){t.hideSettings();t.hide();da(b,1)});m.appendChild(g);m.appendChild(r);O.appendChild(m);O.appendChild(w);O.appendChild(a);l.appendChild(O);k.appendChild(l);h.appendChild(k);D.appendChild(h); | ||
c.appendChild(D);c.appendChild(B);(za||document.body).appendChild(L)}function Ea(){function a(c,d){var f=!1,h=!1;try{for(var k=c.querySelectorAll(b.join(':not([tabindex="-1"]), ')),l,g=k.length,m=0;m<g;)l=k[m].getAttribute("data-focus"),h||"1"!==l?"0"===l&&(f=k[m],h||"0"===k[m+1].getAttribute("data-focus")||(h=k[m+1])):h=k[m],m++}catch(r){return c.querySelectorAll(b.join(", "))}d[0]=k[0];d[1]=k[k.length-1];d[2]=f;d[3]=h}var b=["[href]","button","input","details",'[tabindex="0"]'];a(O,Y);Q&&a(z,ka)} | ||
function xa(a,b){if(b.hasOwnProperty(a))return a;if(0<Z(b).length)return b.hasOwnProperty(F)?F:Z(b)[0]}function Fa(){for(var a=document.querySelectorAll('a[data-cc="c-settings"], button[data-cc="c-settings"]'),b=0;b<a.length;b++)a[b].setAttribute("aria-haspopup","dialog"),I(a[b],"click",function(c){t.showSettings(0);c.preventDefault?c.preventDefault():c.returnValue=!1})}function Ga(a){"number"===typeof a.cookie_expiration&&(sa=a.cookie_expiration);"boolean"===typeof a.autorun&&(ya=a.autorun);"string"=== | ||
typeof a.cookie_domain&&(S=a.cookie_domain);"string"===typeof a.cookie_same_site&&(ua=a.cookie_same_site);"string"===typeof a.cookie_path&&(ta=a.cookie_path);"string"===typeof a.cookie_name&&(ea=a.cookie_name);qa=!0===a.page_scripts;ra=!1!==a.page_scripts_order;if(!0===a.auto_language){var b=navigator.language||navigator.browserLanguage;2<b.length&&(b=b[0]+b[1]);F=xa(b.toLowerCase(),a.languages)}else"string"===typeof a.current_lang&&(F=xa(a.current_lang,a.languages));!0===a.force_consent&&C(T,"force--consent")} | ||
var F="en",ya=!0,ea="cc_cookie",sa=182,S=location.hostname,ta="/",ua="Lax",qa,ra,t={},J,Q=!1,R=!1,ba=!1,ia=!1,aa=!1,u,fa,la,ka=[],Y=[],E=[],T=document.documentElement,L,z,D,O;t.allowedCategory=function(a){return-1<M(JSON.parse(ca(ea,"one",!0)||"{}").level||[],a)};t.run=function(a){if(!L&&(Ga(a),J=ca(ea,"one",!0),Q=""==J,Da(!Q,a),Ca(a.theme_css,function(){Ea();Aa(a.gui_options);Fa();!J&&ya&&t.show(a.delay||0);setTimeout(function(){C(L,"c--anim")},30);setTimeout(function(){Ba()},100)}),J&&(R=!0),R&& | ||
(pa(),"function"===typeof a.onAccept)))a.onAccept(JSON.parse(J||"{}"))};t.showSettings=function(a){setTimeout(function(){C(T,"show--settings");D.setAttribute("aria-hidden","false");ia=!0;ba?la=document.activeElement:fa=document.activeElement;setTimeout(function(){0!==Y.length&&(Y[3]?Y[3].focus():Y[0].focus(),u=Y)},100)},0<a?a:0)};t.loadScript=function(a,b,c){var d="function"===typeof b;if(document.querySelector('script[src="'+a+'"]'))d&&b();else{var f=e("script");if(c&&0<c.length)for(var h=0;h<c.length;++h)c[h]&& | ||
f.setAttribute(c[h].name,c[h].value);d&&(f.readyState?f.onreadystatechange=function(){if("loaded"===f.readyState||"complete"===f.readyState)f.onreadystatechange=null,b()}:f.onload=b);f.src=a;(document.head?document.head:document.getElementsByTagName("head")[0]).appendChild(f)}};t.show=function(a){Q&&setTimeout(function(){C(T,"show--consent");z.setAttribute("aria-hidden","false");ba=!0;fa=document.activeElement;u=ka},0<a?a:0)};t.hide=function(){Q&&(ha(T,"show--consent"),z.setAttribute("aria-hidden", | ||
"true"),ba=!1,fa.focus(),u=null)};t.hideSettings=function(){ha(T,"show--settings");ia=!1;D.setAttribute("aria-hidden","true");ba?(la&&la.focus(),u=ka):(fa.focus(),u=null);aa=!1};t.validCookie=function(a){return""!=ca(a,"one",!0)};return na=window[ma]=void 0,t}var ma="initCookieConsent";"function"!==typeof window[ma]&&(window[ma]=na)})(); | ||
(function(){function ta(Ia){function ua(a,b){return a.classList?a.classList.contains(b):!!a.className.match(new RegExp("(\\s|^)"+b+"(\\s|$)"))}function ia(a,b){a.classList?a.classList.remove(b):a.className=a.className.replace(new RegExp("(\\s|^)"+b+"(\\s|$)")," ")}function E(a,b){a.classList?a.classList.add(b):ua(a,b)||(a.className+=" "+b)}function aa(a){if("object"===typeof a){var b=[],d=0;for(b[d++]in a);return b}}function F(a,b,d,e){a.addEventListener?e?a.addEventListener(b,d,{passive:!0}):a.addEventListener(b, | ||
d,!1):a.attachEvent("on"+b,d)}function va(a,b,d){b=b?b:"/";for(var e=0;e<a.length;e++)for(var c=0;c<d.length;c++)document.cookie=a[e]+"=; Path="+b+"; Domain="+d[c]+"; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"}function da(a,b,d){if("one"===b)var e=(e=document.cookie.match("(^|;)\\s*"+a+"\\s*=\\s*([^;]+)"))?d?e.pop():a:"";else if("all"===b)for(a=document.cookie.split(/;\s*/),e=[],b=0;b<a.length;b++)e.push(a[b].split("=")[0]);return e}function wa(){if(xa){var a=document.querySelectorAll("script[data-cookiecategory]"), | ||
b=ya,d=JSON.parse(C).level||[],e=function(c,h){if(h<c.length){var k=c[h],l=k.getAttribute("data-cookiecategory");if(-1<G(d,l)){k.type="text/javascript";k.removeAttribute("data-cookiecategory");l=k.getAttribute("data-src");var m=f("script");m.textContent=k.innerHTML;(function(p,t){for(var u=t.attributes,v=u.length,g=0;g<v;g++)t=u[g],p.setAttribute(t.nodeName,t.nodeValue)})(m,k);l?m.src=l:l=k.src;l&&(b?m.readyState?m.onreadystatechange=function(){if("loaded"===m.readyState||"complete"===m.readyState)m.onreadystatechange= | ||
null,e(c,++h)}:m.onload=function(){m.onload=null;e(c,++h)}:l=!1);k.parentNode.replaceChild(m,k);if(l)return}e(c,++h)}};e(a,0)}}function Ja(a){function b(e,c,h,k,l,m,p){m=m&&m.split(" ")||[];if(-1<G(c,l)&&(E(e,l),-1<G(h,m[0])))for(c=0;c<m.length;c++)E(e,m[c]);-1<G(k,p)&&E(e,p)}if("object"===typeof a){var d=a.consent_modal;a=a.settings_modal;U&&d&&b(w,["box","bar","cloud"],["top","bottom"],["zoom","slide"],d.layout,d.position,d.transition);a&&b(H,["bar"],["left","right"],["zoom","slide"],a.layout,a.position, | ||
a.transition)}}function Ka(){var a=!1,b=!1;F(document,"keydown",function(d){d=d||window.event;"Tab"===d.key&&(r&&(d.shiftKey?document.activeElement===r[0]&&(r[1].focus(),d.preventDefault()):document.activeElement===r[1]&&(r[0].focus(),d.preventDefault()),b||ba||(b=!0,!a&&d.preventDefault(),d.shiftKey?r[3]?r[2]?r[2].focus():r[0].focus():r[1].focus():r[3]?r[3].focus():r[0].focus())),!b&&(a=!0))});document.contains&&F(K,"click",function(d){d=d||window.event;ja?M.contains(d.target)?ba=!0:(n.hideSettings(0), | ||
ba=!1):ca&&w.contains(d.target)&&(ba=!0)},!0)}function f(a){var b=document.createElement(a);"button"===a&&b.setAttribute("type",a);return b}function G(a,b){for(var d=a.length,e=0;e<d;e++)if(a[e]==b)return e;return-1}function La(a,b){if("string"!==typeof a||""==a||document.getElementById("cc--style"))b();else{var d=f("style");d.id="cc--style";var e=new XMLHttpRequest;e.onreadystatechange=function(){4==this.readyState&&200==this.status&&(d.setAttribute("type","text/css"),d.styleSheet?d.styleSheet.cssText= | ||
this.responseText:d.appendChild(document.createTextNode(this.responseText)),document.getElementsByTagName("head")[0].appendChild(d),b())};e.open("GET",a);e.send()}}function Ma(a){var b=document.querySelectorAll(".c-tgl")||[],d=[],e=!1;if(0<b.length){for(var c=0;c<b.length;c++)-1!==G(a,L[c])?(b[c].checked=!0,N[c]||(d.push(L[c]),N[c]=!0)):(b[c].checked=!1,N[c]&&(d.push(L[c]),N[c]=!1));if(za&&V&&0<d.length){b=x.length;c=-1;var h=da("","all"),k=[P,"."+P];if("www."===P.slice(0,4)){var l=P.substr(4);k.push(l); | ||
k.push("."+l)}for(l=0;l<b;l++){var m=x[l];if(m.hasOwnProperty("toggle")&&!N[++c]&&m.hasOwnProperty("cookie_table")&&-1<G(d,m.toggle.value)){var p=m.cookie_table,t=aa(Q[0])[0],u=p.length;"on_disable"===m.toggle.reload&&(e=!0);for(var v=0;v<u;v++){var g=p[v],R=[],I=g[t],y=g.is_regex||!1,q=g.domain||null;g=g.path||!1;q&&(k=[q,"."+q]);if(y)for(y=0;y<h.length;y++)h[y].match(I)&&R.push(h[y]);else I=G(h,I),-1<I&&R.push(h[I]);0<R.length&&(va(R,g,k),"on_clear"===m.toggle.reload&&(e=!0))}}}}}C=JSON.stringify({level:a, | ||
revision:ka});if(!V||0<d.length)a=ea,b=C,c=new Date,c.setTime(c.getTime()+864E5*Aa),a=a+"="+(b||"")+("; expires="+c.toUTCString())+"; Path="+Ba+";",a+=" SameSite="+Ca+";",-1<location.hostname.indexOf(".")&&(a+=" Domain="+P+";"),"https:"===location.protocol&&(a+=" Secure;"),document.cookie=a;wa();if("function"===typeof la&&!V)return V=!0,la(JSON.parse(C));"function"===typeof ma&&0<d.length&&ma(JSON.parse(C),d);e&&window.location.reload()}function Na(a,b){K=f("div");K.id="cc--main";K.style.position= | ||
"fixed";K.style.zIndex="1000000";K.innerHTML='\x3c!--[if lt IE 9 ]><div id="cc_div" class="cc_div ie"></div><![endif]--\x3e\x3c!--[if (gt IE 8)|!(IE)]>\x3c!--\x3e<div id="cc_div" class="cc_div"></div>\x3c!--<![endif]--\x3e';var d=K.children[0],e=J,c="string"===typeof W.textContent?"textContent":"innerText";if(!a){w=f("div");var h=f("div"),k=f("div"),l=f("div"),m=f("div"),p=f("div"),t=f("button"),u=f("button"),v=f("div");w.id="cm";h.id="c-inr";k.id="c-inr-i";l.id="c-ttl";m.id="c-txt";p.id="c-bns"; | ||
t.id="c-p-bn";u.id="c-s-bn";v.id="cm-ov";t.className="c-bn";u.className="c-bn c_link";l.setAttribute("role","heading");l.setAttribute("aria-level","2");w.setAttribute("role","dialog");w.setAttribute("aria-modal","true");w.setAttribute("aria-hidden","false");w.setAttribute("aria-labelledby","c-ttl");w.setAttribute("aria-describedby","c-txt");w.style.visibility=v.style.visibility="hidden";v.style.opacity=0;l.insertAdjacentHTML("beforeend",b.languages[e].consent_modal.title);var g=b.languages[e].consent_modal.description; | ||
Da&&(g=fa?g.replace("{{revision_message}}",""):g.replace("{{revision_message}}",b.languages[e].consent_modal.revision_message||""));m.insertAdjacentHTML("beforeend",g);t[c]=b.languages[e].consent_modal.primary_btn.text;u[c]=b.languages[e].consent_modal.secondary_btn.text;var R;"accept_all"==b.languages[e].consent_modal.primary_btn.role&&(R="all");F(t,"click",function(){n.hide();n.accept(R)});"accept_necessary"==b.languages[e].consent_modal.secondary_btn.role?F(u,"click",function(){n.hide();n.accept([])}): | ||
F(u,"click",function(){n.showSettings(0)});k.appendChild(l);k.appendChild(m);p.appendChild(t);p.appendChild(u);h.appendChild(k);h.appendChild(p);w.appendChild(h);d.appendChild(w);d.appendChild(v)}H=f("div");h=f("div");k=f("div");l=f("div");M=f("div");m=f("div");p=f("div");g=f("button");t=f("div");u=f("div");v=f("div");H.id="s-cnt";h.id="c-vln";l.id="c-s-in";k.id="cs";m.id="s-ttl";M.id="s-inr";p.id="s-hdr";u.id="s-bl";g.id="s-c-bn";v.id="cs-ov";t.id="s-c-bnc";g.className="c-bn";g.setAttribute("aria-label", | ||
b.languages[e].settings_modal.close_btn_label||"Close");H.setAttribute("role","dialog");H.setAttribute("aria-modal","true");H.setAttribute("aria-hidden","true");H.setAttribute("aria-labelledby","s-ttl");m.setAttribute("role","heading");H.style.visibility=v.style.visibility="hidden";v.style.opacity=0;t.appendChild(g);F(h,"keydown",function(X){X=X||window.event;27==X.keyCode&&n.hideSettings(0)},!0);F(g,"click",function(){n.hideSettings(0)});x=b.languages[J].settings_modal.blocks;e=x.length;m.insertAdjacentHTML("beforeend", | ||
b.languages[J].settings_modal.title);for(g=0;g<e;++g){var I=f("div"),y=f("div"),q=f("div"),B=f("div");I.className="c-bl";y.className="desc";q.className="p";B.className="title";q.insertAdjacentHTML("beforeend",x[g].description);if("undefined"!==typeof x[g].toggle){var z="c-ac-"+g,S=f("button"),D=f("label"),A=f("input"),O=f("span"),T=f("span"),Y=f("span"),Ea=f("span");S.className="b-tl";D.className="b-tg";A.className="c-tgl";Y.className="on-i";Ea.className="off-i";O.className="c-tg";T.className="t-lb"; | ||
S.setAttribute("aria-expanded","false");S.setAttribute("aria-controls",z);A.type="checkbox";O.setAttribute("aria-hidden","true");var na=x[g].toggle.value;A.value=na;T[c]=x[g].title;S.insertAdjacentHTML("beforeend",x[g].title);B.appendChild(S);O.appendChild(Y);O.appendChild(Ea);a?-1<G(JSON.parse(C).level,na)?(A.checked=!0,N.push(!0)):N.push(!1):x[g].toggle.enabled?(A.checked=!0,N.push(!0)):N.push(!1);L.push(na);x[g].toggle.readonly?(A.disabled=!0,E(O,"c-ro"),oa.push(!0)):oa.push(!1);E(y,"b-acc");E(B, | ||
"b-bn");E(I,"b-ex");y.id=z;y.setAttribute("aria-hidden","true");D.appendChild(A);D.appendChild(O);D.appendChild(T);B.appendChild(D);(function(X,pa,Fa){F(S,"click",function(){ua(pa,"act")?(ia(pa,"act"),Fa.setAttribute("aria-expanded","false"),X.setAttribute("aria-hidden","true")):(E(pa,"act"),Fa.setAttribute("aria-expanded","true"),X.setAttribute("aria-hidden","false"))},!1)})(y,I,S)}else z=f("div"),z.className="b-tl",z.setAttribute("role","heading"),z.setAttribute("aria-level","3"),z.insertAdjacentHTML("beforeend", | ||
x[g].title),B.appendChild(z);I.appendChild(B);y.appendChild(q);if(!0!==b.remove_cookie_tables&&"undefined"!==typeof x[g].cookie_table){z=document.createDocumentFragment();Q=b.languages[J].settings_modal.cookie_table_headers;for(D=0;D<Q.length;++D)A=f("th"),q=Q[D],A.setAttribute("scope","col"),q&&(B=q&&aa(q)[0],A[c]=Q[D][B],z.appendChild(A));q=f("tr");q.appendChild(z);B=f("thead");B.appendChild(q);z=f("table");z.appendChild(B);D=document.createDocumentFragment();for(A=0;A<x[g].cookie_table.length;A++){O= | ||
f("tr");for(T=0;T<Q.length;++T)if(q=Q[T])B=aa(q)[0],Y=f("td"),Y.insertAdjacentHTML("beforeend",x[g].cookie_table[A][B]),Y.setAttribute("data-column",q[B]),O.appendChild(Y);D.appendChild(O)}q=f("tbody");q.appendChild(D);z.appendChild(q);y.appendChild(z)}I.appendChild(y);u.appendChild(I)}a=f("div");c=f("button");e=f("button");a.id="s-bns";c.id="s-sv-bn";e.id="s-all-bn";c.className="c-bn";e.className="c-bn";c.insertAdjacentHTML("beforeend",b.languages[J].settings_modal.save_settings_btn);e.insertAdjacentHTML("beforeend", | ||
b.languages[J].settings_modal.accept_all_btn);a.appendChild(e);if(b=b.languages[J].settings_modal.reject_all_btn)g=f("button"),g.id="s-rall-bn",g.className="c-bn",g.insertAdjacentHTML("beforeend",b),F(g,"click",function(){n.hideSettings();n.hide();n.accept([])}),M.className="bns-t",a.appendChild(g);a.appendChild(c);F(c,"click",function(){n.hideSettings();n.hide();n.accept()});F(e,"click",function(){n.hideSettings();n.hide();n.accept("all")});p.appendChild(m);p.appendChild(t);M.appendChild(p);M.appendChild(u); | ||
M.appendChild(a);l.appendChild(M);k.appendChild(l);h.appendChild(k);H.appendChild(h);d.appendChild(H);d.appendChild(v);(Ia||document.body).appendChild(K)}function Oa(){function a(d,e){var c=!1,h=!1;try{for(var k=d.querySelectorAll(b.join(':not([tabindex="-1"]), ')),l,m=k.length,p=0;p<m;)l=k[p].getAttribute("data-focus"),h||"1"!==l?"0"===l&&(c=k[p],h||"0"===k[p+1].getAttribute("data-focus")||(h=k[p+1])):h=k[p],p++}catch(t){return d.querySelectorAll(b.join(", "))}e[0]=k[0];e[1]=k[k.length-1];e[2]=c; | ||
e[3]=h}var b=["[href]","button","input","details",'[tabindex="0"]'];a(M,Z);U&&a(w,qa)}function Ga(a,b){if(b.hasOwnProperty(a))return a;if(0<aa(b).length)return b.hasOwnProperty(J)?J:aa(b)[0]}function Pa(){for(var a=document.querySelectorAll('a[data-cc="c-settings"], button[data-cc="c-settings"]'),b=0;b<a.length;b++)a[b].setAttribute("aria-haspopup","dialog"),F(a[b],"click",function(d){n.showSettings(0);d.preventDefault?d.preventDefault():d.returnValue=!1})}function Qa(a){"number"===typeof a.cookie_expiration&& | ||
(Aa=a.cookie_expiration);"boolean"===typeof a.autorun&&(Ha=a.autorun);"string"===typeof a.cookie_domain&&(P=a.cookie_domain);"string"===typeof a.cookie_same_site&&(Ca=a.cookie_same_site);"string"===typeof a.cookie_path&&(Ba=a.cookie_path);"string"===typeof a.cookie_name&&(ea=a.cookie_name);"function"===typeof a.onAccept&&(la=a.onAccept);"function"===typeof a.onChange&&(ma=a.onChange);"number"===typeof a.revision&&(ka=a.revision,Da=!0);!0===a.autoclear_cookies&&(za=!0);xa=!0===a.page_scripts;ya=!1!== | ||
a.page_scripts_order;if(!0===a.auto_language){var b=navigator.language||navigator.browserLanguage;2<b.length&&(b=b[0]+b[1]);J=Ga(b.toLowerCase(),a.languages)}else"string"===typeof a.current_lang&&(J=Ga(a.current_lang,a.languages));!0===a.force_consent&&E(W,"force--consent")}var J="en",Ha=!0,ea="cc_cookie",Aa=182,P=location.hostname,Ba="/",Ca="Lax",za=!0,ka=0,xa,ya,n={},C,U=!1,V=!1,ca=!1,ja=!1,ba=!1,r,Q,x,la,ma,fa,Da,ha,ra,qa=[],Z=[],N=[],L=[],oa=[],W=document.documentElement,K,w,H,M;n.allowedCategory= | ||
function(a){return-1<G(JSON.parse(da(ea,"one",!0)||"{}").level||[],a)};n.run=function(a){if(!K&&(Qa(a),C=da(ea,"one",!0),fa="number"===typeof a.revision?C?JSON.parse(C||"{}").revision===ka:!0:!0,U=!fa||""===C,Na(!U,a),La(a.theme_css,function(){Oa();Ja(a.gui_options);Pa();!Ha||C&&fa||n.show(a.delay||0);setTimeout(function(){E(K,"c--anim")},30);setTimeout(function(){Ka()},100)}),C&&(V=!0),V&&(wa(),"function"===typeof a.onAccept)))a.onAccept(JSON.parse(C||"{}"))};n.showSettings=function(a){setTimeout(function(){E(W, | ||
"show--settings");H.setAttribute("aria-hidden","false");ja=!0;setTimeout(function(){ca?ra=document.activeElement:ha=document.activeElement;0!==Z.length&&(Z[3]?Z[3].focus():Z[0].focus(),r=Z)},200)},0<a?a:0)};n.loadScript=function(a,b,d){var e="function"===typeof b;if(document.querySelector('script[src="'+a+'"]'))e&&b();else{var c=f("script");if(d&&0<d.length)for(var h=0;h<d.length;++h)d[h]&&c.setAttribute(d[h].name,d[h].value);e&&(c.readyState?c.onreadystatechange=function(){if("loaded"===c.readyState|| | ||
"complete"===c.readyState)c.onreadystatechange=null,b()}:c.onload=b);c.src=a;(document.head?document.head:document.getElementsByTagName("head")[0]).appendChild(c)}};n.show=function(a){U&&setTimeout(function(){E(W,"show--consent");w.setAttribute("aria-hidden","false");ca=!0;setTimeout(function(){ha=document.activeElement;r=qa},200)},0<a?a:0)};n.hide=function(){U&&(ia(W,"show--consent"),w.setAttribute("aria-hidden","true"),ca=!1,setTimeout(function(){ha.focus();r=null},200))};n.hideSettings=function(){ia(W, | ||
"show--settings");ja=!1;H.setAttribute("aria-hidden","true");setTimeout(function(){ca?(ra&&ra.focus(),r=qa):(ha.focus(),r=null);ba=!1},200)};n.accept=function(a,b){function d(){for(var h=document.querySelectorAll(".c-tgl")||[],k=[],l=0;l<h.length;l++)h[l].checked&&k.push(h[l].value);return k}a=a||void 0;var e=b||[];b=[];if(a)if("object"===typeof a&&"number"===typeof a.length)for(var c=0;c<a.length;c++)-1!==G(L,a[c])&&b.push(a[c]);else"string"===typeof a&&("all"===a?b=L.slice():-1!==G(L,a)&&b.push(a)); | ||
else b=d();if(1<=e.length)for(c=0;c<e.length;c++)b=b.filter(function(h){return h!==e[c]});for(c=0;c<L.length;c++)!0===oa[c]&&-1===G(b,L[c])&&b.push(L[c]);Ma(b)};n.eraseCookies=function(a,b,d){var e=[];d=d?[d,"."+d]:[P,"."+P];if(a&&0<a.length)for(var c=0;c<a.length;c++)this.validCookie(a[c])&&e.push(a[c]);else e=[a];va(e,b,d)};n.validCookie=function(a){return""!=da(a,"one",!0)};ta=window[sa]=void 0;return n}var sa="initCookieConsent";"function"!==typeof window[sa]&&(window[sa]=ta)})(); |
{ | ||
"name": "vanilla-cookieconsent", | ||
"version": "2.4.7", | ||
"version": "2.5.0", | ||
"description": "🍪 Simple cross-browser cookie-consent plugin written in vanilla js.", | ||
@@ -5,0 +5,0 @@ "main": "dist/cookieconsent.js", |
203
Readme.md
@@ -14,3 +14,3 @@ Forked to publish in the NPM registry. No further changes. Thanks and credits to [Orest Bida](https://github.com/orestbida/cookieconsent). | ||
A __lightweight__ & __gdpr compliant__ cookie consent plugin written in plain javascript. An "all-in-one" solution which also allows you to write your cookie policy inside it without the need of having a dedicated page. | ||
A __lightweight__ & __gdpr compliant__ cookie consent plugin written in plain javascript. An "all-in-one" solution which also allows you to write your cookie policy inside it without the need of having a dedicated page. | ||
@@ -25,14 +25,15 @@ </div> | ||
## Table of contents | ||
- [Table of contents](#table-of-contents) | ||
- [Key features](#key-features) | ||
- [How to use](#how-to-use) | ||
- [Download & CDN](#download--cdn) | ||
- [Layout options & customization](#layout-options--customization) | ||
- [Manage third party scripts](#manage-third-party-scripts) | ||
- [APIs & configuration parameters](#apis--configuration-parameters) | ||
- [All available options](#all-available-options) | ||
- [Full example configurations](#full-example-configurations) | ||
- [How to configure languages & cookie settings](#how-to-configure-languages--cookie-settings) | ||
- [FAQ](#faq) | ||
- [License](#license) | ||
1. [Key features](#key-features) | ||
2. [How to use](#how-to-use) | ||
3. [Download & CDN](#download--cdn) | ||
4. [Layout options & customization](#layout-options--customization) | ||
5. [APIs & config. parameters](#apis--configuration-parameters) | ||
6. [Manage third party scripts](#manage-third-party-scripts) | ||
7. [Configuration examples](#full-example-configurations) (work-in-progress) | ||
- Configuration with [Google analytics](#full-example-configurations) | ||
- Configuration with [explicit `accept all` and `accept necessary only` buttons](#explicit-consent) | ||
- Configuration with embedded full cookie-policy | ||
8. [How to enable/manage revisions](#how-to-enablemanage-revisions) | ||
9. [FAQ](#faq) | ||
10. [License](#license) | ||
@@ -42,3 +43,3 @@ ## Key features | ||
- __Cross-browser__ support (IE8+) | ||
- __Standalone__ (no external dependecies needed) | ||
- __Standalone__ (no external dependencies needed) | ||
- __GDPR compliant__ | ||
@@ -50,3 +51,3 @@ - __Support for multi language__ | ||
## How to use | ||
## How to use | ||
1. Download (or use via [cdn](#download--cdn)) and include the script at the bottom of `body` tag. | ||
@@ -91,3 +92,4 @@ ```html | ||
accept_all_btn : "Accept all", | ||
close_btn_label: "Close", | ||
reject_all_btn : "Reject all", // optional, [v.2.5.0 +] | ||
close_btn_label: "Close", | ||
blocks : [ | ||
@@ -126,4 +128,4 @@ { | ||
For more details check out [full examples](#full-example-configurations) and [how to configure languages & cookie settings](#how-to-configure-languages--cookie-settings) sections. | ||
## Download & CDN | ||
@@ -134,3 +136,3 @@ You can download the [latest version](https://github.com/orestbida/cookieconsent/releases) or use it via cdn: | ||
```html | ||
https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@v2.4.7/dist/cookieconsent.js | ||
https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@v2.5.0/dist/cookieconsent.js | ||
``` | ||
@@ -140,3 +142,3 @@ | ||
```html | ||
https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@v2.4.7/dist/cookieconsent.css | ||
https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@v2.5.0/dist/cookieconsent.css | ||
``` | ||
@@ -207,2 +209,32 @@ | ||
Additional methods for an easier management of your scripts and cookie settings (expand them to see usage example): | ||
- <details><summary>cookieconsent<code>.accept(<accepted_categories>, <optional_rejected_categories>)</code> [v2.5.0+]</summary> | ||
<p> | ||
- accepted_categories: `string` or `string[]` | ||
- rejected_categories: `string[]` - optional | ||
<br> | ||
Note: **all categories marked as `readonly` will ALWAYS be enabled/accepted regardless of the categories provided inside the `.accept()` API call.** | ||
Examples: | ||
```javascript | ||
cookieconsent.accept('all'); // accept all categories | ||
cookieconsent.accept([]); // accept none (reject all) | ||
cookieconsent.accept('analytics'); // accept only analytics category | ||
cookieconsent.accept(['cat_1', 'cat_2']); // accept only these 2 categories | ||
cookieconsent.accept(); // accept all currently selected categories inside modal | ||
cookieconsent.accept('all', ['analytics']); // accept all except "analytics" category | ||
cookieconsent.accept('all', ['cat_1', 'cat_2']); // accept all except these 2 categories | ||
``` | ||
How to later reject a specific category (cookieconsent already accepted)? Same as above: | ||
```javascript | ||
cookieconsent.accept('all', ['targeting']); // opt out of targeting category | ||
``` | ||
</p> | ||
</details> | ||
- <details><summary>cookieconsent<code>.allowedCategory(<category_name>)</code></summary> | ||
@@ -217,3 +249,3 @@ <p> | ||
```javascript | ||
... | ||
... | ||
toggle : { | ||
@@ -250,2 +282,22 @@ value: 'analytics', // cookie category | ||
</details> | ||
- <details><summary>cookieconsent<code>.eraseCookies(<cookie_names>, <optional_path>, <optional_domains>)</code> [v2.5.0+]</summary> | ||
<p> | ||
- cookie_names: `string[]` | ||
- path: `string` - optional | ||
- domains: `string[]` - optional | ||
<br> | ||
Examples: | ||
```javascript | ||
cookieconsent.eraseCookies(['cc_cookies']); // erase "cc_cookie" if it exists | ||
cookieconsent.eraseCookies(['cookie1', 'cookie2']); // erase these 2 cookies | ||
cookieconsent.eraseCookies(['cc_cookie'], "/demo"); | ||
cookieconsent.eraseCookies(['cc_cookie'], "/demo", [location.hostname]); | ||
``` | ||
</p> | ||
</details> | ||
- <details><summary>cookieconsent<code>.loadScript(<path>, <callback_function>, <optional_custom_attributes>)</code></summary> | ||
@@ -286,2 +338,3 @@ <p> | ||
| `force_consent` | boolean | false | Enable if you want to block page navigation until user action (check [faq](#faq) for a proper implementation) | | ||
| `revision` | number | 0 | Specify this option to enable revisions. [Check below](#how-to-enablemanage-revisions) for a proper usage | | ||
| `current_lang` | string | - | Specify one of the languages you have defined (can also be dynamic): `'en'`, `'de'` ... | | ||
@@ -293,4 +346,4 @@ | `auto_language` | boolean | false | Automatically grab the language based on the user's browser language, if language is not defined => use specified `current_lang` | | ||
| `gui_options` | object | - | Customization option which allows to choose layout, position and transition. Check [layout options & customization](#layout-options--customization) | | ||
| __`onAccept`__ | function | - | Method run `once` either when: <br> 1. The moment the cookie consent is accepted <br> 2. After each page load (if cookie consent has alredy been accepted) | | ||
| __`onChange`__ | function | - | Method run `whenever preferences are modified` (and only if cookie consent has alredy been accepted) | | ||
| __`onAccept`__ | function | - | Method run `once` either when: <br> 1. The moment the cookie consent is accepted <br> 2. After each page load (if cookie consent has already been accepted) | | ||
| __`onChange`__ | function | - | Method run `whenever preferences are modified` (and only if cookie consent has already been accepted) | | ||
| `languages` | object | - | [Check below](#how-to-configure-languages--cookie-settings) for configuration | ||
@@ -308,9 +361,9 @@ | ||
cc.run({ | ||
autorun : true, | ||
autorun : true, | ||
delay : 0, | ||
current_lang : 'en', | ||
theme_css : "../src/cookieconsent.css", | ||
autoclear_cookies : true, | ||
theme_css : "../src/cookieconsent.css", | ||
autoclear_cookies : true, | ||
cookie_expiration : 365, | ||
gui_options : { | ||
@@ -327,6 +380,6 @@ consent_modal : { | ||
}, | ||
onAccept: function(cookies){ | ||
onAccept: function(cookies){ | ||
if(cc.allowedCategory('analytics_cookies')){ | ||
cc.loadScript('https://www.google-analytics.com/analytics.js', function(){ | ||
cc.loadScript('https://www.google-analytics.com/analytics.js', function(){ | ||
ga('create', 'UA-XXXXXXXX-Y', 'auto'); //replace UA-XXXXXXXX-Y with your tracking code | ||
@@ -337,5 +390,5 @@ ga('send', 'pageview'); | ||
}, | ||
languages : { | ||
en : { | ||
en : { | ||
consent_modal : { | ||
@@ -357,7 +410,8 @@ title : "I use cookies", | ||
accept_all_btn : "Accept all", | ||
reject_all_btn : "Reject all", // optional, [v.2.5.0 +] | ||
cookie_table_headers : [ | ||
{col1: "Name" }, | ||
{col2: "Domain" }, | ||
{col3: "Expiration" }, | ||
{col4: "Description" }, | ||
{col1: "Name" }, | ||
{col2: "Domain" }, | ||
{col3: "Expiration" }, | ||
{col4: "Description" }, | ||
{col5: "Type" } | ||
@@ -379,3 +433,3 @@ ], | ||
title : "Analytics cookies", | ||
description: 'These cookies ollect information about how you use the website, which pages you visited and which links you clicked on. All of the data is anonymized and cannot be used to identify you.', | ||
description: 'These cookies collect information about how you use the website, which pages you visited and which links you clicked on. All of the data is anonymized and cannot be used to identify you.', | ||
toggle : { | ||
@@ -558,2 +612,3 @@ value : 'analytics_cookies', | ||
accept_all_btn : "Accept all", | ||
reject_all_btn: "Reject all", // optional, [v.2.5.0 +] | ||
blocks : [ | ||
@@ -589,4 +644,41 @@ { | ||
## How to enable/manage revisions | ||
- default revision number is 0 | ||
- if saved revision number inside the existing cookie is different from the one you just specified => consent modal will be shown. | ||
1. Enable revisions by specifying a valid `revision` parameter: | ||
```javascript | ||
cookieconsent.run({ | ||
... | ||
revision: 1, | ||
... | ||
}) | ||
``` | ||
2. Set a valid `revision_message` parameter (optional) inside `consent_modal`, and put the following placeholder `{{revision_message}}` somewhere inside `description`: | ||
```javascript | ||
cookieconsent.run({ | ||
... | ||
revision: 1, | ||
... | ||
languages : { | ||
en : { | ||
consent_modal : { | ||
... | ||
description: "Usual description ... {{revision_message}}", | ||
revision_message: "<br> Dude, my terms have changed. Sorry for bothering you again!", | ||
... | ||
}, | ||
... | ||
} | ||
} | ||
... | ||
}) | ||
``` | ||
## FAQ | ||
@@ -671,3 +763,3 @@ - <details><summary>How to enable dark-mode</summary> | ||
... | ||
theme_css : "../src/cookieconsent.css", | ||
theme_css : "../src/cookieconsent.css", | ||
... | ||
@@ -679,5 +771,28 @@ }); | ||
</details> | ||
- <details><summary>How to add a "reject all" button inside settings modal</summary> | ||
<p id="add-reject-all-btn"> | ||
You need to specify `reject_all_btn` inside `settings_modal`: | ||
```javascript | ||
cookieconsent.run({ | ||
... | ||
languages : { | ||
en : { | ||
... | ||
settings_modal : { | ||
... | ||
reject_all_btn : "Reject all", | ||
... | ||
} | ||
} | ||
} | ||
}) | ||
``` | ||
</p> | ||
</details> | ||
- <details><summary>Make consent required (block page navigation until action)</summary> | ||
<p> | ||
This is a css only solution: | ||
@@ -689,3 +804,3 @@ | ||
... | ||
force_consent : true, | ||
force_consent : true, | ||
... | ||
@@ -714,3 +829,3 @@ }); | ||
<br> | ||
1. Specify the table structure via the `cookie_table_headers` property inside `settings_modal` object: | ||
@@ -723,5 +838,5 @@ | ||
cookie_table_headers : [ | ||
{col1: "Name" }, | ||
{col2: "Source" }, | ||
{col3: "Description" }, | ||
{col1: "Name" }, | ||
{col2: "Source" }, | ||
{col3: "Description" }, | ||
] | ||
@@ -749,3 +864,3 @@ ... | ||
``` | ||
**Check the examples above for a valid implementation.** | ||
@@ -752,0 +867,0 @@ </p> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
417508
3503
845