/** * ALL IN HOMEPAGE - JAVASCRIPT * Für WordPress Custom JS oder Footer */ (function() { 'use strict'; // Back to top button visibility function initBackToTop() { const backToTop = document.querySelector('.allin-back-to-top'); if (!backToTop) return; window.addEventListener('scroll', function() { if (window.scrollY > 300) { backToTop.classList.add('visible'); } else { backToTop.classList.remove('visible'); } }); backToTop.addEventListener('click', function() { window.scrollTo({ top: 0, behavior: 'smooth' }); }); } // FAQ Accordion with proper ARIA function initFAQ() { const faqQuestions = document.querySelectorAll('.allin-faq-question'); faqQuestions.forEach(function(question) { question.addEventListener('click', function() { const answer = this.nextElementSibling; const icon = this.querySelector('.allin-faq-icon'); const isExpanded = this.getAttribute('aria-expanded') === 'true'; if (isExpanded) { answer.style.display = 'none'; icon.textContent = '+'; this.setAttribute('aria-expanded', 'false'); } else { answer.style.display = 'block'; icon.textContent = '−'; this.setAttribute('aria-expanded', 'true'); } }); // Keyboard navigation question.addEventListener('keydown', function(e) { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); this.click(); } }); }); } // Smooth scroll for anchor links function initSmoothScroll() { const anchorLinks = document.querySelectorAll('a[href^="#"]'); anchorLinks.forEach(function(anchor) { anchor.addEventListener('click', function(e) { const href = this.getAttribute('href'); // Skip if it's just "#" if (href === '#') return; e.preventDefault(); const target = document.querySelector(href); if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'start' }); // Set focus for accessibility target.focus(); } }); }); } // Initialize all functions when DOM is ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function() { initBackToTop(); initFAQ(); initSmoothScroll(); }); } else { // DOM is already ready initBackToTop(); initFAQ(); initSmoothScroll(); } })();