/* The card popup. * * A card on a chapter page is a headline and a picture. Everything else — the * paragraph, the date, the link — waits in here, so the page stays quiet and * the detail is one tap away rather than three screens of scrolling. * * Shape, in order: pictures, title, subtitle, date, then the words, which * scroll on their own if there are a lot of them. Two ways out and no others: * the round X, or anywhere outside the panel. */ (function () { var panel = document.querySelector('[data-pop-panel]'); if (!panel) return; /* #cardData is the chapter pages' rails, and it is what the [data-card] buttons below are indexes into. The FRONT page has no rails and no such buttons — it opens this panel from the constellation's list, by calling _openCard with a card of its own. So a missing #cardData is not a reason to give up any more; it only means nothing on this page is index-driven. */ var dataEl = document.getElementById('cardData'); var RAILS = []; if (dataEl) { try { RAILS = JSON.parse(dataEl.textContent); } catch (e) { RAILS = []; } } var slides = panel.querySelector('[data-popslides]'); var dots = panel.querySelector('[data-popdots]'); var media = panel.querySelector('[data-popmedia]'); var view = panel.querySelector('[data-popview]'); var scroll = panel.querySelector('[data-popscroll]'); var el = { kicker: panel.querySelector('[data-popkicker]'), title: panel.querySelector('[data-poptitle]'), sub: panel.querySelector('[data-popsub]'), meta: panel.querySelector('[data-popmeta]'), text: panel.querySelector('[data-poptext]'), go: panel.querySelector('[data-popgo]'), srcs: panel.querySelector('[data-popsrcs]'), chaps: panel.querySelector('[data-popchaps]'), }; var shareBox = panel.querySelector('.pop__share'); var at = 0, count = 0, timer = null, opener = null; var wasOverflow = ''; // what the page's scroll lock was before this opened function show(n) { if (!count) return; at = (n + count) % count; slides.style.transform = 'translateX(' + (-at * 100) + '%)'; dots.querySelectorAll('i').forEach(function (d, i) { d.classList.toggle('is-on', i === at); }); pointView(); } /* The button must always point at the picture you can actually see, not at the one that happened to be first when the panel opened. */ function pointView() { if (!view) return; var slide = slides.children[at]; var img = slide && slide.querySelector('img'); var src = img && img.getAttribute('src'); /* only a path on this site or an http(s) address: the picture's address is stored text, and a javascript: one here would run when pressed */ if (src && (/^\/(?!\/)/.test(src) || /^https?:\/\//i.test(src))) { view.href = src; view.hidden = false; } else { view.removeAttribute('href'); view.hidden = true; } } /* the pictures move on by themselves — a booth screen has nobody to swipe it */ function startAuto() { stopAuto(); if (count > 1) timer = setInterval(function () { show(at + 1); }, 4200); } function stopAuto() { if (timer) clearInterval(timer); timer = null; } function fill(c) { // pictures slides.innerHTML = ''; dots.innerHTML = ''; count = (c.imgs || []).length; media.hidden = !count; (c.imgs || []).forEach(function (im) { var f = document.createElement('figure'); f.className = 'pop__slide'; /* an element, not a string of HTML: the address is stored text, and a quote in it would otherwise have been the end of the attribute and the start of whatever came next */ var img = document.createElement('img'); img.src = im.src || ''; img.alt = im.alt || ''; f.appendChild(img); slides.appendChild(f); }); // "..." only when there is more than one to move between dots.hidden = count < 2; if (count > 1) { for (var i = 0; i < count; i++) { var d = document.createElement('i'); (function (n) { d.addEventListener('click', function () { show(n); startAuto(); }); })(i); dots.appendChild(d); } } at = 0; show(0); pointView(); /* show() gives up early when there is no picture at all */ set(el.kicker, c.kicker); el.title.textContent = c.title || ''; set(el.sub, c.sub); set(el.meta, c.meta); el.text.innerHTML = ''; var found = null; (c.body || '').split(/(?:\r?\n[ \t]*){2,}/).forEach(function (para) { if (!para.trim()) return; var p = document.createElement('p'); var got = linkify(p, para.trim()); if (!found) found = got; el.text.appendChild(p); }); /* …unless the write-ups are listed below anyway (a story's sources, by name): then a big button repeating the first of them is the same link twice, and the timeline's popup does not have it */ if ((Array.isArray(c.links) ? c.links : []).some(function (s) { return s && /^https?:\/\//i.test(s.url || ''); })) found = null; /* A story whose text names the newspaper it came from now offers that address at the bottom too, where the eye goes looking for the way out. An explicit link on the card still wins. */ var go = c.href || found; if (go) { el.go.href = go; el.go.textContent = c.cta || (c.href ? 'Open →' : 'Read the full article →'); el.go.hidden = false; /* SOMEWHERE ELSE OPENS SOMEWHERE ELSE — AND HERE OPENS HERE. This button used to carry target="_blank" in the markup, which was right while every address it could hold was a newspaper's. It is not any more: a chapter card can now point at a page on this site, and "Smart Mobility → /smart-mobility" was opening a second tab of our own website. The same test as everywhere else decides. */ if (/^https?:\/\//i.test(go)) { el.go.target = '_blank'; el.go.rel = 'noopener noreferrer'; } else { el.go.removeAttribute('target'); el.go.removeAttribute('rel'); } } else { el.go.removeAttribute('href'); el.go.hidden = true; } /* ── AND EVERY WRITE-UP IT GOT ── * Taufik: "some card have more than 1 link … using the domain main name." * The button above is the card's own and says whatever was typed on it. * These are the outside articles, each one already carrying the outlet's * name — worked out on the server so the editor and the page cannot end * up calling the same domain two different things. * * Built as text nodes and anchors, never handed to innerHTML, the same * rule the paragraphs above follow. */ /* ── THE TIMELINE'S WAY ── Taufik, 14 October 2026, of a NEUTalents story: "the information is not complete as (2). With the link to the news" — (2) being the same story opened from the timeline, which shows each write-up as its name, a copy button and the address itself. So it is shown that way here too: the same three pieces, the same classes (share.css), and the copy button answered by share.js. */ if (el.srcs) { el.srcs.textContent = ''; var links = Array.isArray(c.links) ? c.links : []; links.forEach(function (s) { if (!s || !/^https?:\/\//i.test(s.url || '')) return; var row = document.createElement('span'); row.className = 'mlink mlink--wide'; var a = document.createElement('a'); a.className = 'pop__src mlink__go'; a.href = s.url; a.target = '_blank'; a.rel = 'noopener noreferrer'; a.textContent = (s.name || 'Read it') + ' →'; var cp = document.createElement('button'); cp.type = 'button'; cp.className = 'mlink__copy'; cp.setAttribute('data-mcopy', s.url); cp.setAttribute('aria-label', 'Copy the ' + (s.name || '') + ' link'); cp.title = cp.getAttribute('aria-label'); cp.textContent = '⧉'; var code = document.createElement('code'); code.className = 'mlink__url'; code.textContent = s.url; row.appendChild(a); row.appendChild(cp); row.appendChild(code); el.srcs.appendChild(row); }); el.srcs.hidden = !el.srcs.children.length; } /* ── AND WHICH CHAPTERS IT IS IN ── Taufik: "is link to the respective chapters in NEUTalents, NEUCity and etc". Only a story carries this (c.story, from the server), and only chapters the server named — a slug that is no chapter any more is never a link. Same-site, so no new tab. */ if (el.chaps) { el.chaps.textContent = ''; var chaps = (c.story && Array.isArray(c.story.chapters)) ? c.story.chapters : []; chaps = chaps.filter(function (ch) { return ch && /^[a-z0-9-]+$/.test(ch.slug || '') && ch.name; }); if (chaps.length) { var k = document.createElement('span'); k.className = 'mdet__chapsk'; k.textContent = chaps.length > 1 ? 'Chapters' : 'Chapter'; el.chaps.appendChild(k); chaps.forEach(function (ch) { var ca = document.createElement('a'); ca.className = 'mdet__chap'; ca.href = '/' + (ch.slug === 'neuslm' ? 'neudoc' : ch.slug); // NEUSLM is NEUDoc, 30 Oct 2026 ca.textContent = ch.name + ' →'; el.chaps.appendChild(ca); }); } el.chaps.hidden = !chaps.length; } /* ── AND A WAY TO SEND IT ── A story has a page of its own (/news/), so it can be shared; a chapter's own box has none, and its Share button stays hidden rather than sending the chapter page and calling it the story. */ if (window.NEUShare) { window.NEUShare.set(shareBox, c.story && c.story.url ? { url: c.story.url, title: c.title || '', text: (c.body || '').replace(/\s+/g, ' ').trim().slice(0, 140), } : null); } else if (shareBox) { shareBox.hidden = true; } scroll.scrollTop = 0; } /* A web address typed into a story is still just text, and nobody can press it. These three turn it into a link — and hand back the first one found, so the panel can offer it again at the bottom. Only http and https are matched, so nothing a story says can turn into a javascript: link, and every piece is built as a text node or an anchor. The text is never handed to innerHTML. */ var URLISH = /https?:\/\/[^\s<>"']+/g; function trimTail(u) { /* the full stop at the end of a sentence is not part of the address */ while (u && /[.,;:!?'"\]}]$/.test(u)) u = u.slice(0, -1); /* a closing bracket only belongs to the address if one opened inside it */ while (u.slice(-1) === ')' && (u.match(/\(/g) || []).length < (u.match(/\)/g) || []).length) { u = u.slice(0, -1); } return u; } function linkify(p, text) { var last = 0, m, first = null; URLISH.lastIndex = 0; while ((m = URLISH.exec(text))) { var raw = trimTail(m[0]); if (!raw) continue; p.appendChild(document.createTextNode(text.slice(last, m.index))); var a = document.createElement('a'); a.className = 'pop__link'; a.href = raw; a.target = '_blank'; a.rel = 'noopener noreferrer'; /* shown without the http:// — the address is long enough already */ a.textContent = raw.replace(/^https?:\/\//, '').replace(/\/$/, ''); p.appendChild(a); last = m.index + raw.length; if (!first) first = raw; } p.appendChild(document.createTextNode(text.slice(last))); return first; } function set(node, val) { if (val) { node.textContent = val; node.hidden = false; } else node.hidden = true; } /* ── HOW IT ARRIVES ──────────────────────────────────────────────────── * * Taufik, 23 August 2026: "currently its sudden pop-up, no, make it have * animation of the card spin and fly into the middle, then the card stop, * and then background blur." * * So this no longer opens itself. It hands the pressed card and this panel * to arrive.js, which is the one place on the site that knows the order — * the draw, the flight, the stop, the veil, the settle — and it is the same * order the graph stage, the milestone box and the film panel now use. * * `fill` is passed rather than called first because arrive.js measures this * panel to know where to fly the card to, and an unfilled panel is a * different size from a filled one: the card would land at the LAST card's * shape. And the pictures start moving on `done` rather than at the press, * because a carousel that has already changed twice by the time you can see * it has skipped the first picture — which is the one the card showed. */ var arriving = false; function open(c, from) { if (arriving) return; /* one press, one flight */ opener = from || null; wasOverflow = document.body.style.overflow; if (!window.NEUArrive) { /* nothing to fly with — be there, plainly */ fill(c); panel.hidden = false; panel.classList.add('is-veiled', 'is-here'); document.body.style.overflow = 'hidden'; startAuto(); var x0 = panel.querySelector('.pop__x'); if (x0) x0.focus(); return; } arriving = true; window.NEUArrive.open({ from: opener, root: panel, panel: panel.querySelector('.pop__panel'), fill: function () { fill(c); }, done: function () { arriving = false; startAuto(); /* focus moves when the panel has finished arriving and not before: a screen reader announcing a dialog that is still on its way is the audible version of the pop this replaces */ var x = panel.querySelector('.pop__x'); if (x) x.focus(); }, }); } function close() { stopAuto(); if (window.NEUShare) window.NEUShare.close(); if (!window.NEUArrive) { panel.hidden = true; panel.classList.remove('is-veiled', 'is-here'); document.body.style.overflow = wasOverflow; if (opener) opener.focus(); return; } arriving = false; window.NEUArrive.close({ root: panel, panel: panel.querySelector('.pop__panel'), from: opener, /* PUT BACK WHAT WAS THERE, not ''. This panel opens on top of the constellation, which has locked the body itself — clearing the lock on the way out would let the front page scroll away behind a stage that is still up. arrive.js remembers what it found and restores that. */ done: function () { if (opener) opener.focus(); }, }); } document.querySelectorAll('[data-card]').forEach(function (btn) { btn.addEventListener('click', function () { var ix = btn.dataset.card.split('-'); var rail = RAILS[+ix[0]]; if (rail && rail.cards[+ix[1]]) open(rail.cards[+ix[1]], btn); }); }); panel.querySelectorAll('[data-popclose]').forEach(function (b) { b.addEventListener('click', close); }); document.addEventListener('keydown', function (e) { if (e.key === 'Escape' && !panel.hidden) close(); }); /* Reaching for the button should not be a race — the pictures stop moving the moment the cursor arrives, or the panel opens the wrong one. */ if (view) { view.addEventListener('pointerenter', stopAuto); view.addEventListener('focus', stopAuto); } // swipe the pictures on a phone var from = null; media.addEventListener('pointerdown', function (e) { from = e.clientX; stopAuto(); }); media.addEventListener('pointerup', function (e) { if (from === null) return; var dx = e.clientX - from; if (Math.abs(dx) > 40) show(at + (dx < 0 ? 1 : -1)); from = null; startAuto(); }); window._openCard = open; })();