// Cookie Banner Functionality let cookieBannerElement = null; function createCookieBanner() { const cookieBanner = document.createElement('div'); cookieBanner.id = 'cookie-banner'; cookieBanner.className = 'fixed bottom-0 left-0 right-0 bg-white border-t border-gray-200 shadow-2xl z-50 transform translate-y-0 transition-transform duration-500'; cookieBanner.innerHTML = `

Wir verwenden Cookies

Diese Website verwendet Cookies, um Ihnen die bestmögliche Nutzererfahrung zu bieten. Durch die weitere Nutzung der Website stimmen Sie der Verwendung von Cookies zu. Mehr erfahren

`; return cookieBanner; } function showCookieBanner() { if (!cookieBannerElement) { cookieBannerElement = createCookieBanner(); document.body.appendChild(cookieBannerElement); // Add event listeners document.getElementById('cookie-accept').addEventListener('click', acceptAllCookies); document.getElementById('cookie-decline').addEventListener('click', declineAllCookies); document.getElementById('cookie-settings').addEventListener('click', showCookieSettings); } // Show banner with animation setTimeout(() => { cookieBannerElement.classList.remove('translate-y-full'); }, 100); } function hideCookieBanner() { if (cookieBannerElement) { cookieBannerElement.classList.add('translate-y-full'); setTimeout(() => { if (cookieBannerElement && cookieBannerElement.parentNode) { cookieBannerElement.parentNode.removeChild(cookieBannerElement); cookieBannerElement = null; } }, 500); } } function acceptAllCookies() { localStorage.setItem('cookies-accepted', 'true'); localStorage.setItem('cookies-necessary', 'true'); localStorage.setItem('cookies-analytics', 'true'); localStorage.setItem('cookies-marketing', 'true'); // Enable all cookie types here console.log('All cookies accepted'); hideCookieBanner(); } function declineAllCookies() { localStorage.setItem('cookies-accepted', 'false'); localStorage.setItem('cookies-necessary', 'true'); // Always true localStorage.setItem('cookies-analytics', 'false'); localStorage.setItem('cookies-marketing', 'false'); // Disable non-essential cookies here console.log('Non-essential cookies declined'); hideCookieBanner(); } function showCookieSettings() { // Create and show cookie settings modal const modal = document.createElement('div'); modal.id = 'cookie-settings-modal'; modal.className = 'fixed inset-0 bg-black bg-opacity-50 z-[60] flex items-center justify-center p-4'; modal.innerHTML = `

Cookie-Einstellungen

Notwendige Cookies

Diese Cookies sind für die ordnungsgemäße Funktion der Website erforderlich und können nicht deaktiviert werden.

Analyse-Cookies

Diese Cookies helfen uns, die Website-Nutzung zu verstehen und zu verbessern.

Marketing-Cookies

Diese Cookies ermöglichen es uns, Ihnen relevante Werbung und personalisierte Inhalte anzuzeigen.

`; document.body.appendChild(modal); // Add event listeners for modal document.getElementById('close-cookie-settings').addEventListener('click', closeCookieSettings); document.getElementById('save-cookie-settings').addEventListener('click', saveCookieSettings); document.getElementById('accept-all-modal').addEventListener('click', acceptAllFromModal); // Add toggle functionality const switches = document.querySelectorAll('.cookie-switch'); switches.forEach(switchEl => { switchEl.addEventListener('click', toggleCookieSwitch); }); // Load current settings loadCurrentCookieSettings(); } function toggleCookieSwitch(event) { const switchEl = event.currentTarget; const targetId = switchEl.getAttribute('data-target'); const checkbox = document.getElementById(targetId); const slider = switchEl.querySelector('.cookie-slider'); const isChecked = checkbox.checked; checkbox.checked = !isChecked; if (checkbox.checked) { switchEl.classList.remove('bg-gray-300'); switchEl.classList.add('bg-[var(--accent-color)]'); slider.classList.remove('translate-x-0'); slider.classList.add('translate-x-6'); } else { switchEl.classList.remove('bg-[var(--accent-color)]'); switchEl.classList.add('bg-gray-300'); slider.classList.remove('translate-x-6'); slider.classList.add('translate-x-0'); } } function loadCurrentCookieSettings() { const analytics = localStorage.getItem('cookies-analytics') === 'true'; const marketing = localStorage.getItem('cookies-marketing') === 'true'; updateSwitchState('cookies-analytics', analytics); updateSwitchState('cookies-marketing', marketing); } function updateSwitchState(targetId, isEnabled) { const checkbox = document.getElementById(targetId); const switchEl = document.querySelector(`[data-target="${targetId}"]`); const slider = switchEl.querySelector('.cookie-slider'); checkbox.checked = isEnabled; if (isEnabled) { switchEl.classList.remove('bg-gray-300'); switchEl.classList.add('bg-[var(--accent-color)]'); slider.classList.remove('translate-x-0'); slider.classList.add('translate-x-6'); } else { switchEl.classList.remove('bg-[var(--accent-color)]'); switchEl.classList.add('bg-gray-300'); slider.classList.remove('translate-x-6'); slider.classList.add('translate-x-0'); } } function closeCookieSettings() { const modal = document.getElementById('cookie-settings-modal'); if (modal) { modal.remove(); } } function saveCookieSettings() { const analytics = document.getElementById('cookies-analytics').checked; const marketing = document.getElementById('cookies-marketing').checked; localStorage.setItem('cookies-accepted', 'true'); localStorage.setItem('cookies-necessary', 'true'); localStorage.setItem('cookies-analytics', analytics.toString()); localStorage.setItem('cookies-marketing', marketing.toString()); console.log('Cookie settings saved:', { analytics, marketing }); closeCookieSettings(); hideCookieBanner(); } function acceptAllFromModal() { acceptAllCookies(); closeCookieSettings(); } function checkCookieConsent() { const cookiesAccepted = localStorage.getItem('cookies-accepted'); if (cookiesAccepted === null) { // Show banner after a short delay setTimeout(showCookieBanner, 1000); } } // Export functions for the website system function init() { checkCookieConsent(); } function teardown() { if (cookieBannerElement) { hideCookieBanner(); } const modal = document.getElementById('cookie-settings-modal'); if (modal) { modal.remove(); } } // Make functions available globally if needed window.showCookieBanner = showCookieBanner; window.hideCookieBanner = hideCookieBanner; export { init, teardown };