/* The shared "reel" behaviours, used by sections 1, 3, 4, Commitment and SDG.
*
* [data-pop] anything clickable that opens into the long landscape panel:
* reel cards, orbit cards, partner logos, SDG goals. Carries
* data-name / data-role / data-img / data-href.
*
* See-through headlines live in torch.js: every page has titles, only this one
* has the reel.
*
* Rings are NOT paused when a card opens — Dr. KC wants them always moving.
*/
(function () {
/* ---- the landscape panel ---- */
var panel = document.querySelector('[data-reelopen]');
if (!panel) return;
/* THE PANEL MUST NOT LIVE INSIDE A CLIPPED BOX. THIS LINE IS THE WHOLE BUG.
*
* In the markup it sits inside Section 1, within `.hero__pin`. That pin is
* `overflow: hidden`, and the section around it is `overflow: clip` — both
* deliberate, both needed for the reel and the flying ball.
*
* `position: fixed` does not escape either of them. The panel was laid out
* correctly over the whole viewport — the right size, opacity 1, `hidden`
* removed, the right title in it — and then clipped away to Section 1's box,
* which by then was thousands of pixels above the screen. So every card in
* Sovereign, How It Works, Trust, SDG, NEUStory and NEUFamily opened this
* panel perfectly and drew absolutely nothing. No error, no warning: the
* only way to see it was to photograph a real browser and find the popup
* missing while the DOM insisted it was open.
*
* Moved to the body once, at startup, where no ancestor can clip it. Cards
* in Section 1 still work because the panel is the same element either way.
*/
if (panel.parentElement !== document.body) document.body.appendChild(panel);
var openImg = panel.querySelector('[data-openimg]');
var openTtl = panel.querySelector('[data-opentitle]');
var openRole = panel.querySelector('[data-openrole]');
var openLink = panel.querySelector('[data-openlink]');
var openDesc = panel.querySelector('[data-opendesc]');
var closeBtn = panel.querySelector('[data-openclose]');
var video = panel.querySelector('[data-openvideo]');
var last = null;
function open(el) {
var d = el.dataset;
/* Carry the card's chapter onto the panel, so the light a person pressed
follows them into it. The CSS does the rest off the attribute. */
var openPanel = panel.querySelector('.reelopen__panel');
if (openPanel) {
if (d.neu) openPanel.setAttribute('data-neu', d.neu);
else openPanel.removeAttribute('data-neu');
}
// a film card plays; everything else shows its picture
if (video) {
if (d.file) {
// a local film: click-to-play only, never preloaded — these are ~13 MB
video.innerHTML = '';
video.hidden = false;
openImg.hidden = true;
panel.classList.add('is-film');
} else if (d.video) {
// loop needs the playlist parameter too — on its own, loop=1 does
// nothing to a single YouTube video
video.innerHTML = '';
video.hidden = false;
openImg.hidden = true;
panel.classList.add('is-film');
} else {
video.innerHTML = ''; // stop whatever was playing
video.hidden = true;
openImg.hidden = false;
panel.classList.remove('is-film');
}
}
/* NO PICTURE MEANS NO PICTURE BOX.
This used to set the src to the picture OR THE EMPTY STRING, and an
empty src is not
"nothing" to a browser: it resolves to the page's own address, the
browser fetches an HTML document, fails to decode it as an image and
draws the broken-image icon. Every card without a picture opened with
one: the five G.R.A.I.N. cards, and any story card with no photograph.
The attribute is removed rather than emptied, and the whole box goes
with it. */
if (d.img) {
openImg.src = d.img;
openImg.alt = d.name || '';
openImg.hidden = false;
} else {
openImg.removeAttribute('src');
openImg.alt = '';
openImg.hidden = true;
}
if (openPanel) openPanel.classList.toggle('has-no-media', !d.img && !d.video && !d.file);
openTtl.textContent = d.name || '';
/* Box 2 takes a short label above the title and a sentence below it. A
film card carries its chapter name in data-role, which belongs above;
an orbit card carries a whole sentence, which belongs below. Split on
length rather than asking every caller to say which it meant. */
var desc = d.desc || (d.role && d.role.length > 34 ? d.role : '');
var kind = d.desc ? (d.role || '') : (desc ? '' : (d.role || ''));
openRole.textContent = kind;
openRole.hidden = !kind;
if (openDesc) {
openDesc.textContent = desc;
openDesc.hidden = !desc;
}
// box 3 goes away entirely when there is nowhere to go, rather than
// leaving an empty box sitting under the description
var goBox = openLink.closest('.rbox--go');
if (goBox) goBox.hidden = !d.href && !d.story;
/* a story card has its own page, so it can be shared */
if (window.NEUShare) window.NEUShare.set(panel.querySelector('.reelopen__share'),
d.story ? { url: d.story, title: d.name || '', text: (d.role || '').slice(0, 140) } : null);
if (d.href) {
openLink.href = d.href;
openLink.hidden = false;
openLink.textContent = d.cta || 'Open this chapter →';
/* SOMEWHERE ELSE OPENS SOMEWHERE ELSE. The SDG cards now go to the
United Nations and the story cards to wherever they were published;
following those in the same tab takes a reader out of the site
mid-scroll, and out of Dr KC's presentation mid-sentence. An address
on this site still opens here, as it should. */
if (/^https?:\/\//i.test(d.href)) {
openLink.target = '_blank';
openLink.rel = 'noopener';
} else {
openLink.removeAttribute('target');
openLink.removeAttribute('rel');
}
} else {
// not everything has somewhere to go. Clear the href as well as hiding
// it — a stale href on a hidden link has already caused one stray
// navigation on this site.
openLink.hidden = true;
openLink.removeAttribute('href');
}
last = el;
el.classList.add('is-open');
/* ── THE CARD MAKES THE JOURNEY, NOT THE PANEL ──
* This panel used to throw itself at the screen from 28vw away — see the
* note where `card-throw` was, in site.css. It looked good and it was
* still the thing Taufik named on 23 August 2026: the panel arrived from
* nowhere while the card that had been pressed sat where it was.
*
* Now a copy of that card turns, flies here, and stops; the page goes soft
* behind it; the panel takes its place. Same order as the card popup, the
* graph stage and the milestone box — see public/assets/js/arrive.js.
*/
if (!window.NEUArrive) {
panel.hidden = false;
panel.classList.add('is-veiled', 'is-here');
document.body.style.overflow = 'hidden';
closeBtn.focus();
return;
}
window.NEUArrive.open({
from: el,
root: panel,
panel: panel.querySelector('.reelopen__panel'),
done: function () {
/* THE SCRIM GUARD IS ARMED FROM HERE, not from the press.
A press on a ring that is still turning can be followed by a stray
click a moment later, and the guard below throws those away — but it
was measuring from the press, and the panel now takes a second and a
half to arrive. Measured from the press, the guard would have
expired before the scrim it protects existed. */
openedAt = Date.now();
closeBtn.focus();
},
});
}
function close() {
if (window.NEUShare) window.NEUShare.close();
if (video) { video.innerHTML = ''; video.hidden = true; } // never keep playing
panel.classList.remove('is-film');
if (openImg) openImg.hidden = false;
var back = function () {
if (last) { last.classList.remove('is-open'); last.focus(); last = null; }
};
if (!window.NEUArrive) {
panel.hidden = true;
panel.classList.remove('is-veiled', 'is-here');
document.body.style.overflow = '';
back();
return;
}
window.NEUArrive.close({
root: panel,
panel: panel.querySelector('.reelopen__panel'),
from: last,
done: back,
});
}
/* The reel's cards are on the page at load and bound below. The fan of films
in Section 1 is built later, so it needs a way in to the same panel —
otherwise a second, nearly-identical player would end up existing. */
window.NEUReelOpen = open;
/* ---- opening a card ----
*
* WHY THIS IS NOT SIMPLY A `click` HANDLER, WHICH IS WHAT IT USED TO BE.
*
* A browser only fires `click` when the press AND the release happen on the
* same element. That is a safe assumption almost everywhere, and a bad one
* here: every one of these cards is riding a ring that never stops turning.
* Press a card, and in the tenth of a second before the button comes up the
* ring has carried it out from under the pointer. The release lands on the
* ring instead, so the click fires on the ring, and nothing opens. It is
* worse on a phone, where a finger drifts 10-15 px during an ordinary tap
* and the ring's own drag handler multiplies that drift on the way in.
*
* So the PRESS is what counts. Remember which card went down; if the pointer
* comes back up near where it started, open that card — wherever the ring
* has since carried it. Move further than SLOP and it was a drag of the
* ring, not a press of a card, and nothing opens.
*
* Delegated from the document rather than bound card by card, so the film
* fan in Section 1 — built long after this file runs — works the same way
* without being wired up separately.
*/
var SLOP = 12; // px of drift still counted as a press, not a drag
var PATIENCE = 800; // ms; longer than this is a hold, not a press
var pressed = null, pX = 0, pY = 0, pAt = 0, openedAt = 0;
document.addEventListener('pointerdown', function (e) {
pressed = (e.target && e.target.closest) ? e.target.closest('[data-pop]') : null;
pX = e.clientX; pY = e.clientY; pAt = Date.now();
}, true);
/* A finger that starts on a card and then scrolls the page is taken over by
the browser: pointercancel arrives and pointerup never does. Forget the
press, or it is still sitting there waiting when the finger next comes up
somewhere else. */
document.addEventListener('pointercancel', function () { pressed = null; }, true);
document.addEventListener('pointerup', function (e) {
var el = pressed;
pressed = null;
if (!el) return;
if (Date.now() - pAt > PATIENCE) return;
if (Math.abs(e.clientX - pX) > SLOP || Math.abs(e.clientY - pY) > SLOP) return;
openedAt = Date.now();
open(el);
}, true);
/* Enter or Space on a focused card fires a click with no pointer behind it,
so the keyboard still needs this. The guard stops a pointer press being
served twice, since `click` follows `pointerup` on the way out. */
document.addEventListener('click', function (e) {
var el = (e.target && e.target.closest) ? e.target.closest('[data-pop]') : null;
if (!el) return;
e.preventDefault();
if (Date.now() - openedAt < 700) return;
open(el);
});
closeBtn.addEventListener('click', close);
/* ── THE TAP THAT OPENS IT MUST NOT ALSO CLOSE IT ──
*
* Pressing a film card on a touch screen did nothing at all: the panel
* opened and shut again inside the same tap, so fast that nothing appeared.
*
* Why it happens on a finger and not on a mouse. With a mouse the browser
* works out the click's target from where the button went DOWN and came UP
* — both on the card — so the click that follows arrives on the card and the
* guard below it does its job. With a finger the click is hit-tested when it
* is dispatched, which is AFTER pointerup has run and opened the panel. By
* then the panel is under the finger, the click lands on the scrim, and the
* scrim means close. The panel had the right film in it and was already
* gone.
*
* So the close-on-scrim ignores anything that arrives in the same breath as
* the opening. `openedAt` was already being kept for exactly this reason one
* handler down; it simply was not being read here.
*/
panel.addEventListener('click', function (e) {
/* the scrim is a real element now rather than the panel's own background —
it had to become one to be the site's shared `.veil`, which is what
holds the blur back until the card has landed. Both still close. */
if (e.target !== panel && !e.target.classList.contains('veil')) return;
if (Date.now() - openedAt < 700) return;
close();
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && !panel.hidden) close();
});
})();
/* ═══════════════ HOW FAST THE FILM STRIP RUNS ═══════════════
*
* THE MISTAKE THIS FIXES, plainly: the strip's speed was a hardcoded 52
* seconds. That is not a speed — it is how long one lap takes, and a lap gets
* longer every time a film is added. When the hero went from two short bands
* to one long one, the strip got four times longer and the 52 seconds stayed,
* so it ran four times faster: 294 pixels a second, where the two-row version
* had been running at about 77. Dr KC's note — "moderate speed, not too fast"
* — is a description of exactly that.
*
* So the CONSTANT is the speed and the duration is worked out from it. A lap
* is half the track (the strip is doubled so it can loop seamlessly), and the
* duration is that distance divided by how fast it should go. Add a film,
* remove one, change the card size on a different screen: the strip carries on
* moving at the same pace, because the pace is the thing that was specified.
*
* Rows are given slightly different speeds around the target — not for
* decoration, but because several rows at an identical pace read as one block
* sliding rather than as separate strips.
*/
(function () {
'use strict';
/* pixels per second. The two-row hero ran at about 77 and nobody complained
about it; this is a shade livelier and still unhurried — a 640px card
takes about seven and a half seconds to cross its own width. */
var SPEED = 85;
/* how much each row may differ from that, so rows do not march in step */
var VARY = [1, 0.9, 1.08, 0.94, 1.14, 0.86];
if (matchMedia('(prefers-reduced-motion: reduce)').matches) return;
function pace() {
document.querySelectorAll('.reel[data-reel] .reel__track').forEach(function (track, i) {
/* scrollWidth, not getBoundingClientRect: the track is far wider than
the box that clips it, and the rect would only report the clip. */
var lap = track.scrollWidth / 2;
if (!lap) return;
var speed = SPEED * (VARY[i % VARY.length]);
track.style.animationDuration = (lap / speed).toFixed(1) + 's';
});
}
/* Cards are sized from the viewport, so a resize changes the lap length and
the duration has to be worked out again — otherwise turning a laptop into
a projector quietly changes the speed. */
var waiting = null;
addEventListener('resize', function () {
clearTimeout(waiting);
waiting = setTimeout(pace, 200);
});
/* Once now, and once more when the pictures have arrived: an image that has
not loaded yet has no width, so the first measurement of a cold page can
come out short. */
pace();
addEventListener('load', pace);
setTimeout(pace, 1500);
})();