Skip to content

Instantly share code, notes, and snippets.

@trys
Created July 23, 2018 18:43
Show Gist options
  • Save trys/b10819f753bd801c04edbc95f0d5b7da to your computer and use it in GitHub Desktop.
Save trys/b10819f753bd801c04edbc95f0d5b7da to your computer and use it in GitHub Desktop.
(function(key, maxWidth, padding, bg, color, url) {
var load = function (load) {
if (localStorage.getItem(key)) return;
var cookieBar = document.createElement('aside');
var size = window.innerWidth > 600 ? '15' : '12';
cookieBar.innerHTML = '<div style="max-width: ' + maxWidth + 'px; margin: 0 auto; position: relative;"><p style="width: calc(100% - 40px); max-width: 1025px; margin: 0; font-size: ' + size + 'px; line-height: 1.375;">By browsing this site, you are agreeing to our use of cookies. <a href="' + url + '" style="color: inherit; text-decoration: underline; margin-right: 10px;">Our Privacy Policy.</a></p><button style="background: none; border: none; box-shadow: none; padding: 0; cursor: pointer; position: absolute; right: 0; top: 0;" aria-label="Close cookie message" type="button"><svg width="16" height="15" viewBox="0 0 16 15" xmlns="http://www.w3.org/2000/svg"><g stroke="' + color + '" fill="none" fill-rule="evenodd" stroke-linecap="square"><path d="M.5.5l14.04 14.04M.5 14.5L14.54.46"/></g></svg></button></div>';
cookieBar.style.cssText = 'color: ' + color + '; background: ' + bg + '; z-index: 100; padding: 15px ' + padding + 'px; box-sizing: border-box; position: fixed; width: 100%; right: 0; bottom: 0;';
var accept = function() {
localStorage.setItem(key, 1);
cookieBar.parentNode.removeChild(cookieBar);
}
cookieBar.querySelector('button').addEventListener('click', accept);
cookieBar.querySelector('a').addEventListener('click', accept);
document.body.appendChild(cookieBar);
}
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") load();
else document.addEventListener('DOMContentLoaded', load);
})('seen_the_cookie_bars', 938, 20, 'rgba(0, 0, 0, 0.8)', '#FFFFFF', '/privacy');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment