50 lines
2.4 KiB
JavaScript
50 lines
2.4 KiB
JavaScript
(() => {
|
|
const menuButton = document.querySelector('[data-menu-toggle]');
|
|
const mobileNav = document.querySelector('[data-mobile-nav]');
|
|
if (menuButton && mobileNav) {
|
|
menuButton.addEventListener('click', () => {
|
|
const open = mobileNav.classList.toggle('open');
|
|
menuButton.classList.toggle('open', open);
|
|
menuButton.setAttribute('aria-expanded', String(open));
|
|
});
|
|
mobileNav.querySelectorAll('a').forEach(a => a.addEventListener('click', () => {
|
|
mobileNav.classList.remove('open'); menuButton.classList.remove('open');
|
|
menuButton.setAttribute('aria-expanded', 'false');
|
|
}));
|
|
}
|
|
|
|
const observer = 'IntersectionObserver' in window ? new IntersectionObserver(entries => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) { entry.target.classList.add('visible'); observer.unobserve(entry.target); }
|
|
});
|
|
}, {threshold: .12}) : null;
|
|
document.querySelectorAll('.reveal-on-scroll').forEach(el => observer ? observer.observe(el) : el.classList.add('visible'));
|
|
|
|
document.querySelectorAll('[data-mailto-form]').forEach(form => {
|
|
form.addEventListener('submit', event => {
|
|
event.preventDefault();
|
|
if (!form.reportValidity()) return;
|
|
const fd = new FormData(form);
|
|
const lang = document.documentElement.lang || 'de';
|
|
const lines = [];
|
|
for (const [key, value] of fd.entries()) {
|
|
if (key !== 'privacy' && key !== 'website') lines.push(`${key}: ${value}`);
|
|
}
|
|
const subject = lang === 'de' ? 'Anfrage über dilibworld.com' : 'Enquiry via dilibworld.com';
|
|
const email = form.dataset.recipient || 'info@dilibworld.com';
|
|
window.location.href = `mailto:${email}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(lines.join('\n'))}`;
|
|
const status = form.querySelector('.form-status');
|
|
if (status) { status.style.display = 'block'; }
|
|
});
|
|
});
|
|
|
|
const notice = document.querySelector('[data-cookie-notice]');
|
|
const choice = localStorage.getItem('dilibworld-cookie-choice');
|
|
if (notice && !choice) notice.classList.add('show');
|
|
document.querySelectorAll('[data-cookie-choice]').forEach(btn => btn.addEventListener('click', () => {
|
|
localStorage.setItem('dilibworld-cookie-choice', btn.dataset.cookieChoice);
|
|
notice?.classList.remove('show');
|
|
}));
|
|
|
|
document.querySelectorAll('[data-current-year]').forEach(el => el.textContent = new Date().getFullYear());
|
|
})(); |