hackertours/themes/hackertours/assets/js/schedule.js
Vincent Mahnke f53721555f
Show day picker on desktop schedules
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-14 03:17:19 +01:00

26 lines
996 B
JavaScript

// Day picker for the schedule shortcode. Without JavaScript all days remain visible.
for (const schedule of document.querySelectorAll('[data-schedule]')) {
const picker = schedule.querySelector('.schedule__picker');
const buttons = [...picker.querySelectorAll('button')];
const select = (selected) => {
for (const button of buttons) {
const isSelected = button === selected;
button.setAttribute('aria-pressed', isSelected);
document
.getElementById(button.getAttribute('aria-controls'))
.classList.toggle('schedule__day--selected', isSelected);
}
};
for (const button of buttons) {
button.addEventListener('click', () => select(button));
}
// During the event, start on today's tours. The 'sv' locale formats as YYYY-MM-DD.
const today = new Date().toLocaleDateString('sv');
select(buttons.find((button) => button.dataset.date === today) ?? buttons[0]);
picker.hidden = false;
schedule.classList.add('schedule--picker');
}