${item.title}
${guest ? item.teaser : item.description.slice(0, 140) + '...'}
${guest ? '' : desc} ${contact}document.addEventListener('DOMContentLoaded', () => { const body = document.body; const isLoggedIn = body.dataset.auth === '1'; const childGender = body.dataset.childGender || ''; const header = document.querySelector('.site-header'); const headerSentinel = document.getElementById('headerSentinel'); // Logo-Logik const pickLogo = (gender) => { if (gender === 'female') return 'logo_female.png'; if (gender === 'male') return 'logo_male.png'; return Math.random() < 0.5 ? 'logo_female.png' : 'logo_male.png'; }; const chosenLogo = pickLogo(childGender); document.querySelectorAll('[data-logo-img]').forEach(img => { img.src = `/assets/bilder/${chosenLogo}`; }); // Header shrink via IntersectionObserver (no flicker around threshold) if (header && headerSentinel && 'IntersectionObserver' in window) { const observer = new IntersectionObserver(([entry]) => { header.classList.toggle('is-scrolled', !entry.isIntersecting); }, { rootMargin: '-1px 0px 0px 0px', threshold: 0, }); observer.observe(headerSentinel); } else if (header) { // Fallback with simple threshold const limit = 120; const onScroll = () => header.classList.toggle('is-scrolled', window.scrollY > limit); onScroll(); window.addEventListener('scroll', onScroll, { passive: true }); } // Mobile Menü const mobileMenu = document.getElementById('mobileMenu'); document.querySelectorAll('.menu-toggle').forEach(btn => { btn.addEventListener('click', () => { mobileMenu?.classList.toggle('open'); }); }); // Scroll zu Events const scrollBtn = document.getElementById('scrollToEvents'); if (scrollBtn) { scrollBtn.addEventListener('click', () => { document.getElementById('events')?.scrollIntoView({ behavior: 'smooth' }); }); } // Events from backend (injected on page); fallback to empty const events = Array.isArray(window.__events) ? window.__events : []; const state = { topic: 'all', age: '', region: '', query: '', geo: null }; const el = { list: document.getElementById('eventList'), chips: document.querySelectorAll('[data-filter]'), locInput: document.getElementById('locInput'), topicSelect: document.getElementById('topicSelect'), ageSelect: document.getElementById('ageSelect'), btnSearch: document.getElementById('btnSearch'), btnGeo: document.getElementById('btnGeo'), modal: document.getElementById('eventModal'), modalBody: document.getElementById('eventModalBody'), modalTitle: document.getElementById('eventModalTitle'), }; const searchState = { active: false }; const fmtDate = (iso) => { const d = new Date(iso); return d.toLocaleDateString('de-DE', { weekday: 'short', day: '2-digit', month: 'short', hour: '2-digit', minute: '2-digit' }); }; const haversine = (lat1, lon1, lat2, lon2) => { const toRad = (d) => d * Math.PI / 180; const R = 6371e3; const dLat = toRad(lat2 - lat1); const dLon = toRad(lon2 - lon1); const a = Math.sin(dLat/2) ** 2 + Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon/2) ** 2; const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); return R * c; }; const tag = (label) => `${label}`; const renderCard = (item) => { const guest = !isLoggedIn; const access = item.visibility === 'members' && guest ? '
${item.teaser}
`; const contact = !guest ? `${guest ? item.teaser : item.description.slice(0, 140) + '...'}
${guest ? '' : desc} ${contact}Keine Events gefunden.
'; // wire detail buttons el.list.querySelectorAll('[data-event-detail]').forEach(btn => { btn.addEventListener('click', () => { const id = parseInt(btn.getAttribute('data-event-detail'), 10); const ev = events.find(e => e.id === id); if (!ev || !el.modal || !el.modalBody || !el.modalTitle) return; el.modalTitle.textContent = ev.title; el.modalBody.innerHTML = `${ev.teaser}
${ev.description}
${ev.locationLabel ? `Ort: ${ev.locationLabel}
` : ''}Kinder: ${ev.allowKids ? 'Mit Kindern' : 'Ohne Kinder'}
Sichtbarkeit: ${ev.visibility === 'public' ? 'Öffentlich' : 'Nur Mitglieder'}
`; el.modal.classList.add('open'); }); }); }; if (el.chips.length > 0) { el.chips[0].classList.add('active'); } el.chips.forEach(chip => { chip.addEventListener('click', () => { el.chips.forEach(c => c.classList.remove('active')); chip.classList.add('active'); state.topic = chip.dataset.filter; renderEvents(); }); }); if (el.btnSearch) { el.btnSearch.addEventListener('click', () => { const q = (el.locInput?.value || '').trim(); const url = '/search' + (q ? ('?q=' + encodeURIComponent(q)) : ''); window.location.href = url; }); } if (el.btnGeo) { el.btnGeo.addEventListener('click', () => { if (!navigator.geolocation) { alert('Geolocation wird nicht unterstützt.'); return; } navigator.geolocation.getCurrentPosition( (pos) => { state.geo = { lat: pos.coords.latitude, lng: pos.coords.longitude }; searchState.active = false; renderEvents(); }, () => alert('Standort konnte nicht ermittelt werden.') ); }); } // Close modal document.querySelectorAll('[data-event-modal-close]').forEach(btn => { btn.addEventListener('click', () => el.modal?.classList.remove('open')); }); el.modal?.addEventListener('click', (e) => { if (e.target === el.modal) el.modal.classList.remove('open'); }); renderEvents(); });