(function () { 'use strict'; const $ = (s, r) => (r || document).querySelector(s); const $$ = (s, r) => Array.from((r || document).querySelectorAll(s)); const deck = $('#deck'); const slides = $$('.slide', deck); /* — side rail: one dot per slide, jump on click, highlight current — */ const rail = $('#rail'); const dots = slides.map(s => { const b = document.createElement('button'); b.className = 'rail__dot'; // the pill label on the rail — the running order, readable at a glance const LABEL = { hero: 'Why', 'teach-learn': 'How', sovereign: 'Sovereign', 'how-it-works': 'We Serve', commitment: 'Trust', sdg: 'Impact', growth: 'Growth', news: 'Latest News', allies: 'Partners', family: 'NEUFamily', }; const label = LABEL[s.dataset.slide] || s.dataset.slide; b.dataset.label = label; b.setAttribute('aria-label', 'Go to ' + label); b.addEventListener('click', () => s.scrollIntoView({ behavior: 'smooth' })); rail.appendChild(b); return b; }); /* WHICH SLIDE AM I ON. This was an IntersectionObserver at threshold 0.6 — "light the dot once 60% of the slide is on screen". Section 1 is three viewports tall. Sixty per cent of it can never be on screen at once, so its dot never lit, and because nothing else took the light either, standing at the very top of the page the rail said Sovereign — the last section that happened to win during layout. Any slide over 1.67 screens tall is unmeasurable that way. Measured the other way round it cannot go wrong: of everything on screen, light whichever slide is covering the most of it. Tall or short, that is always the one somebody is looking at. Read on a frame, not on every scroll event: getBoundingClientRect forces layout, and a wheel can fire dozens of times between two paints. */ let pending = 0; function lightCurrent() { pending = 0; const h = innerHeight; let best = -1, most = 0; slides.forEach((s, i) => { const r = s.getBoundingClientRect(); const seen = Math.min(r.bottom, h) - Math.max(r.top, 0); if (seen > most) { most = seen; best = i; } }); if (best < 0) return; dots.forEach((d, di) => d.classList.toggle('active', di === best)); const slug = slides[best].dataset.slide; $$('.nav__pill a[data-jump]').forEach(a => a.classList.toggle('active', a.dataset.jump === slug)); } const relight = () => { if (!pending) pending = requestAnimationFrame(lightCurrent); }; addEventListener('scroll', relight, { passive: true }); addEventListener('resize', relight); /* and once now, so the rail is right before anybody has scrolled at all — which is the state it was wrong in */ lightCurrent(); /* — nav pill: smooth-scroll to the target slide inside the deck — */ $$('.nav__pill a[href^="#"]').forEach(a => { a.addEventListener('click', e => { e.preventDefault(); const target = $(a.getAttribute('href')); if (target) target.scrollIntoView({ behavior: 'smooth' }); }); }); /* How It Works / Sovereign use the orbit component — see orbit.js */ })();