Files
fewo-stommer/resources/themes/ostsee-licht/theme.js
T
Lars StommerandClaude Opus 5.5 7d0bc93abc Offers by their own rules, seasonal photos per section, theme authoring tooling
- Special offers: kinds (rule, fixed dates, gap filler), package price, priority, highlight;
  GapFinder detects calendar gaps (optionally waiving the minimum stay); OfferShowcase decides
  what the website advertises and prices fixed dates/gaps with PriceCalculator; offers section
  shows them side by side, as a list or rotating; hero can show the top offer. Appearances no
  longer carry a featured offer.
- Sections get stable ids; appearances set photos per section ("Bilder je Baustein") and
  sections can be limited to appearances. Photo pickers show thumbnails everywhere.
- Themes: themes:make (scaffold, never overwrites), themes:check (contract, build, markup,
  colours, external resources, WCAG contrast), themes:preview (signed links per page and
  appearance), signed ?theme= preview and preview action in the site form, inherited colour
  tokens in the admin. Base CSS split into theme.css + reusable theme-base.css.
- docs/THEME-ERSTELLUNG.md: binding guide for building additional themes elsewhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:51:38 +02:00

71 lines
2.8 KiB
JavaScript

/**
* Theme "Ostsee-Licht": small progressive enhancements. Everything works without JavaScript.
*/
// Lightbox for galleries: links with data-lightbox open the large image in a <dialog>.
document.addEventListener('click', (event) => {
const link = event.target.closest('a[data-lightbox]');
if (!link) {
return;
}
const dialog = document.getElementById('lightbox');
if (!dialog || typeof dialog.showModal !== 'function') {
return;
}
event.preventDefault();
const image = dialog.querySelector('img');
image.src = link.href;
image.alt = link.dataset.alt ?? '';
dialog.querySelector('[data-caption]').textContent = link.dataset.alt ?? '';
dialog.showModal();
});
document.addEventListener('click', (event) => {
const dialog = event.target.closest('dialog#lightbox');
if (dialog && (event.target === dialog || event.target.closest('[data-close]'))) {
dialog.close();
}
});
// Availability search in the hero: forwards the dates to the booking page.
document.addEventListener('submit', (event) => {
const form = event.target.closest('form[data-availability-search]');
if (!form) {
return;
}
const arrival = form.querySelector('[name=anreise]').value;
const departure = form.querySelector('[name=abreise]').value;
if (!arrival || !departure) {
event.preventDefault();
form.querySelector('[name=anreise]').focus();
}
});
// Rotating offers: one slide at a time, advancing every 7 s; pauses on hover/focus and
// does not advance by itself when the visitor prefers reduced motion.
document.querySelectorAll('[data-rotator]').forEach((rotator) => {
const slides = [...rotator.querySelectorAll('[data-rotator-slide]')];
const dots = [...rotator.querySelectorAll('[data-rotator-dot]')];
let current = 0;
let paused = false;
const show = (index) => {
current = (index + slides.length) % slides.length;
slides.forEach((slide, i) => { slide.hidden = i !== current; });
dots.forEach((dot, i) => dot.setAttribute('aria-selected', i === current ? 'true' : 'false'));
};
rotator.querySelector('[data-rotator-prev]')?.addEventListener('click', () => show(current - 1));
rotator.querySelector('[data-rotator-next]')?.addEventListener('click', () => show(current + 1));
dots.forEach((dot, i) => dot.addEventListener('click', () => show(i)));
['mouseenter', 'focusin'].forEach((type) => rotator.addEventListener(type, () => { paused = true; }));
['mouseleave', 'focusout'].forEach((type) => rotator.addEventListener(type, () => { paused = false; }));
if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
setInterval(() => { if (!paused && !document.hidden) show(current + 1); }, 7000);
}
});