|
// Creare's 'Implied Consent' EU Cookie Law Banner v:2.4 |
|
// Conceived by Robert Kent, James Bavington & Tom Foyster |
|
|
|
// Creare's 'Implied Consent' EU Cookie Law Banner v:2.4 |
|
// Conceived by Robert Kent, James Bavington & Tom Foyster |
|
// Updated by Naomi Spirit - 23 May 2017 - to add animation slide in & out |
|
// |
|
|
|
var dropCookie = true; // false disables the Cookie, allowing you to style the banner |
|
var cookieDuration = 365; // Number of days before the cookie expires, and the banner reappears |
|
var cookieName = 'complianceCookie'; // Name of our cookie |
|
var cookieValue = 'on'; // Value of cookie |
|
var cookieDivHeight = 30; // Provide the height of the cookie div as per your own implementation |
|
|
|
|
|
window.onload = function(){ |
|
if(checkCookie(window.cookieName) != window.cookieValue){ |
|
createDiv(); |
|
} |
|
} |
|
|
|
function createDiv(){ |
|
var bodytag = document.getElementsByTagName('body')[0]; |
|
var div = document.createElement('div'); |
|
div.setAttribute('id','cookie-law'); |
|
div.innerHTML = '<p>Our website uses cookies. You can find out more about how we use these in our <a href="cookie-policy.html" rel="nofollow" title="Privacy & Cookies Policy">privacy and cookies policy</a>. <a class="close-cookie-banner" href="javascript:void(0);" onclick="initRemoval();"<span>Accept</span></a></p>'; |
|
// |
|
bodytag.insertBefore(div,bodytag.firstChild); // Adds the Cookie Law Banner just after the opening <body> tag |
|
|
|
slideIn(div); //initiates slidein Animation |
|
|
|
document.getElementsByTagName('body')[0].className+=' cookiebanner'; //Adds a class tothe <body> tag when the banner is visible |
|
} |
|
|
|
function createCookie(name,value,days) { |
|
if (days) { |
|
var date = new Date(); |
|
date.setTime(date.getTime()+(days*24*60*60*1000)); |
|
var expires = "; expires="+date.toGMTString(); |
|
} |
|
else var expires = ""; |
|
if(window.dropCookie) { |
|
document.cookie = name+"="+value+expires+"; path=/"; |
|
} |
|
} |
|
|
|
function checkCookie(name) { |
|
var nameEQ = name + "="; |
|
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,c.length); |
|
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); |
|
} |
|
return null; |
|
} |
|
|
|
function eraseCookie(name) { |
|
createCookie(name,"",-1); |
|
} |
|
|
|
|
|
function slideIn(){ |
|
var element = document.getElementById('cookie-law'); |
|
element.style.top = -cookieDivHeight; |
|
var topposition = -cookieDivHeight; |
|
var id = setInterval(frame, 10); |
|
function frame(){ |
|
if (topposition >= 0){ |
|
clearInterval(id); |
|
}else{ |
|
topposition ++; |
|
element.style.top = topposition; |
|
} |
|
} |
|
} |
|
function slideOut(){ |
|
var element = document.getElementById('cookie-law'); |
|
var topposition = 0; |
|
var id = setInterval(frame, 10); |
|
function frame(){ |
|
if (topposition <= -cookieDivHeight){ |
|
clearInterval(id); |
|
deleteMe(element); |
|
}else{ |
|
topposition --; |
|
element.style.top = topposition; |
|
} |
|
} |
|
} |
|
|
|
function initRemoval(){ |
|
createCookie(window.cookieName,window.cookieValue, window.cookieDuration); // Create the cookie |
|
// |
|
slideOut(); |
|
|
|
} |
|
|
|
function deleteMe(element){ |
|
element.parentNode.removeChild(element); |
|
} |
Updated to add in a slide in as the page loads, and a slide out once the policy has been accepted.
I have also maintained a previous change to save cookie only once the user has agreed to accept the policy.
I may add a session cookie so that the browser knows if the slide out animation has already happened as the user browses to other pages so that it doesn't slide out on every page.