| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- // Page routing only. Changing the visible page never changes a device session.
- (() => {
- const pages = new Set(['overview', 'thermal', 'connections', 'plan', 'uip', 'amt', 'testing', 'records', 'queue']);
- function show(value, updateHash = true) {
- const page = pages.has(value) ? value : 'overview';
- document.body.dataset.currentPage = page;
- document.querySelectorAll('[data-pages]').forEach(node => {
- node.hidden = !node.dataset.pages.split(' ').includes(page);
- });
- document.querySelectorAll('.workspace-tab').forEach(button => {
- const selected = button.dataset.page === page;
- button.classList.toggle('selected', selected);
- button.setAttribute('aria-selected', String(selected));
- button.tabIndex = selected ? 0 : -1;
- });
- if (updateHash && location.hash !== '#' + page) history.replaceState(null, '', '#' + page);
- window.dispatchEvent(new CustomEvent('stl:page-change', {detail:{page}}));
- }
- document.querySelectorAll('.workspace-tab').forEach(button => {
- button.addEventListener('click', () => show(button.dataset.page));
- button.addEventListener('keydown', event => {
- if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
- event.preventDefault();
- const buttons = [...document.querySelectorAll('.workspace-tab')];
- const i = buttons.indexOf(button);
- const next = event.key === 'Home' ? 0 : event.key === 'End' ? buttons.length - 1 : (i + (event.key === 'ArrowRight' ? 1 : -1) + buttons.length) % buttons.length;
- show(buttons[next].dataset.page); buttons[next].focus();
- });
- });
- document.querySelectorAll('[data-nav-page]').forEach(button => button.addEventListener('click', () => show(button.dataset.navPage)));
- document.getElementById('nav-station').addEventListener('change', event => {
- window.dispatchEvent(new CustomEvent('stl:station-select', {detail:{stationId:event.target.value}}));
- });
- window.addEventListener('hashchange', () => show(location.hash.slice(1), false));
- window.stlNavigation = {
- show,
- current: () => document.body.dataset.currentPage,
- updateStations(stations, selected) {
- const select = document.getElementById('nav-station');
- const signature = JSON.stringify(stations.map(s => [s.station_id, s.name]));
- if (select.dataset.signature !== signature) {
- select.replaceChildren(...stations.map(s => {
- const option = document.createElement('option');
- option.value = s.station_id; option.textContent = `${s.station_id} · ${s.name || s.station_id}`;
- return option;
- }));
- select.dataset.signature = signature;
- }
- select.value = selected;
- },
- };
- show(location.hash.slice(1), false);
- })();
|