oficina / slides Public

Clone
git clone https://amadan.net/oficina/slides

Plain git — no account needed to clone.

Download

Download this file

1// quiet-bar.mjs — the slide window's control bar, out of sight while
2// presenting (templates/present.html styles it by [data-quiet] on the
3// surface; without scripts the attribute is never set and the bar stays).
4// A pointer moving, or focus entering the bar, shows it. It goes after two
5// seconds of stillness while the pointer is off it and focus is outside,
6// and when the talk moves (the slide, the step or the blackout the window
7// draws). Focus inside the bar holds it, whatever the talk does.
8// static/present.js carries a small copy: a classic script cannot import.
9export function quietBar (root, wait = 2000) {
10 let timer
11 const focused = () => root.querySelector('[slides-bar]:focus-within')
12 const hide = () => { clearTimeout(timer); root.setAttribute('data-quiet', '') }
13 const rest = () => {
14 clearTimeout(timer)
15 timer = setTimeout(() => { if (!focused() && !root.querySelector('[slides-bar]:hover')) hide() }, wait)
16 }
17 const show = () => { root.removeAttribute('data-quiet'); rest() }
18 hide()
19 root.addEventListener('pointermove', show)
20 root.addEventListener('pointerleave', () => { if (!root.hasAttribute('data-quiet')) rest() })
21 root.addEventListener('focusin', e => { if (e.target.closest('[slides-bar]')) show() })
22 root.addEventListener('focusout', e => { if (e.target.closest('[slides-bar]')) show() })
23 const seen = ['data-slide', 'data-step', 'data-blackout']
24 new MutationObserver(records => {
25 if (!focused() && records.some(r => r.target.getAttribute(r.attributeName) !== r.oldValue)) hide()
26 }).observe(root, { attributes: true, attributeFilter: seen, attributeOldValue: true })
27}
28