First draft.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
(function () {
|
||||
var KEY = 'cookie_consent';
|
||||
var banner = document.getElementById('cookie-banner');
|
||||
if (!banner) return;
|
||||
updateStatus();
|
||||
|
||||
var consent = localStorage.getItem(KEY);
|
||||
if (!consent) banner.style.display = 'flex';
|
||||
|
||||
function dismiss() {
|
||||
banner.classList.add('fade-out');
|
||||
setTimeout(function () { banner.style.display = 'none'; }, 500);
|
||||
}
|
||||
|
||||
function updateStatus() {
|
||||
var el = document.getElementById('cookie-status');
|
||||
if (!el) return;
|
||||
var consent = localStorage.getItem(KEY);
|
||||
el.textContent = consent === 'accepted' ? el.dataset.accepted
|
||||
: consent === 'declined' ? el.dataset.declined
|
||||
: el.dataset.none;
|
||||
}
|
||||
|
||||
document.getElementById('cookie-accept').onclick = function () {
|
||||
localStorage.setItem(KEY, 'accepted');
|
||||
updateStatus();
|
||||
dismiss();
|
||||
window.dispatchEvent(new Event('cookieAccepted'));
|
||||
};
|
||||
|
||||
document.getElementById('cookie-decline').onclick = function () {
|
||||
localStorage.setItem(KEY, 'declined');
|
||||
updateStatus();
|
||||
dismiss();
|
||||
};
|
||||
|
||||
window.reopenCookieBanner = function () {
|
||||
localStorage.removeItem(KEY);
|
||||
updateStatus();
|
||||
banner.classList.remove('fade-out');
|
||||
banner.style.display = 'flex';
|
||||
};
|
||||
|
||||
window.addEventListener('cookieAccepted', function () {
|
||||
if (typeof window.trackVisit === 'function') window.trackVisit();
|
||||
});
|
||||
|
||||
if (localStorage.getItem(KEY) === 'accepted') {
|
||||
if (typeof window.trackVisit === 'function') window.trackVisit();
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user