|
(function ($) { |
|
|
|
$(document).ready(function () { |
|
/** |
|
* CookiePolicy handles the displaying of a cookie banner |
|
* If policy is accepted, we set a cookie and hide the banner on subsequent visits |
|
* Otherwise we display the banner |
|
*/ |
|
var CookiePolicy = { |
|
cookieKey: 'accepted', |
|
cookieValue: 'true', |
|
bannerText: '<div class=grid-container><div class=grid-100><p>By using this website, you consent to the use of cookies in accordance with the <a href="/privacy-policy">cookie policy</a>.</p><a class="accept" href="#">Hide notice</a></div></div>', |
|
bannerContainer: '<aside class="cookie-policy"></aside>', |
|
page: $('.hfeed.page'), |
|
// If true, it'll display the banner every time you visit a page |
|
debug: true, |
|
|
|
init: function () { |
|
// If the cookie exists, do nothing |
|
if (Cookies.get(this.cookieKey) && !this.debug) { |
|
return; |
|
} |
|
|
|
// Used if debug === true |
|
this.deleteCookie(); |
|
|
|
// Otherwise, show the banner |
|
this.showCookieBanner(); |
|
}, |
|
|
|
// Shows the banner and sets up the event for hiding it |
|
showCookieBanner: function () { |
|
this.page.prepend(this.bannerContainer); |
|
var $bannerContainer = $('.cookie-policy'); |
|
|
|
$bannerContainer.html(this.bannerText); |
|
|
|
setTimeout(function () { |
|
$bannerContainer.addClass('is-visible'); |
|
}, 700); |
|
|
|
|
|
$('.cookie-policy .accept').on('click', CookiePolicy.cookieAccepted); |
|
}, |
|
|
|
cookieAccepted: function () { |
|
Cookies.set(CookiePolicy.cookieKey, CookiePolicy.cookieValue); |
|
CookiePolicy.hideBanner(); |
|
}, |
|
|
|
hideBanner: function () { |
|
// Transitions handled by CSS |
|
var $policy = $('.cookie-policy') |
|
.removeClass('is-visible'); |
|
|
|
setTimeout(function () { |
|
$policy.remove(); |
|
}, 600); |
|
}, |
|
|
|
deleteCookie: function () { |
|
Cookies.expire(this.cookieKey); |
|
} |
|
}; |
|
|
|
|
|
if (Cookies.enabled) { |
|
CookiePolicy.init(); |
|
} |
|
}); |
|
|
|
}(jQuery)); |