diff --git a/README.md b/README.md index 0745474..d27947a 100644 --- a/README.md +++ b/README.md @@ -114,11 +114,11 @@ days: - `time` is `HH:MM` with a leading zero (`09:30`). Tours are sorted by time, so their order in the file doesn't matter. - `title` (optional) replaces the page's title on the card, with one entry per language: `title: { de: "Hafen am Abend", en: "Harbour by Night" }`. - `status` (optional): `soldout` marks the tour as fully booked. Other values are ignored. -- With the day picker on screens wider than the mobile-menu breakpoint (666px), the first local photo in the tour page fills the right half of its card behind a fade when it has alt text; its gallery credit remains visible. +- With JavaScript on screens wider than the mobile-menu breakpoint (666px), the first local photo in the tour page fills the right half of its card behind a fade when it has alt text; its gallery credit remains visible. For the events managed with Hackertours-Admin, the data file is generated by its website sync; don't edit it by hand. -A day picker shows one day at a time on all screen sizes, starting with today's day during the event. Without JavaScript, narrow screens show all days stacked; wide screens show a column per day on an hour grid. +With JavaScript, narrow screens show a day picker, starting with today's day during the event. Wider screens list days under their headings, hiding past days until the event ends. Before and after the event, all days are shown. Dates use the visitor's local time. Without JavaScript, narrow screens show all days stacked; wide screens show a column per day on an hour grid. For a different event than the page's section, pass its name: `{{< schedule 39c3 >}}`. diff --git a/tests/test_schedule.js b/tests/test_schedule.js new file mode 100644 index 0000000..28dd716 --- /dev/null +++ b/tests/test_schedule.js @@ -0,0 +1,75 @@ +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const test = require('node:test'); +const vm = require('node:vm'); + +const script = fs.readFileSync( + path.join(__dirname, '../themes/hackertours/assets/js/schedule.js'), + 'utf8', +); + +function runSchedule(today) { + const days = new Map(); + const buttons = Array.from({ length: 5 }, (_, day) => { + const id = `day-${day}`; + const classes = new Set(); + days.set(id, { + classes, + classList: { + toggle(name, enabled) { + if (enabled) classes.add(name); + else classes.delete(name); + }, + }, + }); + return { + dataset: { date: `2026-12-${26 + day}` }, + getAttribute: () => id, + setAttribute() {}, + addEventListener(name, callback) { + this.click = callback; + }, + }; + }); + const picker = { querySelectorAll: () => buttons, hidden: true }; + const schedule = { + querySelector: () => picker, + classList: { add() {} }, + }; + const document = { + querySelectorAll: () => [schedule], + getElementById: (id) => days.get(id), + }; + const Date = class { + toLocaleDateString() { + return today; + } + }; + vm.runInNewContext(script, { document, Date }); + return { buttons, days }; +} + +test('only past days are hidden during the event, and all return afterwards', () => { + const cases = [ + ['2026-12-25', []], + ['2026-12-26', []], + ['2026-12-28', [0, 1]], + ['2026-12-30', [0, 1, 2, 3]], + ['2026-12-31', []], + ]; + for (const [today, expected] of cases) { + const { days } = runSchedule(today); + const past = [...days.values()] + .map((day, index) => day.classes.has('schedule__day--past') ? index : null) + .filter((index) => index !== null); + assert.deepEqual(past, expected, today); + } +}); + +test('mobile selection can still switch to a past day', () => { + const { buttons, days } = runSchedule('2026-12-28'); + buttons[0].click(); + assert.ok(days.get('day-0').classes.has('schedule__day--selected')); + assert.ok(!days.get('day-2').classes.has('schedule__day--selected')); +}); diff --git a/themes/hackertours/assets/css/_schedule.css b/themes/hackertours/assets/css/_schedule.css index 397260d..5489285 100644 --- a/themes/hackertours/assets/css/_schedule.css +++ b/themes/hackertours/assets/css/_schedule.css @@ -1,4 +1,4 @@ -/* Tour schedule shortcode: a day picker, with a grid fallback on wide screens without JavaScript. */ +/* Tour schedule shortcode: a mobile day picker and a wide-screen list, with a no-JavaScript grid fallback. */ .schedule { --schedule-line: color-mix(in oklch, var(--color-text) 20%, transparent); @@ -250,7 +250,7 @@ } } -/* The picker is only shown with JavaScript. */ +/* The picker is only shown on mobile with JavaScript. */ .schedule__picker { display: none; } @@ -304,30 +304,37 @@ color: var(--color-text-meta); } -.schedule--picker { - .schedule__day:not(.schedule__day--selected) { - display: none; - } +@media (width <= 666px) { + .schedule--picker { + .schedule__day:not(.schedule__day--selected) { + display: none; + } - /* The picker already names the day. */ - .schedule__day-title { - position: absolute; - width: 1px; - height: 1px; - overflow: hidden; - clip-path: inset(50%); - white-space: nowrap; + /* The picker already names the day. */ + .schedule__day-title { + position: absolute; + width: 1px; + height: 1px; + overflow: hidden; + clip-path: inset(50%); + white-space: nowrap; + } } } @container (width >= 48rem) { .schedule--picker { .schedule__days { - display: block; + display: grid; + grid-template-columns: none; + grid-template-rows: none; + gap: var(--spacing-l); } .schedule__day { display: block; + grid-column: auto; + grid-row: auto; } .schedule__list { @@ -351,3 +358,10 @@ } } } + +@media (width >= 667px) { + .schedule__picker:not([hidden]), + .schedule--picker .schedule__day--past { + display: none; + } +} diff --git a/themes/hackertours/assets/js/schedule.js b/themes/hackertours/assets/js/schedule.js index 10fd9ae..9ce06a6 100644 --- a/themes/hackertours/assets/js/schedule.js +++ b/themes/hackertours/assets/js/schedule.js @@ -1,4 +1,4 @@ -// Day picker for the schedule shortcode. Without JavaScript all days remain visible. +// Responsive schedule for the 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')]; @@ -21,6 +21,13 @@ for (const schedule of document.querySelectorAll('[data-schedule]')) { const today = new Date().toLocaleDateString('sv'); select(buttons.find((button) => button.dataset.date === today) ?? buttons[0]); + const hasUpcomingDays = buttons.some((button) => button.dataset.date >= today); + for (const button of buttons) { + document + .getElementById(button.getAttribute('aria-controls')) + .classList.toggle('schedule__day--past', hasUpcomingDays && button.dataset.date < today); + } + picker.hidden = false; schedule.classList.add('schedule--picker'); }