Skip to content

Instantly share code, notes, and snippets.

@palicko
Created June 15, 2016 17:46
Show Gist options
  • Save palicko/c2e2ea9404bc0f8b07516d61270b2adf to your computer and use it in GitHub Desktop.
Save palicko/c2e2ea9404bc0f8b07516d61270b2adf to your computer and use it in GitHub Desktop.
EU cookies
.eu-cookies {
padding-top: rem-calc(10);
padding-bottom: rem-calc(10);
position: fixed;
left: 0;
bottom: 0;
width: 100%;
color: #fff;
background-color: #000;
z-index: 1000;
display: none;
&-agree {
margin-bottom: 0;
margin-left: rem-calc(15);
padding: rem-calc(10) rem-calc(15);
font-size: rem-calc(13);
}
&-text {
@include grid-row();
margin-bottom: 0;
font-size: rem-calc(12);
}
a {
color: #fff;
&:hover {
text-decoration: underline;
}
}
}
/**
* By www.webikon.sk
*
* Cookies javascript
*/
(function($) {
// show cookies html when eu cookie was not yet accepted
$('.js-cookies-agree').click(function() {
var date = new Date();
date.setFullYear(date.getFullYear() + 10);
document.cookie = 'eu-cookies=1; path=/; expires=' + date.toGMTString();
$('.eu-cookies').hide();
});
if ( ! getCookie('eu-cookies') ) {
$('.eu-cookies').show();
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
}
})(jQuery);
<div class="eu-cookies">
<p class="eu-cookies-text">
<?php _e( 'This internet website uses cookie files for the purposes of providing services, adjusting advertisements, and analysing website data. By using this website, you also acknowledge that you consent to the use of cookies.', 'textdomain' ); ?>
<button class="eu-cookies-agree js-cookies-agree"><?php _e( 'OK', 'textdomain' ); ?></button>
</p>
</div>
<noscript><style>.eu-cookies { display:none }</style></noscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment