Skip to content

Instantly share code, notes, and snippets.

@kirillrocks
Created October 22, 2018 07:37
Show Gist options
  • Save kirillrocks/3f7757719b5eb77e9c9b23568b4f3f02 to your computer and use it in GitHub Desktop.
Save kirillrocks/3f7757719b5eb77e9c9b23568b4f3f02 to your computer and use it in GitHub Desktop.
<script>
window.gdprText = {
"disclaimer_txt_main": "By continuing to use this site, you agree to the use of cookies. You can change this and find our more through our Privacy policy",
"disclaimer_txt_link": "More info",
"disclaimer_link": "/privacy-policy/",
"disclaimer_txt_btn": "Got it!"
};
var GDPR=function(){window.gdprText=window.gdprText||{disclaimer_txt_main:"By continuing to use this site, you agree to the use of cookies. You can change this and find our more through our Privacy policy",disclaimer_txt_link:"More info",disclaimer_link:"/gdpr-disclaimer",disclaimer_txt_btn:"Got it!"};var _buildhtml=function(data,isP){var html='<div class="cookie_disclaimer">'+data.disclaimer_txt_main+' <a href="'+data.disclaimer_link+'">'+data.disclaimer_txt_link+'</a></div><span class="gotit'+(isP?" btn":"")+'">'+data.disclaimer_txt_btn+"</span>";var css="<style>.cookie_notice{background:#fff;background-color:rgba(255,255,255,0.95);padding:15px;font-size:16px;line-height:1.375;position:fixed;bottom:0;left:0;width:100%;z-index:100;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-transition:-webkit-transform 0.2s ease;transition:transform 0.2s ease;box-shadow:0 -2px 35.3px 21.7px rgba(0,0,0,0.15)}.cookie_notice.closed{-webkit-transform:translateY(100%);-ms-transform:translateY(100%);transform:translateY(100%);-webkit-transition:-webkit-transform 0.2s ease;transition:transform 0.2s ease}.cookie_notice .cookie_disclaimer{width:990px;-webkit-box-flex:0;-webkit-flex:0 1 auto;-ms-flex:0 1 auto;flex:0 1 auto}.cookie_notice .cookie_disclaimer a{text-decoration:none;border:none;outline:none}.cookie_notice .cookie_disclaimer a:hover{text-decoration:underline}.cookie_notice .gotit{width:auto;height:auto;font-size:18px;line-height:41px;text-align:center;cursor:pointer;margin-left:15px;-webkit-box-flex:0;padding:0 1em;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;-webkit-box-flex:0;flex:0 0 auto;-webkit-transition:all 0.2s ease;transition:all 0.2s ease;box-sizing:content-box}.cookie_notice .gotit:not(.btn){background-color:#686b73;color:#ffffff}.cookie_notice .gotit:not(.btn):hover{background-color:#43454a}.cookie_notice .gotit:hover{-webkit-transition:all 0.2s ease;transition:all 0.2s ease}@media (max-width: 767px){.cookie_notice{font-size:11px}.cookie_notice .gotit{line-height:32px;font-size:14px;font-weight:600}}</style>";if(!isP){document.body.insertAdjacentHTML("beforeend",'<div class="cookie_notice closed"></div>')}var htmlString=html+css;var cn=document.getElementsByClassName("cookie_notice")[0];cn.insertAdjacentHTML("beforeend",htmlString);var closeBtn=cn.querySelector(".gotit");closeBtn.addEventListener("click",function(e){this.parentNode.classList.add("closed");GDPR.save();setTimeout(function(){var cn=document.getElementsByClassName("cookie_notice")[0];cn.parentNode.removeChild(cn)},500)});setTimeout(function(){cn.classList.remove("closed")},1500)};var _isClosedByUser=function(){if(localStorage.getItem("GDPR")){var expDate=parseInt(localStorage.getItem("GDPR"));var now=parseInt(_timeStamp());if(now-expDate>7884e6){localStorage.removeItem("GDPR");return false}else{return true}}else{return false}};var save=function(){localStorage.setItem("GDPR",_timeStamp())};var _timeStamp=function(){return(new Date).getTime().toString()};var init=function(){if(!_isClosedByUser()){var cn=document.getElementsByClassName("cookie_notice")[0];if(cn){var gdprText=JSON.parse(cn.getAttribute("data-text"));_buildhtml(gdprText,true)}else{_buildhtml(window.gdprText,false)}}};document.addEventListener("DOMContentLoaded",function(event){GDPR.init()});return{init:init,save:save}}();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment