/* TWO RAILS, ONE SET OF BEHAVIOUR. * * The milestone timeline at the foot of NEUStory, and G.R.A.I.N. behind the * five cards in NEUFamily. Dr KC asked for the second one "like the * milestone", so it is the milestone — the same panel, the same rail, the same * arrows, wheel and drag — and everything below is written once and handed a * panel rather than written twice with the ids swapped. * * What differs between them is one thing: G.R.A.I.N. is opened FROM a card and * therefore knows which stage it was opened on, and lights it. That is the * `focus` argument, and it is the only branch in this file. * * The markup is rendered by the server, so this only opens, closes, moves and * lights. If it never arrives nothing breaks: the milestone button is still an * ordinary link to /news. */ (function () { function rail(panel, closeBt) { if (!panel) return null; var scroll = panel.querySelector('[data-mstone-scroll]'); var lastFocus = null; /* ONE CARD'S WORTH, measured rather than hardcoded: the column width is a clamp() of the viewport and there is no number here that would still be right on the next screen. Two cards a press, because one is a fidget. */ function step() { var item = panel.querySelector('.mtl__item'); if (!item) return 320; return Math.max(160, item.getBoundingClientRect().width * 2); } /* the rail turns ninety degrees on a phone — CSS decides that, so ask the element what it is doing rather than repeating the media query here */ function upright() { return scroll && scroll.scrollHeight > scroll.clientHeight + 4 && scroll.scrollWidth <= scroll.clientWidth + 4; } function open(litLetter) { lastFocus = document.activeElement; document.body.style.overflow = 'hidden'; panel.hidden = false; /* THE ONE THAT WAS PRESSED IS THE ONE SHINING. Everything else stays perfectly readable — this is a highlight, not a spotlight with the rest in shadow, because the point of opening the whole word is that the whole word can be read. */ var items = panel.querySelectorAll('.mtl__item'); var target = null; Array.prototype.forEach.call(items, function (li) { var hit = litLetter && li.getAttribute('data-letter') === litLetter; li.classList.toggle('mtl__item--lit', !!hit); if (hit) target = li; }); if (!scroll) { if (closeBt) closeBt.focus(); return; } if (target) { /* CENTRED, AND WITHOUT A GLIDE. The panel has only just appeared, so there is nothing for a smooth scroll to be smooth against — it would read as the rail sliding about on its own the moment it opens. It arrives already in the right place, and every move the reader makes after that is animated. */ var mid = upright() ? target.offsetTop - (scroll.clientHeight - target.offsetHeight) / 2 : target.offsetLeft - (scroll.clientWidth - target.offsetWidth) / 2; var prev = scroll.style.scrollBehavior; scroll.style.scrollBehavior = 'auto'; if (upright()) scroll.scrollTop = Math.max(0, mid); else scroll.scrollLeft = Math.max(0, mid); /* let the jump land before smooth scrolling is switched back on */ requestAnimationFrame(function () { scroll.style.scrollBehavior = prev || ''; }); } else { /* AT THE BEGINNING. It is "how we got here", so it starts where the story does; the arrows and the wheel carry the reader to today. */ scroll.scrollLeft = 0; scroll.scrollTop = 0; } if (closeBt) closeBt.focus(); } function close() { panel.hidden = true; document.body.style.overflow = ''; if (lastFocus && lastFocus.focus) lastFocus.focus(); } if (closeBt) closeBt.addEventListener('click', close); panel.addEventListener('click', function (e) { if (e.target === panel || e.target.hasAttribute('data-mstone-shut')) close(); }); document.addEventListener('keydown', function (e) { if (e.key === 'Escape' && !panel.hidden) close(); }); panel.querySelectorAll('[data-mstone-go]').forEach(function (b) { b.addEventListener('click', function () { var d = +b.getAttribute('data-mstone-go') || 1; if (!scroll) return; if (upright()) scroll.scrollBy({ top: d * step(), behavior: 'smooth' }); else scroll.scrollBy({ left: d * step(), behavior: 'smooth' }); }); }); if (scroll) { /* A WHEEL TURNS DOWNWARDS AND THE RAIL RUNS SIDEWAYS, which is the one thing every horizontal strip on the web gets wrong. A vertical wheel over the rail moves it along; a trackpad's sideways swipe is left alone, because the browser already does the right thing with that. */ scroll.addEventListener('wheel', function (e) { if (upright()) return; if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) return; e.preventDefault(); scroll.scrollLeft += e.deltaY; }, { passive: false }); /* DRAG IT. The ring on the front page is dragged, the strip is dragged, so this is dragged — and it follows the hand, which is the lesson from the ring: dragging left moves the content left. */ var down = false, startX = 0, startL = 0, moved = 0; scroll.addEventListener('pointerdown', function (e) { if (e.button) return; if (e.target.closest('a, button')) return; // a link is still a link down = true; moved = 0; startX = e.clientX; startL = scroll.scrollLeft; scroll.style.cursor = 'grabbing'; }); scroll.addEventListener('pointermove', function (e) { if (!down || upright()) return; var dx = e.clientX - startX; /* a finger wobbles where a mouse does not: on a touch screen (the NEUONBOX, a tablet) a tap that moved a few pixels is still a tap, and now that a tap on a card opens it, it has to count as one */ if (Math.abs(dx) > (e.pointerType === 'touch' ? 12 : 3)) moved = 1; scroll.scrollLeft = startL - dx; }); ['pointerup', 'pointercancel', 'pointerleave'].forEach(function (ev) { scroll.addEventListener(ev, function () { down = false; scroll.style.cursor = ''; }); }); /* a drag that ended on a link must not also follow it — and, now that the whole card opens (below), a drag that ended on a card must not open it: the hand was moving the rail, not choosing a milestone. The mark lasts for this one click and is gone before the next. */ scroll.addEventListener('click', function (e) { if (!moved) return; if (e.target.closest('a')) e.preventDefault(); scroll.setAttribute('data-dragged', ''); setTimeout(function () { scroll.removeAttribute('data-dragged'); }, 0); moved = 0; }, true); } return { open: open, close: close, isShut: function () { return panel.hidden; } }; } /* ── THE MILESTONES, from the button at the foot of NEUStory ── */ var mstone = rail(document.getElementById('mstonePanel'), document.getElementById('mstoneClose')); if (mstone) { /* THE DOOR. Written like any other address in the template, and still an ordinary link if this script never runs. */ document.querySelectorAll('[data-milestonedoor]').forEach(function (a) { a.addEventListener('click', function (e) { e.preventDefault(); if (mstone.isShut()) mstone.open(null); }); }); } /* ── G.R.A.I.N., from any of the five cards ── Every card opens the same panel and names its own letter, which is the one that ends up shining. The ring keeps turning underneath; opening the panel is not a reason to stop it, and it is behind a full-screen scrim. */ var grain = rail(document.getElementById('grainPanel'), document.getElementById('grainClose')); if (grain) { document.querySelectorAll('[data-grainstep]').forEach(function (b) { b.addEventListener('click', function (e) { e.preventDefault(); if (grain.isShut()) grain.open(b.getAttribute('data-grainstep')); }); }); } /* ── THE VISION AND THE MISSION, from the second button in NEUFamily ── The same rail again, with two cards on it. Nothing is lit: neither of the two is the one you came for, so lighting one would be an answer to a question nobody asked. */ var vision = rail(document.getElementById('visionPanel'), document.getElementById('visionClose')); if (vision) { document.querySelectorAll('[data-visiondoor]').forEach(function (b) { b.addEventListener('click', function (e) { e.preventDefault(); if (vision.isShut()) vision.open(null); }); }); } })(); /* ── THE MILESTONE RAIL, FILTERED ──────────────────────────────────────── * * Taufik, 20 August 2026: * "make the milestone able to select/sort/filter by year, date, month, etc." * "…only appear pop-up when being click, cause later will have a lot of * milestones [this is so that the milestone can become the calendar * reference for auditing]" * * Its own block, deliberately separate from `rail()` above: that function is * shared with G.R.A.I.N. and with the vision panel, neither of which has a * filter bar, and pushing this into it would put three features' worth of * branching into something that currently does one thing well. * * IT FILTERS IN THE BROWSER. Every milestone is already in the page — the * server sent them all — so asking it again to show thirteen of the thirteen * it has just sent would be slower, would flicker, and would stop working the * moment somebody opened this on a train. * * ── the two things that stop being CSS's job once it filters ── * * The cards alternate above and below the rail, and a year is announced once * on the first card that belongs to it. Both were decided at render time. * Neither can be any more: filter out the card between two others and * `:nth-child` puts them on the same side; filter out the first card of 2025 * and the year 2025 is never announced at all. Both are worked out here, * after filtering, every time. */ (function () { 'use strict'; var panel = document.getElementById('mstonePanel'); if (!panel) return; var bar = panel.querySelector('[data-mfilter]'); var list = panel.querySelector('.mtl'); if (!bar || !list) return; var items = [].slice.call(list.querySelectorAll('[data-mitem]')); var countAt = panel.querySelector('[data-mcount]'); var noneAt = panel.querySelector('[data-mnone]'); var clearBt = panel.querySelector('[data-mclear]'); var scroll = panel.querySelector('[data-mstone-scroll]'); /* found here rather than beside their handler further down: `apply()` reads `countOn`, and `apply()` runs before the bottom of this file does */ var toggle = bar.querySelector('[data-mfiltertoggle]'); var countOn = bar.querySelector('[data-mfiltercount]'); /* ── IT STARTS ON THE LATEST YEAR ── * Taufik, 23 August 2026: "also make it default 2026 [latest year]". * * Read off the markup rather than written down: `data-mdefault` carries the * newest year that actually has something on the rail, so this is still * right in 2027 and there is no year hard-coded in two places to disagree * with each other. See the note in public/views/_milestones.ejs. * * The