Refreshes the shared reverse engineering docs, adds the requirements, application design and units for the homepage-sections feature, and updates the static design: live prices and form fields, the new Lieve woorden block and the coming-soon gate over the contact form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
527 lines
18 KiB
JavaScript
527 lines
18 KiB
JavaScript
/* ==========================================================================
|
|
Andrea Slop Fotografie — interactie
|
|
--------------------------------------------------------------------------
|
|
Geen build-stap, geen dependencies. Elke module is een losse init-functie
|
|
zodat je ze straks een voor een kunt vervangen door een React-component
|
|
of -hook.
|
|
========================================================================== */
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
var prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Sticky header */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
function initHeader() {
|
|
var header = document.querySelector('[data-header]');
|
|
if (!header) return;
|
|
|
|
var threshold = 60;
|
|
|
|
function update() {
|
|
header.classList.toggle('header--sticky', window.scrollY > threshold);
|
|
}
|
|
|
|
update();
|
|
window.addEventListener('scroll', update, { passive: true });
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Mobiel menu */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
function initMobileNav() {
|
|
var toggle = document.querySelector('[data-nav-toggle]');
|
|
var nav = document.querySelector('[data-mobile-nav]');
|
|
if (!toggle || !nav) return;
|
|
|
|
function setOpen(open) {
|
|
nav.classList.toggle('is-open', open);
|
|
toggle.setAttribute('aria-expanded', String(open));
|
|
toggle.setAttribute('aria-label', open ? 'Menu sluiten' : 'Menu openen');
|
|
document.body.classList.toggle('is-locked', open);
|
|
}
|
|
|
|
toggle.addEventListener('click', function () {
|
|
setOpen(!nav.classList.contains('is-open'));
|
|
});
|
|
|
|
nav.addEventListener('click', function (event) {
|
|
if (event.target.closest('a')) setOpen(false);
|
|
});
|
|
|
|
document.addEventListener('keydown', function (event) {
|
|
if (event.key === 'Escape' && nav.classList.contains('is-open')) setOpen(false);
|
|
});
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Side area ("Info Menu") */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
function initSideArea() {
|
|
var area = document.querySelector('[data-side-area]');
|
|
if (!area) return;
|
|
|
|
var openers = document.querySelectorAll('[data-side-area-open]');
|
|
var closers = area.querySelectorAll('[data-side-area-close]');
|
|
var lastFocused = null;
|
|
|
|
function setOpen(open) {
|
|
area.classList.toggle('is-open', open);
|
|
area.setAttribute('aria-hidden', String(!open));
|
|
document.body.classList.toggle('is-locked', open);
|
|
|
|
if (open) {
|
|
lastFocused = document.activeElement;
|
|
var firstClose = area.querySelector('[data-side-area-close]');
|
|
if (firstClose) firstClose.focus();
|
|
} else if (lastFocused) {
|
|
lastFocused.focus();
|
|
}
|
|
}
|
|
|
|
openers.forEach(function (btn) {
|
|
btn.addEventListener('click', function () { setOpen(true); });
|
|
});
|
|
|
|
closers.forEach(function (btn) {
|
|
btn.addEventListener('click', function () { setOpen(false); });
|
|
});
|
|
|
|
document.addEventListener('keydown', function (event) {
|
|
if (event.key === 'Escape' && area.classList.contains('is-open')) setOpen(false);
|
|
});
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Hero slider */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
function initHeroSlider() {
|
|
var hero = document.querySelector('[data-hero]');
|
|
if (!hero) return;
|
|
|
|
var slides = Array.prototype.slice.call(hero.querySelectorAll('[data-hero-slide]'));
|
|
var thumbs = Array.prototype.slice.call(hero.querySelectorAll('[data-hero-thumb]'));
|
|
var progress = hero.querySelector('[data-hero-progress]');
|
|
if (slides.length < 2) return;
|
|
|
|
var DURATION = 6000; // ms per slide
|
|
var TICK = 50;
|
|
var index = 0;
|
|
var elapsed = 0;
|
|
var timer = null;
|
|
|
|
function show(next) {
|
|
index = (next + slides.length) % slides.length;
|
|
elapsed = 0;
|
|
|
|
slides.forEach(function (slide, i) {
|
|
slide.classList.toggle('is-active', i === index);
|
|
slide.setAttribute('aria-hidden', String(i !== index));
|
|
});
|
|
|
|
thumbs.forEach(function (thumb, i) {
|
|
thumb.classList.toggle('is-active', i === index);
|
|
thumb.setAttribute('aria-current', i === index ? 'true' : 'false');
|
|
});
|
|
}
|
|
|
|
function tick() {
|
|
elapsed += TICK;
|
|
if (progress) progress.style.width = (elapsed / DURATION) * 100 + '%';
|
|
if (elapsed >= DURATION) show(index + 1);
|
|
}
|
|
|
|
function start() {
|
|
if (prefersReducedMotion || timer) return;
|
|
timer = window.setInterval(tick, TICK);
|
|
}
|
|
|
|
function stop() {
|
|
window.clearInterval(timer);
|
|
timer = null;
|
|
}
|
|
|
|
thumbs.forEach(function (thumb, i) {
|
|
thumb.addEventListener('click', function () {
|
|
show(i);
|
|
if (progress) progress.style.width = '0%';
|
|
});
|
|
});
|
|
|
|
hero.addEventListener('mouseenter', stop);
|
|
hero.addEventListener('mouseleave', start);
|
|
|
|
document.addEventListener('visibilitychange', function () {
|
|
if (document.hidden) stop(); else start();
|
|
});
|
|
|
|
show(0);
|
|
start();
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Lightbox (portfolio) */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
function initLightbox() {
|
|
var triggers = Array.prototype.slice.call(document.querySelectorAll('[data-lightbox]'));
|
|
var box = document.querySelector('[data-lightbox-box]');
|
|
if (!triggers.length || !box) return;
|
|
|
|
var img = box.querySelector('[data-lightbox-img]');
|
|
var caption = box.querySelector('[data-lightbox-caption]');
|
|
var counter = box.querySelector('[data-lightbox-counter]');
|
|
var current = 0;
|
|
var lastFocused = null;
|
|
|
|
var items = triggers.map(function (trigger) {
|
|
return {
|
|
src: trigger.getAttribute('data-lightbox-src') || trigger.querySelector('img').src,
|
|
alt: trigger.querySelector('img') ? trigger.querySelector('img').alt : ''
|
|
};
|
|
});
|
|
|
|
function render() {
|
|
var item = items[current];
|
|
img.src = item.src;
|
|
img.alt = item.alt;
|
|
caption.textContent = item.alt;
|
|
counter.textContent = (current + 1) + ' / ' + items.length;
|
|
}
|
|
|
|
function open(i) {
|
|
current = i;
|
|
lastFocused = document.activeElement;
|
|
render();
|
|
box.classList.add('is-open');
|
|
box.setAttribute('aria-hidden', 'false');
|
|
document.body.classList.add('is-locked');
|
|
var closeBtn = box.querySelector('[data-lightbox-close]');
|
|
if (closeBtn) closeBtn.focus();
|
|
}
|
|
|
|
function close() {
|
|
box.classList.remove('is-open');
|
|
box.setAttribute('aria-hidden', 'true');
|
|
document.body.classList.remove('is-locked');
|
|
if (lastFocused) lastFocused.focus();
|
|
}
|
|
|
|
function step(delta) {
|
|
current = (current + delta + items.length) % items.length;
|
|
render();
|
|
}
|
|
|
|
triggers.forEach(function (trigger, i) {
|
|
trigger.addEventListener('click', function (event) {
|
|
event.preventDefault();
|
|
open(i);
|
|
});
|
|
});
|
|
|
|
box.addEventListener('click', function (event) {
|
|
if (event.target.closest('[data-lightbox-close]') || event.target === box) close();
|
|
if (event.target.closest('[data-lightbox-prev]')) step(-1);
|
|
if (event.target.closest('[data-lightbox-next]')) step(1);
|
|
});
|
|
|
|
document.addEventListener('keydown', function (event) {
|
|
if (!box.classList.contains('is-open')) return;
|
|
if (event.key === 'Escape') close();
|
|
if (event.key === 'ArrowLeft') step(-1);
|
|
if (event.key === 'ArrowRight') step(1);
|
|
});
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Contactformulier */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
/**
|
|
* Verstuurt het formulier.
|
|
*
|
|
* Er is nu nog geen back-end, dus dit logt de payload en doet alsof het
|
|
* gelukt is. Vervang de body straks door een fetch naar de .NET API:
|
|
*
|
|
* return fetch('/api/contact', {
|
|
* method: 'POST',
|
|
* headers: { 'Content-Type': 'application/json' },
|
|
* body: JSON.stringify(payload)
|
|
* }).then(function (res) {
|
|
* if (!res.ok) throw new Error('Versturen mislukt');
|
|
* return res.json();
|
|
* });
|
|
*/
|
|
function submitContactForm(payload) {
|
|
console.info('[contact] payload', payload);
|
|
return new Promise(function (resolve) {
|
|
window.setTimeout(resolve, 600);
|
|
});
|
|
}
|
|
|
|
// Submissions faster than this after the form appeared are treated as bots.
|
|
var MIN_FILL_MS = 3000;
|
|
|
|
function initContactForm() {
|
|
var forms = Array.prototype.slice.call(document.querySelectorAll('[data-contact-form]'));
|
|
if (!forms.length) return;
|
|
|
|
var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
|
|
|
|
// Required-field messages. The home form asks for a shoot type, the
|
|
// contact page still has a free-text subject; validate whichever exists.
|
|
var requiredMessages = {
|
|
naam: 'Vul je naam in.',
|
|
onderwerp: 'Vul een onderwerp in.',
|
|
shoot: 'Kies een soort shoot.',
|
|
bericht: 'Schrijf hier je vraag.'
|
|
};
|
|
|
|
// "Boek je shoot" links to ?pakket=<id>#contact; preselect that package.
|
|
var requestedPackage = new URLSearchParams(window.location.search).get('pakket');
|
|
|
|
forms.forEach(function (form) {
|
|
var status = form.querySelector('[data-form-status]');
|
|
var submit = form.querySelector('[type="submit"]');
|
|
var shownAt = Date.now();
|
|
|
|
if (requestedPackage && form.elements.shoot) {
|
|
var option = form.elements.shoot.querySelector('option[value="' + CSS.escape(requestedPackage) + '"]');
|
|
if (option) form.elements.shoot.value = requestedPackage;
|
|
}
|
|
|
|
function setError(field, message) {
|
|
var wrapper = field.closest('.form__field');
|
|
var slot = wrapper ? wrapper.querySelector('[data-form-error]') : null;
|
|
if (slot) slot.textContent = message || '';
|
|
field.setAttribute('aria-invalid', message ? 'true' : 'false');
|
|
return !message;
|
|
}
|
|
|
|
function validate() {
|
|
var valid = true;
|
|
|
|
Object.keys(requiredMessages).forEach(function (name) {
|
|
var field = form.elements[name];
|
|
if (!field) return;
|
|
valid = setError(field, field.value.trim() ? '' : requiredMessages[name]) && valid;
|
|
});
|
|
|
|
var email = form.elements.email;
|
|
var emailValue = email.value.trim();
|
|
var emailMessage = '';
|
|
if (!emailValue) emailMessage = 'Vul je e-mailadres in.';
|
|
else if (!emailPattern.test(emailValue)) emailMessage = 'Dit e-mailadres klopt nog niet.';
|
|
valid = setError(email, emailMessage) && valid;
|
|
|
|
return valid;
|
|
}
|
|
|
|
// Honeypot filled in, or submitted inhumanly fast.
|
|
function looksLikeSpam() {
|
|
var honeypot = form.elements.website;
|
|
return (honeypot && honeypot.value !== '') || Date.now() - shownAt < MIN_FILL_MS;
|
|
}
|
|
|
|
function showStatus(message) {
|
|
if (!status) return;
|
|
status.hidden = false;
|
|
status.textContent = message;
|
|
}
|
|
|
|
form.addEventListener('submit', function (event) {
|
|
event.preventDefault();
|
|
|
|
if (status) {
|
|
status.hidden = true;
|
|
status.textContent = '';
|
|
}
|
|
|
|
if (!validate()) {
|
|
var firstInvalid = form.querySelector('[aria-invalid="true"]');
|
|
if (firstInvalid) firstInvalid.focus();
|
|
return;
|
|
}
|
|
|
|
var thanks = 'Bedankt voor je bericht. Andrea reageert binnen 2-3 werkdagen.';
|
|
|
|
// Spam gets the normal thank-you, so bots learn nothing; nothing is sent.
|
|
if (looksLikeSpam()) {
|
|
form.reset();
|
|
showStatus(thanks);
|
|
return;
|
|
}
|
|
|
|
var payload = { naam: form.elements.naam.value.trim(), email: form.elements.email.value.trim() };
|
|
if (form.elements.shoot) payload.shoot = form.elements.shoot.value;
|
|
if (form.elements.onderwerp) payload.onderwerp = form.elements.onderwerp.value.trim();
|
|
payload.bericht = form.elements.bericht.value.trim();
|
|
|
|
if (submit) submit.disabled = true;
|
|
|
|
submitContactForm(payload)
|
|
.then(function () {
|
|
form.reset();
|
|
showStatus(thanks);
|
|
})
|
|
.catch(function () {
|
|
showStatus('Versturen lukte niet. Mail gerust rechtstreeks naar info@andreaslop.nl.');
|
|
})
|
|
.finally(function () {
|
|
if (submit) submit.disabled = false;
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Contact form gate ("coming soon" overlay) */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
// While there is no back-end the form stays visible but dimmed and inert
|
|
// under a notice with a mail button. Remove data-form-disabled to switch
|
|
// the form on.
|
|
function initFormGate() {
|
|
var gates = Array.prototype.slice.call(document.querySelectorAll('[data-form-gate]'));
|
|
|
|
gates.forEach(function (gate) {
|
|
var form = gate.querySelector('[data-contact-form]');
|
|
var notice = gate.querySelector('[data-form-notice]');
|
|
var disabled = gate.hasAttribute('data-form-disabled');
|
|
|
|
if (form) form.inert = disabled;
|
|
if (notice) notice.hidden = !disabled;
|
|
});
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Lieve woorden (testimonials) */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
// One review at a time; previous/next and dots, no autoplay. Manual
|
|
// changes are announced politely to screen readers.
|
|
function initTestimonials() {
|
|
var root = document.querySelector('[data-testimonials]');
|
|
if (!root) return;
|
|
|
|
var slides = Array.prototype.slice.call(root.querySelectorAll('[data-testimonial]'));
|
|
var dots = Array.prototype.slice.call(root.querySelectorAll('[data-testimonials-dot]'));
|
|
var controls = root.querySelector('.testimonials__controls');
|
|
var status = root.querySelector('[data-testimonials-status]');
|
|
var active = 0;
|
|
|
|
// A single review needs no controls.
|
|
if (slides.length < 2) {
|
|
if (controls) controls.hidden = true;
|
|
return;
|
|
}
|
|
|
|
function show(index) {
|
|
active = (index + slides.length) % slides.length;
|
|
|
|
slides.forEach(function (slide, i) {
|
|
var isActive = i === active;
|
|
slide.hidden = !isActive;
|
|
slide.classList.toggle('is-active', isActive);
|
|
});
|
|
|
|
dots.forEach(function (dot, i) {
|
|
if (i === active) dot.setAttribute('aria-current', 'true');
|
|
else dot.removeAttribute('aria-current');
|
|
});
|
|
|
|
if (status) status.textContent = 'Review ' + (active + 1) + ' van ' + slides.length;
|
|
}
|
|
|
|
root.querySelector('[data-testimonials-prev]').addEventListener('click', function () { show(active - 1); });
|
|
root.querySelector('[data-testimonials-next]').addEventListener('click', function () { show(active + 1); });
|
|
dots.forEach(function (dot, i) {
|
|
dot.addEventListener('click', function () { show(i); });
|
|
});
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Scroll-reveal */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
function initReveal() {
|
|
var items = Array.prototype.slice.call(document.querySelectorAll('.reveal'));
|
|
if (!items.length) return;
|
|
|
|
if (prefersReducedMotion || !('IntersectionObserver' in window)) {
|
|
items.forEach(function (item) { item.classList.add('is-visible'); });
|
|
return;
|
|
}
|
|
|
|
var observer = new IntersectionObserver(function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (!entry.isIntersecting) return;
|
|
entry.target.classList.add('is-visible');
|
|
observer.unobserve(entry.target);
|
|
});
|
|
}, { threshold: 0.12, rootMargin: '0px 0px -60px 0px' });
|
|
|
|
items.forEach(function (item) { observer.observe(item); });
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Terug naar boven */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
function initToTop() {
|
|
var btn = document.querySelector('[data-to-top]');
|
|
if (!btn) return;
|
|
|
|
function update() {
|
|
btn.classList.toggle('is-visible', window.scrollY > window.innerHeight * 0.6);
|
|
}
|
|
|
|
btn.addEventListener('click', function () {
|
|
window.scrollTo({ top: 0, behavior: prefersReducedMotion ? 'auto' : 'smooth' });
|
|
});
|
|
|
|
update();
|
|
window.addEventListener('scroll', update, { passive: true });
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Jaartal in de footer */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
function initYear() {
|
|
var slots = document.querySelectorAll('[data-year]');
|
|
var year = String(new Date().getFullYear());
|
|
slots.forEach(function (slot) { slot.textContent = year; });
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Start */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
function init() {
|
|
initHeader();
|
|
initMobileNav();
|
|
initSideArea();
|
|
initHeroSlider();
|
|
initLightbox();
|
|
initContactForm();
|
|
initFormGate();
|
|
initTestimonials();
|
|
initReveal();
|
|
initToTop();
|
|
initYear();
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
} else {
|
|
init();
|
|
}
|
|
})();
|