drink-it-cold/web/assets/js/main.js
torsten fe388838db Startseite: Anfrageformular sendet serverseitig, Landingpage und netcup-Ziel
- Neues oeffentliches Formular-Endpoint POST /anfrage (app/inquiry.php):
  Pflichtfelder ausser Nachricht, Validierung, Honeypot, IP-Limit 5/Stunde,
  Versand per mail_send() mit Reply-To des Kunden - kein mailto mehr
- mail_send() akzeptiert zusaetzliche Kopfzeilen (CRLF bereinigt)
- app.inquiry_email in Konfiguration und Deploy-Template (DIC_INQUIRY_EMAIL)
- Statische Landingpage web/index.html mit Assets, Service-Worker-Cache dic-v18
- App-Routen auf /dashboard, netcup-Deploy-Doku und Fundstellen aktualisiert
2026-11-29 16:31:28 +01:00

203 lines
6.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* Drink it cold – Interaktionen
Kein Framework, kein Tracking. */
(function () {
'use strict';
var reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
/* ---------- Jahr im Footer ---------- */
var year = document.getElementById('year');
if (year) year.textContent = new Date().getFullYear();
/* ---------- Header: Zustand beim Scrollen ---------- */
var header = document.getElementById('header');
var lastY = -1;
function onScroll() {
var y = window.scrollY;
if (y === lastY) return;
lastY = y;
header.classList.toggle('is-scrolled', y > 24);
}
onScroll();
window.addEventListener('scroll', onScroll, { passive: true });
/* ---------- Mobile Navigation ---------- */
var toggle = document.getElementById('navToggle');
var nav = document.getElementById('nav');
function setNav(open) {
header.classList.toggle('is-open', open);
toggle.setAttribute('aria-expanded', String(open));
toggle.setAttribute('aria-label', open ? 'Menü schließen' : 'Menü öffnen');
document.body.style.overflow = open && window.innerWidth <= 1200 ? 'hidden' : '';
}
if (toggle && nav) {
toggle.addEventListener('click', function () {
setNav(!header.classList.contains('is-open'));
});
nav.addEventListener('click', function (e) {
if (e.target.closest('a')) setNav(false);
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && header.classList.contains('is-open')) {
setNav(false);
toggle.focus();
}
});
document.addEventListener('click', function (e) {
if (!header.classList.contains('is-open')) return;
if (header.contains(e.target)) return;
setNav(false);
});
window.addEventListener('resize', function () {
if (window.innerWidth > 1200) setNav(false);
});
}
/* ---------- Einblenden beim Scrollen ---------- */
var revealItems = document.querySelectorAll('.reveal');
if (!reduceMotion && 'IntersectionObserver' in window) {
var io = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (!entry.isIntersecting) return;
var el = entry.target;
var siblings = Array.prototype.slice.call(
el.parentElement ? el.parentElement.children : []
).filter(function (n) { return n.classList.contains('reveal'); });
var i = Math.max(0, siblings.indexOf(el));
el.style.transitionDelay = Math.min(i * 70, 350) + 'ms';
el.classList.add('is-visible');
io.unobserve(el);
});
}, { rootMargin: '0px 0px -8% 0px', threshold: 0.08 });
revealItems.forEach(function (el) { io.observe(el); });
} else {
revealItems.forEach(function (el) { el.classList.add('is-visible'); });
}
/* ---------- Galerie-Lightbox ---------- */
var lightbox = document.getElementById('lightbox');
var lightboxImg = document.getElementById('lightboxImg');
var lightboxClose = document.getElementById('lightboxClose');
var lastFocus = null;
function openLightbox(img) {
lastFocus = document.activeElement;
lightboxImg.src = img.currentSrc || img.src;
lightboxImg.alt = img.alt || '';
lightbox.hidden = false;
document.body.style.overflow = 'hidden';
lightboxClose.focus();
}
function closeLightbox() {
lightbox.hidden = true;
lightboxImg.removeAttribute('src');
document.body.style.overflow = '';
if (lastFocus) lastFocus.focus();
}
document.querySelectorAll('#gallery figure').forEach(function (fig) {
var img = fig.querySelector('img');
if (!img) return;
fig.addEventListener('click', function () { openLightbox(img); });
fig.setAttribute('tabindex', '0');
fig.setAttribute('role', 'button');
fig.setAttribute('aria-label', 'Bild vergrößern: ' + (img.alt || ''));
fig.addEventListener('keydown', function (e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
openLightbox(img);
}
});
});
if (lightbox) {
lightboxClose.addEventListener('click', closeLightbox);
lightbox.addEventListener('click', function (e) {
if (e.target === lightbox) closeLightbox();
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && !lightbox.hidden) closeLightbox();
});
}
/* ---------- Anfrageformular ---------- */
var form = document.getElementById('requestForm');
var status = document.getElementById('formStatus');
var MAIL = 'drinkitcold@web.de';
function showStatus(message, isError) {
if (!status) return;
status.textContent = message;
status.classList.add('is-visible');
status.classList.toggle('is-error', !!isError);
}
if (form) {
var submitButton = form.querySelector('button[type="submit"]');
var phone = form.elements['phone'];
var dateFrom = form.elements['from'];
var dateTo = form.elements['to'];
form.addEventListener('submit', function (e) {
e.preventDefault();
if (!form.checkValidity()) {
form.reportValidity();
return;
}
if (phone && !/[0-9+][0-9 ()\/+.-]{4,}/.test(phone.value.trim())) {
phone.setCustomValidity('Bitte eine erreichbare Telefonnummer angeben.');
form.reportValidity();
return;
}
if (phone) phone.setCustomValidity('');
if (dateFrom && dateTo && dateFrom.value && dateTo.value && dateTo.value < dateFrom.value) {
dateTo.setCustomValidity('Das Ende der Miete muss nach dem Beginn liegen.');
form.reportValidity();
return;
}
if (dateTo) dateTo.setCustomValidity('');
if (submitButton) submitButton.disabled = true;
showStatus('Ihre Anfrage wird gesendet …', false);
fetch(form.action, {
method: 'POST',
body: new FormData(form),
headers: { 'X-Requested-With': 'fetch', 'Accept': 'application/json' },
credentials: 'omit'
})
.then(function (response) {
return response.json()
.catch(function () { return {}; })
.then(function (payload) {
return { ok: response.ok && payload.ok !== false, message: payload.message || '' };
});
})
.then(function (result) {
if (result.ok) {
form.reset();
showStatus(result.message || 'Vielen Dank! Ihre Anfrage ist bei uns eingegangen.', false);
} else {
showStatus(result.message || ('Die Anfrage konnte nicht gesendet werden. Bitte schreiben Sie uns an ' + MAIL + '.'), true);
}
})
.catch(function () {
showStatus('Die Anfrage konnte nicht gesendet werden – bitte prüfen Sie Ihre Verbindung oder schreiben Sie uns an ' + MAIL + '.', true);
})
.then(function () {
if (submitButton) submitButton.disabled = false;
});
});
}
})();