/* SECTION 1 — the boy, and the ball he is moving.
*
* Two layers driven by one number. `p` runs 0 → 1 across the hero's extra
* height: at 0 the ball is off to the right and small, at 1 it is centred,
* large, and sitting exactly where his hand is reaching. The plate drifts a
* little the other way, which is what makes the ball feel like it is being
* pulled rather than the camera panning.
*
* Everything is written to CSS custom properties rather than to styles
* directly, so the movement itself is described in the stylesheet where the
* rest of the look lives, and this file only ever says HOW FAR ALONG we are.
*/
(function () {
'use strict';
var stage = document.querySelector('[data-herostage]');
if (!stage) return;
var ball = document.querySelector('[data-heroball]');
var media = document.querySelector('[data-heromedia]');
/* ── A PHONE, OR THE NEUONBOX ──
Taufik, 31 August 2026: "for neuonbox [potrait] make it like mobile
version ... unable to display so much animation. old and cannot be
update." The standing panel is 1080 wide, so every rule written for a
phone missed it. lowfi.js names the one query both answer to. */
var PHONE = window.NEULowFi ? window.NEULowFi.matches()
: (window.matchMedia && window.matchMedia('(max-width: 820px)').matches);
var label = document.querySelector('[data-heroneu]');
var inner = document.querySelector('[data-heroballin]');
var reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;
/* ---------- how far through are we ---------- */
var p = 0;
/* THE LAST PART OF THE SCROLL IS A PAUSE, NOT A MOVE.
*
* Dr KC's note: at the end it went straight on to the next section, with no
* moment to stop and look at the chapter the ball was showing. So the
* movement is spent over the first two thirds of the section's travel and
* the last third is standing still — the ball landed, naming one chapter
* after another, waiting to be touched.
*
* It is done by shortening the RUN rather than by trapping the scroll. A
* page that refuses to move when you scroll is a page people fight; this one
* simply has nothing left to animate, and lets go the moment you keep going.
*
* 0.43, down from 0.66, and the section grew from 230vh to 300vh at the same
* time — asked for, because one pause was not long enough to get through the
* chapters before the page moved on. Those two numbers are one decision:
*
* travel = 300vh - 100vh = 200vh
* movement = 200 x 0.43 = 86vh (unchanged — the ball flies at the
* same rate per turn of the wheel)
* pause = 200 - 86 = 114vh (was 44)
*
* Raising the height on its own would have made the ball fly further per
* turn of the wheel; dropping RUN on its own would have made it fly faster.
* Change one and the other has to move. */
var RUN = 0.43;
function measure() {
var r = stage.getBoundingClientRect();
/* the pinned stage is one screen tall; the travel is everything above that */
var travel = stage.offsetHeight - window.innerHeight;
if (travel <= 0) return 1;
var raw = Math.max(0, Math.min(1, -r.top / travel));
return Math.min(1, raw / RUN);
}
/* PHONE OR NOT IS A QUESTION, NOT A FACT.
It used to be answered once, at load. A tablet turned from portrait to
landscape crosses this line, and so does anybody dragging a window wider
during a demo — and the answer was never asked again, so the page stayed
in whichever layout it happened to start in. It is asked on every frame
now, which costs nothing: matchMedia keeps the answer. */
var phone = window.matchMedia &&
window.matchMedia(window.NEULowFi ? window.NEULowFi.query : '(max-width: 820px)');
function stillNow() { return reduced || (phone && phone.matches); }
function apply() {
if (stillNow()) {
/* No flight: the ball starts where it ends up and the section is one
screen tall. `is-landed` as well as `is-still`, or the ball arrives
and sits there unnamed — everything that names a chapter hangs off
the landing. */
stage.classList.add('is-still', 'is-landed');
stage.style.setProperty('--hp', '1');
stage.style.setProperty('--hp-text', '1');
scrub(1);
landing(true);
return;
}
stage.classList.remove('is-still');
p = measure();
stage.style.setProperty('--hp', p.toFixed(4));
scrub(p);
/* the headline fades as the ball takes the stage — one thing at a time */
stage.style.setProperty('--hp-text', (1 - Math.min(1, p * 1.6)).toFixed(3));
stage.classList.toggle('is-landed', p > 0.985);
/* start and stop the chapter cycle on the frame the ball actually lands.
This used to be a second scroll listener, which meant the class was set
inside this animation frame and only noticed on the NEXT scroll event —
so a visitor who stopped scrolling the moment it landed got a still
ball and no chapter at all. */
landing(stage.classList.contains('is-landed'));
}
/* `ready` is not ceremony. apply() runs once during setup, and everything the
chapter cycle needs — the chapter list, `at`, the hover test — is declared
BELOW this point. A browser that restores the scroll position on refresh
lands the ball before the script has finished reading itself, so that first
apply() found the stage already landed and called into a cycle whose parts
did not exist yet: "held is not a function", the script died there, and the
name at the foot of Section 1 never appeared. Which is exactly what was on
screen. So the cycle stays shut until the file is done, and is then started
once, explicitly, at the bottom. */
var ready = false, wasLanded = false;
function landing(now) {
if (!ready || now === wasLanded) return;
wasLanded = now;
if (now) { cycle(); return; }
stopEverything();
var g = graph();
if (g && g._pick) g._pick(new Set());
}
/* ---------- the boy moves because you moved ----------
* The footage is never played. Its time is set from the scroll, so he leans
* in exactly as far as somebody has scrolled and stops the instant they do.
* A video that runs on its own has to be paused and explained; this one is
* already answering the hand on the mouse.
*
* Seeking is only attempted once the browser says it can, and only when the
* frame would actually change — setting currentTime on every scroll event
* makes the decoder thrash and the picture judder. */
var lastSeek = -1;
function scrub(t) {
if (!media || !media.duration || !isFinite(media.duration)) return;
if (media.readyState < 2) return;
var want = Math.max(0, Math.min(media.duration - 0.05, t * media.duration));
if (Math.abs(want - lastSeek) < 0.03) return;
lastSeek = want;
try { media.currentTime = want; } catch (e) { /* not ready yet */ }
}
if (media) {
media.pause();
media.addEventListener('loadedmetadata', function () { scrub(p); });
}
/* rAF-throttled: scroll fires far more often than the screen redraws, and
doing the work every time is how a smooth page becomes a stuttering one */
var queued = false;
function onScroll() {
if (queued) return;
queued = true;
requestAnimationFrame(function () { queued = false; apply(); });
}
/* NO FLIGHT ON A PHONE.
Dr KC's note. The ball flying in from the corner is worth a screen and a
half of scrolling on a laptop; on a phone it is a screen and a half of
scrolling before anything can be read, and the reel of films underneath
it was a second wall on top of that. So a phone gets the finished picture
straight away — headline, ball, two films, the chapter row — and the
section is one screen tall. Anybody who asked for less movement gets the
same thing, which is what `is-still` has always meant.
WHICH of those two it is, is decided in apply() on every frame rather than
once here — see stillNow(). The listeners go on either way: a phone still
has to be told when the window turns, and a desktop that is dragged narrow
has to stop flying the ball. */
addEventListener('scroll', onScroll, { passive: true });
addEventListener('resize', onScroll);
if (phone && phone.addEventListener) phone.addEventListener('change', onScroll);
apply();
/* ---------- the ball shows one NEU at a time ----------
* Once it has landed it steps through the chapters, lighting one and naming
* it, and holds on whichever one is showing the moment a pointer touches
* the ball — so a chapter can be stopped on and talked about rather than
* chased. The same idea as the pop-up on Section 2.
*/
var PILLARS = (function () {
try {
var el = document.getElementById('graphData');
return el ? (JSON.parse(el.textContent).pillars || []) : [];
} catch (e) { return []; }
})();
var HUE = { neucity: '#ff9f1c', neunature: '#2ec4a6', neumotion: '#4aa8ff',
neufactory: '#a86bff', neuslm: '#00d4c8', neutalents: '#ff5fa2',
neustudio: '#ffd166', neustory: '#7aa2ff' };
var at = -1;
/* a film window either side of the ball */
var wins = [].slice.call(document.querySelectorAll('[data-herofilm]'));
/* ---------- every film a chapter has, on a ring ----------
* The same component as the starter pack: it turns by itself, stops dead
* under a pointer, and can be dragged. Built the first time a chapter is
* asked for and then kept, so pressing the same name twice is instant.
*/
var FILMS = (function () {
try {
var el = document.getElementById('filmData');
return el ? (JSON.parse(el.textContent) || []) : [];
} catch (e) { return []; }
})();
/* The hero's ball says something; it does not idle. Silence its random
charges so the only light on those wires is the aimed one announcing the
chapter — otherwise Section 2's scenery plays over Section 1's message. */
(function hush() {
var g = graph();
if (g && g._idle) { g._idle(false); return; }
setTimeout(hush, 200); // it is built a moment after this runs
})();
var fan = document.querySelector('[data-neufan]');
var fanStage = document.querySelector('[data-neufanstage]');
var fanCore = fan && fan.querySelector('.neufan__core [data-netgraph]');
var built = {};
function openFan(pl) {
if (!fan || !pl) return;
stopEverything(); // hold this chapter while it is open
at = PILLARS.indexOf(pl); // so the arrows and the hero agree
fan.style.setProperty('--c', HUE[pl.slug] || '#8ec5ff');
document.querySelector('[data-neufanname]').textContent = pl.name;
document.querySelector('[data-neufanrole]').textContent = pl.role || '';
/* the ball in the middle lights this chapter's dots and nothing else, so
it is answering the name underneath it rather than idling */
if (fanCore && fanCore._pick) fanCore._pick(new Set([pl.slug]));
if (!built[pl.slug]) {
var mine = FILMS.filter(function (f) {
return f.slug === pl.slug || (f.also || []).indexOf(pl.slug) > -1;
});
var box = document.createElement('div');
if (!mine.length) {
box.className = 'neufan__none';
box.textContent = 'No films on this chapter yet.';
} else {
/* A grid of stills, the shape of a video list anywhere on the
internet: picture, running time in the corner of it, title
underneath. It used to be a ring that turned by itself, which is
lovely on a slide and hopeless when somebody is trying to find one
particular film in front of a room. */
box.className = 'ytgrid';
mine.forEach(function (f) {
var b = document.createElement('button');
b.className = 'ytcard';
b.type = 'button';
/* the same attributes the reel's own cards carry, so the panel that
opens is the one that already exists rather than a second player */
b.setAttribute('data-name', f.t);
b.setAttribute('data-role', f.k);
b.setAttribute('data-video', f.id);
b.setAttribute('data-img', 'https://i.ytimg.com/vi/' + f.id + '/hqdefault.jpg');
b.setAttribute('data-href', '/' + (f.slug === 'neuslm' ? 'neudoc' : f.slug)); // NEUSLM is NEUDoc, 30 Oct 2026
b.setAttribute('data-cta', 'Open ' + f.k + ' →');
b.setAttribute('aria-label', 'Play: ' + f.t);
var thumb = document.createElement('span');
thumb.className = 'ytcard__thumb';
var img = document.createElement('img');
/* mqdefault is 320x180 and never letterboxed; hqdefault is 4:3 with
black bars baked in, which is why the old cards had grey edges */
img.src = 'https://i.ytimg.com/vi/' + f.id + '/mqdefault.jpg';
img.alt = '';
img.loading = 'lazy';
thumb.appendChild(img);
var play = document.createElement('span');
play.className = 'ytcard__play';
play.setAttribute('aria-hidden', 'true');
thumb.appendChild(play);
if (f.mins) {
var d = document.createElement('span');
d.className = 'ytcard__dur';
d.textContent = f.mins;
thumb.appendChild(d);
}
b.appendChild(thumb);
var meta = document.createElement('span');
meta.className = 'ytcard__meta';
var t = document.createElement('strong');
t.textContent = f.t; // textContent: titles are staff-typed
var k = document.createElement('em');
k.textContent = f.k;
/* THE FILM'S OWN CHAPTER, IN THE FILM'S OWN COLOUR.
A film can belong to more than one chapter, so this panel is full
of films whose home is somewhere else — all four of NEUStudio's
are borrowed. Taking the panel's colour made the card read
"NEUDoc" in NEUStudio's yellow, which looks like a mistake rather
than the fact it is. Coloured by what it says, it reads as
"this one is really NEUDoc, and it is here as well". */
k.style.color = HUE[f.slug] || '#8ec5ff';
meta.appendChild(t);
meta.appendChild(k);
b.appendChild(meta);
b.addEventListener('click', function () {
if (window.NEUReelOpen) window.NEUReelOpen(b);
});
box.appendChild(b);
});
}
built[pl.slug] = box;
}
/* Outside the build, not inside it: a chapter that has been opened before
is reused from `built`, and a line left over from the chapter before it
would then be counting somebody else's films. */
var n = built[pl.slug].querySelectorAll('.ytcard').length;
document.querySelector('[data-neufanhint]').textContent = n
? n + (n === 1 ? ' film' : ' films') + ' on ' + pl.name + ' — press one to play it'
: '';
fanStage.textContent = '';
fanStage.appendChild(built[pl.slug]);
fanStage.scrollTop = 0; // a new chapter starts at its top
fan.hidden = false;
/* THE SCRIM IS THE SITE'S `.veil`, AND A VEIL STARTS CLEAR.
It fades to its blur off `is-veiled` — see public/assets/css/arrive.css.
The flush between the two is what gives it something to fade FROM;
without it the blur would appear in one frame, which is the whole thing
arrive.css exists to stop. */
void fan.offsetHeight;
fan.classList.add('is-veiled');
document.body.style.overflow = 'hidden';
}
function closeFan() {
if (!fan) return;
fan.hidden = true;
fan.classList.remove('is-veiled');
document.body.style.overflow = '';
if (at >= 0) showNeu(at); // leave the hero on the one being looked at
cycle(); // and the chapters carry on
}
/* Moving between chapters without shutting the panel: Dr KC opens NEUCity,
talks, and goes next — closing and reopening for each of the eight is the
kind of friction that ends up not being demonstrated at all. */
function fanStep(d) {
if (!PILLARS.length) return;
var i = ((at + d) % PILLARS.length + PILLARS.length) % PILLARS.length;
openFan(PILLARS[i]);
}
if (fan) {
fan.querySelectorAll('[data-neufanclose]').forEach(function (b) {
b.addEventListener('click', closeFan);
});
var fanPrev = fan.querySelector('[data-neufanprev]');
var fanNext = fan.querySelector('[data-neufannext]');
if (fanPrev) fanPrev.addEventListener('click', function () { fanStep(-1); });
if (fanNext) fanNext.addEventListener('click', function () { fanStep(1); });
document.addEventListener('keydown', function (e) {
if (fan.hidden) return;
if (e.key === 'Escape') { closeFan(); return; }
if (e.key === 'ArrowLeft') { fanStep(-1); return; }
if (e.key === 'ArrowRight') fanStep(1);
});
}
if (label) {
label.addEventListener('click', function () {
if (PILLARS[at]) openFan(PILLARS[at]);
});
}
wins.forEach(function (w) {
w.addEventListener('click', function () {
var f = w._film;
if (!f) return;
stopEverything();
w.setAttribute('data-name', f.t);
w.setAttribute('data-role', f.k);
w.setAttribute('data-video', f.id);
w.setAttribute('data-img', 'https://i.ytimg.com/vi/' + f.id + '/hqdefault.jpg');
w.setAttribute('data-href', '/' + (f.slug === 'neuslm' ? 'neudoc' : f.slug)); // NEUSLM is NEUDoc, 30 Oct 2026
w.setAttribute('data-cta', 'Open ' + f.k + ' →');
if (window.NEUReelOpen) window.NEUReelOpen(w);
});
});
function showNeu(i) {
if (!PILLARS.length) return;
at = ((i % PILLARS.length) + PILLARS.length) % PILLARS.length;
var pl = PILLARS[at];
var g = graph();
if (g && g._pick) g._pick(new Set([pl.slug]));
if (label) {
label.style.setProperty('--c', HUE[pl.slug] || '#8ec5ff');
label.hidden = false;
label.innerHTML = '' + pl.name + '' + (pl.role || '') + '';
label.setAttribute('aria-label', 'See every film on ' + pl.name);
/* Section 1's call to action is this, now the buttons are gone — so it
is tagged like any other, and Backstage → Presses can still answer
"is the first thing anybody sees doing its job". */
label.setAttribute('data-cta', '');
label.setAttribute('data-cta-from', 'hero');
label.setAttribute('data-cta-label', 'Chapter: ' + pl.name);
}
/* THE WINDOWS ON THE BALL.
Two films from this chapter, one hanging off each side. They read the
same list the reel and the fan read, so a film added in Backstage turns
up here without anybody touching this file. */
if (wins.length) {
chapterFilms = FILMS.filter(function (f) {
return f.slug === pl.slug || (f.also || []).indexOf(pl.slug) > -1;
});
filmPage = 0; // a new chapter starts at its first films
/* the chapter's colour, for the border a window takes under a pointer */
var c = HUE[pl.slug] || '#8ec5ff';
wins.forEach(function (w) { w.style.setProperty('--c', c); });
fillWindows();
}
}
/* Two windows, and most chapters have more than two films. `filmPage` is
which pair is showing; the arrows move it and it wraps, so there is no
dead button at either end. */
var chapterFilms = [], filmPage = 0;
var filmNav = document.querySelector('[data-herofilmnav]');
function pages() {
return Math.max(1, Math.ceil(chapterFilms.length / wins.length));
}
function fillWindows() {
var from = filmPage * wins.length;
wins.forEach(function (w, i) {
var f = chapterFilms[from + i];
w._film = f || null;
if (!f) { w.hidden = true; return; } // an odd number, so one window
w.hidden = false;
w.querySelector('[data-herofilmimg]').src =
'https://i.ytimg.com/vi/' + f.id + '/mqdefault.jpg';
w.querySelector('[data-herofilmtag]').textContent = f.t;
/* how many are left after this pair, on the last window showing */
var rest = chapterFilms.length - (from + wins.length);
w.querySelector('[data-herofilmmore]').textContent =
(i === wins.length - 1 && rest > 0) ? '+' + rest + ' more' : (f.mins || '');
w.setAttribute('aria-label', 'Play: ' + f.t);
});
/* no arrows for a chapter that fits in the two windows */
if (filmNav) filmNav.hidden = pages() < 2;
}
function pageFilms(d) {
if (!chapterFilms.length) return;
stopEverything(); // hold this chapter while browsing it
var n = pages();
filmPage = ((filmPage + d) % n + n) % n;
fillWindows();
}
if (filmNav) {
filmNav.querySelector('[data-herofilmprev]')
.addEventListener('click', function () { pageFilms(-1); });
filmNav.querySelector('[data-herofilmnext]')
.addEventListener('click', function () { pageFilms(1); });
}
/* THE ZAP BEFORE THE HANDOVER.
* Section 2's ball fires a charge along an edge and flares both ends; the
* component already does it and calls it `_pulse`. Reusing it here means the
* two balls behave like one machine rather than two things that happen to
* look alike — and it gives the eye a beat of warning before the name
* changes, instead of the label simply blinking into something else.
*/
/* ---------- moving from one chapter to the next ----------
*
* Three things went wrong in the first version and all three came from one
* mistake: the zap burst and the wait-between-chapters shared a single
* timer variable.
*
* · pressing an arrow mid-burst cleared the burst's own timeout, so the
* ball was left wearing `is-zapping` for good;
* · if the press landed just as a burst finished, the cycle advanced AND
* the arrow advanced, and it jumped two chapters;
* · and the arrows did not zap at all, while the automatic change did —
* so the same movement looked like two different things.
*
* Now: one timer for the wait, another for the burst, and a `gen` counter.
* Any manual step bumps `gen`, and a burst that finishes after that quietly
* does nothing — so a press always wins over whatever was already running.
*/
var waitT = null, zapT = null, gen = 0;
function stopEverything() {
clearTimeout(waitT);
clearTimeout(zapT);
if (ball) ball.classList.remove('is-zapping');
}
/* fire the aimed charge three times, then hand over — unless the world
moved on while it was firing */
function zapTo(pl, done) {
var g = graph();
var mine = ++gen;
if (!g || !g._zapTo || !pl) { done(); return; }
if (ball) ball.classList.add('is-zapping');
var n = 0;
(function fire() {
if (mine !== gen) { if (ball) ball.classList.remove('is-zapping'); return; }
g._zapTo(pl.slug, HUE[pl.slug] || '#8ec5ff');
if (++n < 3) { zapT = setTimeout(fire, 150); return; }
if (ball) ball.classList.remove('is-zapping');
if (mine === gen) done();
})();
}
/* a declaration, not `var held = function`, so it exists as early as
everything else that is reached from a hoisted function */
function held() { return !!(ball && ball.classList.contains('is-held')); }
/* Go to a chapter: announce it, show it, then wait before the next one.
The generation guard lives entirely inside zapTo — it simply does not call
back if it has been overtaken — so there is nothing to check here.
THE FIRST ONE IS NOT DELAYED. The zap is a beat of warning before the name
CHANGES, which is worth having; but the very first chapter has nothing to
change from, and hanging its appearance off the end of an animation meant
the row at the foot of Section 1 was empty whenever anything upstream of
that animation did not finish — which is exactly how it went missing. The
name is a fact about what the ball is showing, so it is written down
first, and the light is decoration on top of it. */
function goTo(i, andWait) {
stopEverything();
var pl = PILLARS[((i % PILLARS.length) + PILLARS.length) % PILLARS.length];
var first = at < 0;
if (first) showNeu(i);
zapTo(pl, function () {
if (!first) showNeu(i);
/* ── NOT ON ITS OWN, ON A PHONE ──
Taufik, 29 August 2026: "no need to auto, let user click the arrow."
A chapter that changes itself every 2.2 seconds is a chapter you
cannot read on a phone — and on a small screen the arrows are right
there under your thumb, which they are not on a desktop where this
cycle is how somebody discovers there are eight of them at all.
The arrows, the keys and the pill all still work either way. */
if (andWait && !held() && !PHONE) {
waitT = setTimeout(function () { goTo(at + 1, true); }, 2200);
}
});
}
/* THE SECOND WAY THE NAME WENT MISSING, and the one that actually did it:
if the pointer was already resting where the ball lands, the ball came up
already held — and a held ball meant this returned before anything had
been named at all. So the arrows appeared and the row at the foot did
not. Being held has to mean "do not move on", never "do not say what
this is": a ball somebody has stopped on is precisely the one they want
named. It settles on a chapter either way; only the advancing waits. */
function cycle() {
stopEverything();
if (!stage.classList.contains('is-landed')) return;
if (at < 0) { goTo(0, !held()); return; }
if (held()) return;
goTo(at + 1, true);
}
/* An arrow goes straight there, announces it the same way the clock does,
and restarts the wait — so the button never feels ignored and never
leaves the ball about to jump again a moment later. */
function step(d) { goTo(at + d, !held()); }
var prevBtn = document.querySelector('[data-heroprev]');
var nextBtn = document.querySelector('[data-heronext]');
if (prevBtn) prevBtn.addEventListener('click', function () { step(-1); });
if (nextBtn) nextBtn.addEventListener('click', function () { step(1); });
/* ---------- it stops when you look at it ----------
* Dr KC's note: hovering must halt it. The spin lives in netgraph.js, which
* parks itself when told the element is not visible — so rather than reach
* into it, this sets a class the stylesheet uses to freeze the drift, and
* pauses the component's own rotation through the handle it already
* exposes. Touch devices have no hover, so they get the drag instead. */
if (ball) {
ball.addEventListener('pointerenter', function () {
ball.classList.add('is-held');
stopEverything(); // hold on whichever NEU is showing
});
ball.addEventListener('pointerleave', function () {
if (drag.on) return;
ball.classList.remove('is-held');
cycle(); // and carry on when let go
});
}
/* ---------- and it can be turned ----------
* The netgraph exposes `_turn(dx, dy)`. Dragging feeds it straight through,
* so the ball a visitor spins in the hero is the same object, turned the
* same way, as the one inside the knowledge graph. */
var drag = { on: false, x: 0, y: 0 };
function graph() {
var g = inner && inner.querySelector('[data-netgraph]');
return g && g._turn ? g : null;
}
if (inner) {
inner.addEventListener('pointerdown', function (e) {
var g = graph();
if (!g) return;
drag.on = true;
drag.x = e.clientX;
drag.y = e.clientY;
/* where it started, so a press can be told from a turn on the way up */
drag.fromX = e.clientX;
drag.fromY = e.clientY;
drag.moved = 0;
ball.classList.add('is-held', 'is-turning');
try { inner.setPointerCapture(e.pointerId); } catch (err) { /* not fatal */ }
});
inner.addEventListener('pointermove', function (e) {
if (!drag.on) return;
var g = graph();
if (!g) return;
g._turn((e.clientX - drag.x) * 0.009, (e.clientY - drag.y) * -0.007);
drag.x = e.clientX;
drag.y = e.clientY;
drag.moved = Math.max(drag.moved,
Math.abs(e.clientX - drag.fromX) + Math.abs(e.clientY - drag.fromY));
});
/* PRESSING THE BALL OPENS THE CHAPTER TOO.
* The ball is already draggable, so a press and a turn arrive through the
* same pointer events and have to be told apart on the way up: under six
* pixels of travel is somebody tapping it, anything more is somebody
* spinning it. Without that test every drag would end by opening a panel
* over the thing they were just turning. */
['pointerup', 'pointercancel', 'pointerleave'].forEach(function (ev) {
inner.addEventListener(ev, function (e) {
if (!drag.on) return;
var tapped = ev === 'pointerup' && drag.moved < 6;
drag.on = false;
ball.classList.remove('is-turning');
if (tapped && PILLARS[at]) { openFan(PILLARS[at]); return; }
if (!ball.matches(':hover')) ball.classList.remove('is-held');
});
});
}
/* Everything above exists now, so the cycle may run. Start it by hand for the
page that was refreshed part-way down and came back already landed — there
will be no scroll event to notice that, and without this the ball sits
there unnamed. */
ready = true;
landing(stage.classList.contains('is-landed'));
})();