First draft.

This commit is contained in:
2026-06-14 11:14:34 +02:00
parent c1b8e161fc
commit cb07db14dc
10 changed files with 269 additions and 1 deletions
+51
View File
@@ -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();
}
})();
+24
View File
@@ -0,0 +1,24 @@
(function () {
function trackVisit() {
var banner = document.getElementById('cookie_banner');
if (!banner) return;
var matomoUrl = banner.dataset.matomoUrl;
var siteId = banner.dataset.matomoSiteId;
if (!matomoUrl || !siteId) return;
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
_paq.push(['setTrackerUrl', matomoUrl + 'matomo.php']);
_paq.push(['setSiteId', siteId]);
var d = document, g = d.createElement('script'),
s = d.getElementsByTagName('script')[0];
g.async = true; g.src = matomoUrl + 'matomo.js';
s.parentNode.insertBefore(g, s);
}
window.addEventListener('cookieAccepted', trackVisit);
if (localStorage.getItem('cookie_consent') === 'accepted') {
trackVisit();
}
})();
+39
View File
@@ -0,0 +1,39 @@
#cookie-banner {
position: fixed;
top: 2.5rem;
left: 50%;
transform: translateX(-50%);
width: min(480px, calc(100vw - 2rem));
background: #fff;
border: 1px solid #e2e2e2;
border-radius: 12px;
padding: 1rem 1.25rem;
box-shadow: 0 4px 24px rgba(0,0,0,.08);
display: flex;
align-items: center;
gap: 1rem;
z-index: 9999;
transition: opacity 0.5s ease;
}
#cookie-banner.fade-out {
opacity: 0;
pointer-events: none;
}
#cookie-banner p { margin: 0; font-size: 14px; flex: 1; }
#cookie-banner button {
margin: 0.1rem 0;
padding: .45rem 1rem;
border-radius: 8px;
border: 1px solid #ccc;
cursor: pointer;
font-size: 13px;
white-space: nowrap;
}
#cookie-accept {
background: #0b913a; color: #fff; border-color: #1a1a1a;
}