interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / public / js / engineer-universe.js

29 lines · 1366 bytes Raw Blame History
1// Universe map: planets are plain links to #w-<id>; this only adds keyboard
2// travel, Escape to close, and focus handling. Everything works without it.
3(function () {
4 var uni = document.querySelector('.uni');
5 if (!uni) return;
6 var worlds = Array.prototype.slice.call(uni.querySelectorAll('.world'));
7 function current() {
8 var id = location.hash.slice(1);
9 return worlds.filter(function (w) { return w.id === id; })[0] || null;
10 }
11 function syncState() {
12 var w = current();
13 uni.classList.toggle('has-world', !!w);
14 uni.querySelectorAll('.planet').forEach(function (p) {
15 p.classList.toggle('is-active', !!w && p.getAttribute('href') === '#' + w.id);
16 });
17 if (w) { var h = w.querySelector('h2'); if (h) { h.setAttribute('tabindex', '-1'); h.focus({ preventScroll: true }); } }
18 }
19 window.addEventListener('hashchange', syncState);
20 syncState();
21 document.addEventListener('keydown', function (e) {
22 var w = current();
23 if (e.key === 'Escape' && w) { history.pushState(null, '', location.pathname + '#map'); syncState(); return; }
24 if (!w || e.target.closest('input,textarea')) return;
25 var sel = e.key === 'ArrowRight' ? '.world-next' : e.key === 'ArrowLeft' ? '.world-prev' : null;
26 var a = sel && w.querySelector(sel);
27 if (a) { e.preventDefault(); location.hash = a.getAttribute('href'); }
28 });
29})();