Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The site is self-contained: layouts, styles and data live in this repository (th
| `i18n/` | Small UI strings (menu label, 404 text, ...) |
| `layouts/` | Templates |
| `assets/` | CSS and JS, minified and fingerprinted by Hugo at build time |
| `assets/kit/`, `static/kit/` | The shared InterImm kit (styles, fonts, header and footer) that other InterImm sites link from interimm.org/kit/. See [kit/README.md](kit/README.md) |
| `static/` | Files served as-is (images, video, favicons) |

## Deploy
Expand Down
459 changes: 142 additions & 317 deletions assets/css/main.css

Large diffs are not rendered by default.

56 changes: 20 additions & 36 deletions assets/js/main.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
// Progressive enhancement for the site header. Without JavaScript the menu is
// simply always visible and the dropdowns are native <details> elements.
// Live Mars clock on the home page (NASA Mars24 algorithm, Allison & McEwen 2000).
(() => {
const toggle = document.querySelector('.nav-toggle');
const nav = document.getElementById('site-nav');
const dropdowns = Array.from(document.querySelectorAll('.dropdown'));

const setMenu = (open) => {
toggle.setAttribute('aria-expanded', String(open));
nav.classList.toggle('is-open', open);
const el = document.querySelector('[data-mars-clock]');
if (!el) return;
const mtc = el.querySelector('[data-mtc]');
const msd = el.querySelector('[data-msd]');
const utc = el.querySelector('[data-utc]');
const TT_MINUS_UTC = 37 + 32.184; // TAI-UTC (leap seconds since 2017) + TT-TAI, in seconds
const pad = (n) => String(Math.floor(n)).padStart(2, '0');
const hms = (hours) => {
const s = hours * 3600;
return `${pad(s / 3600)}:${pad((s % 3600) / 60)}:${pad(s % 60)}`;
};

if (toggle && nav) {
toggle.addEventListener('click', () => {
setMenu(toggle.getAttribute('aria-expanded') !== 'true');
});
}

const closeDropdowns = (except) => {
dropdowns.forEach((d) => { if (d !== except) d.open = false; });
const tick = () => {
const now = Date.now();
const jdTT = now / 86400000 + 2440587.5 + TT_MINUS_UTC / 86400;
const sol = (jdTT - 2405522.0028779) / 1.0274912517;
mtc.textContent = hms((((sol % 1) + 1) % 1) * 24);
msd.textContent = sol.toFixed(5);
utc.textContent = new Date(now).toISOString().slice(11, 19);
};

// One dropdown open at a time; close on outside click and on Escape.
dropdowns.forEach((d) => {
d.addEventListener('toggle', () => { if (d.open) closeDropdowns(d); });
});
document.addEventListener('click', (e) => {
if (!e.target.closest('.dropdown')) closeDropdowns();
});
document.addEventListener('keydown', (e) => {
if (e.key !== 'Escape') return;
const open = dropdowns.find((d) => d.open);
closeDropdowns();
if (open) open.querySelector('summary').focus();
else if (toggle && toggle.getAttribute('aria-expanded') === 'true') {
setMenu(false);
toggle.focus();
}
});
tick();
setInterval(tick, 1000);
})();
Loading
Loading