cookie-notice
Version:
A very simple configurable and small (4.5kb / 2kB gzipped) vanilla JS lib with out of the box multi language support [it, en, fr, pt, es, nl, de, pl] for GDPR/DSGVO and notification purposes
3 lines (2 loc) • 4.75 kB
JavaScript
/*! cookie-notice v1.3.9 by Alessandro Benoit, Bernhard Behrendt 2021-12-09 */
!function(){"use strict";var c,l,u={messageLocales:{it:"Utilizziamo i cookie per essere sicuri che tu possa avere la migliore esperienza sul nostro sito. Se continui ad utilizzare questo sito assumiamo che tu ne sia felice.",en:"We use cookies to ensure that you have the best experience on our website. If you continue to use this site we assume that you accept this.",fr:"Nous utilisons des cookies afin d'être sûr que vous pouvez avoir la meilleure expérience sur notre site. Si vous continuez à utiliser ce site, nous supposons que vous acceptez.",pt:"Utilizamos cookies para garantir que você tenha a melhor experiência em nosso site. Se você continuar a usar este site, assumimos que você aceita isso.",es:"Utilizamos cookies para asegurarnos de que usted tenga la mejor experiencia en nuestro sitio web. Si continúa usando este sitio, asumimos que lo acepta.",nl:"We gebruiken cookies om ervoor te zorgen dat u de beste ervaring heeft op onze website. Als u deze site blijft gebruiken, gaan we ervan uit dat u dit accepteert.",pl:"Używamy plików cookie w celu zapewnienia najlepszych doświadczeń na naszej stronie internetowej. Jeśli będziesz nadal korzystać z tej strony, zakładamy, że to akceptujesz.",de:"Wir verwenden Cookies, um sicherzustellen, dass Sie die beste Erfahrung auf unserer Website machen können. Wenn Sie diese Website weiterhin nutzen, gehen wir davon aus, dass Sie dies akzeptieren."},cookieNoticePosition:"bottom",learnMoreLinkEnabled:!1,learnMoreLinkHref:"/cookie-banner-information.html",learnMoreLinkText:{it:"Saperne di più",en:"Learn more",fr:"En savoir plus",pt:"Saber mais",es:"Aprende más.",nl:"Meer informatie",pl:"Dowiedz się więcej",de:"Mehr erfahren"},buttonLocales:{en:"OK"},expiresIn:30,fontFamily:"inherit",fontSize:"12px",buttonBgColor:"#ca5000",buttonTextColor:"#fff",noticeBgColor:"#000",noticeTextColor:"#fff",linkColor:"#009fdd",linkBgColor:"#000",linkTarget:"_blank",debug:!1};function d(e){var t=(navigator.userLanguage||navigator.language).substr(0,2);return e[t]||e.en}document.addEventListener("DOMContentLoaded",function(){c||new cookieNoticeJS}),window.cookieNoticeJS=function(){if(void 0===c&&(c=this,-1==document.cookie.indexOf("cookie_notice"))){var t=document.querySelector("script[ data-cookie-notice ]");try{o=t?JSON.parse(t.getAttribute("data-cookie-notice")):{}}catch(e){console.error("data-cookie-notice JSON error:",t,e),o={}}var n=function e(t,o){for(var i in o)o.hasOwnProperty(i)&&("object"==typeof t[i]?t[i]=e(t[i],o[i]):t[i]=o[i]);return t}(u,arguments[0]||o||{});n.debug&&console.warn("cookie-notice:",n);var e,o,i,r=function(e,t,o,i,n,r){var a=document.createElement("div"),s=a.style,c="28px",u=parseInt(c,10)+20;n=void 0!==n?n:"12px",a.innerHTML=e+" ",a.setAttribute("id","cookieNotice"),a.setAttribute("data-test-section","cookie-notice"),a.setAttribute("data-test-transitioning","false"),s.position="fixed","top"===r?(r=document.querySelector("body"),l=r.style.paddingTop,s.top="0",r.style.paddingTop=u+"px"):s.bottom="0";s.left="0",s.right="0",s.background=t,s.color=o,s["z-index"]="999",s.padding="10px 5px",s["text-align"]="center",s["font-size"]=n,s["line-height"]=c,i&&(s.fontFamily=i);return a}(d(n.messageLocales),n.noticeBgColor,n.noticeTextColor,n.fontFamily,n.fontSize,n.cookieNoticePosition);n.learnMoreLinkEnabled&&(a=d(n.learnMoreLinkText),e=a,t=n.learnMoreLinkHref,o=n.linkTarget,i=n.linkColor,n.linkBgColor,s=document.createElement("a"),a=s.style,s.href=t,s.textContent=e,s.title=e,s.target=o,s.className="learn-more",s.setAttribute("data-test-action","learn-more-link"),a.color=i,a.backgroundColor="transparent",a["text-decoration"]="underline",a.display="inline",i=s);var a=function(e,t,o,i){var n=document.createElement("span"),r=n.style;n.href="#",n.innerHTML=e,n.setAttribute("role","button"),n.className="confirm",n.setAttribute("data-test-action","dismiss-cookie-notice"),r.background=t,r.color=o,r["text-decoration"]="none",r.cursor="pointer",r.display="inline-block",r.padding="0 15px",r.margin="0 0 0 10px",i&&(r.fontFamily=i);return n}(d(n.buttonLocales),n.buttonBgColor,n.buttonTextColor,n.fontFamily);a.addEventListener("click",function(e){var t,o,i;e.preventDefault(),t=60*parseInt(n.expiresIn+"",10)*1e3*60*24,o=new Date,(e=new Date).setTime(o.getTime()+t),document.cookie="cookie_notice=1; expires="+e.toUTCString()+"; path=/;",(i=r).style.opacity=1,i.setAttribute("data-test-transitioning","true"),function e(){(i.style.opacity-=.1)<.01?(void 0!==l&&(document.querySelector("body").style.paddingTop=l),document.body.removeChild(i)):setTimeout(e,40)}()});var s=document.body.appendChild(r);i&&s.appendChild(i),s.appendChild(a)}}}();