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
28 changes: 25 additions & 3 deletions design/assets/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@
.switcher[data-pager] .switcher-tabs { display: none; }
.pager { position: relative; flex: 0 1 auto; min-width: 0; display: flex; gap: 4px; }
.switcher.switcher .pager-now { min-width: 0; max-width: 340px; justify-content: flex-start; }
.pager-name { overflow: hidden; text-overflow: ellipsis; }
/* the name and the place keep one width, the longest of all they can say (each cell's hidden .pager-fit, laid over
it), so ‹ and › stay put while you step; a name over 24ch ends in … and the name's title holds it whole */
.pager-cell { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; }
.pager-cell > * { grid-area: 1 / 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.pager-cell:first-child { max-width: 24ch; }
.pager-fit { visibility: hidden; height: 0; white-space: pre; }
.pager-of, .pager-caret { flex: none; color: var(--bar-muted); font-weight: 500; } .pager-of:empty { display: none; }
.pager-of, .pager-of + .pager-fit { font-variant-numeric: tabular-nums; }
.switcher.switcher :is(.pager-prev, .pager-next) { width: 28px; padding: 0; font-size: 17px; }
.pager-menu { position: absolute; z-index: 2; top: calc(100% + 6px); left: 0; display: grid; width: min(300px, calc(100vw - 24px));
max-height: min(60vh, 480px); overflow: auto; padding: 4px; background: var(--bar-bg); color: var(--bar-ink);
Expand Down Expand Up @@ -651,9 +657,12 @@
if (!p) { p = el('div', 'pager'); tabs.before(p); }
const key = (cls, text, name) => { const b = el('button', cls, text); b.type = 'button'; if (name) b.setAttribute('aria-label', name); return b; };
const prev = key('pager-prev', '\u2039', 'Previous frame'), next = key('pager-next', '\u203a', 'Next frame'), now = key('pager-now');
prev.title = 'Previous frame (\u2190, h or k)'; next.title = 'Next frame (\u2192, l or j)';
prev.setAttribute('aria-keyshortcuts', 'h k'); next.setAttribute('aria-keyshortcuts', 'l j');
now.setAttribute('aria-haspopup', 'menu'); now.setAttribute('aria-expanded', 'false');
const caret = el('span', 'pager-caret', '\u25be'); caret.setAttribute('aria-hidden', 'true');
now.append(el('span', 'pager-name'), el('span', 'pager-of'), caret);
const n = all().length, cell = (cls, fit) => { const c = el('span', 'pager-cell'), f = el('span', 'pager-fit', fit.join('\n')); f.setAttribute('aria-hidden', 'true'); c.append(el('span', cls), f); return c; };
now.append(cell('pager-name', ['All ' + n + ' frames', ...all().map(label)]), cell('pager-of', [n + ' of ' + n]), caret);
const menu = el('div', 'pager-menu menu'); menu.setAttribute('role', 'menu'); menu.setAttribute('aria-label', 'Frames'); menu.hidden = true;
if ('popover' in menu) menu.popover = 'manual'; // opened in the top layer: a frame's own fixed bar or nav can't draw over it
if (all().length > 8) { const f = el('input', 'pager-filter'); f.type = 'search'; f.placeholder = 'Filter frames'; f.setAttribute('aria-label', 'Filter frames'); menu.append(f); }
Expand All @@ -676,6 +685,7 @@
const name = all_ ? 'All ' + dirs.length + ' frames' : label(cur), of = all_ ? '' : (dirs.indexOf(cur) + 1) + ' of ' + dirs.length;
const set = (x, t) => { if (x.textContent !== t) x.textContent = t; }; // unchanged: no mutation to answer
set(p.querySelector('.pager-name'), name); set(p.querySelector('.pager-of'), of);
const now = p.querySelector('.pager-now'); if (now.title !== name) now.title = name; // whole, where the name ends in …
p.querySelectorAll('.pager-item').forEach((b) => { const on = String(!all_ && b.dataset.for === (cur && cur.dataset.ssId)); if (b.getAttribute('aria-checked') !== on) b.setAttribute('aria-checked', on); });
}
function openMenu() {
Expand Down Expand Up @@ -741,7 +751,18 @@
else if ((e.key === 'Enter' || e.key === ' ') && i >= 0) { e.preventDefault(); shutMenu(true); t.click(); }
else if (e.key === 'Tab') shutMenu(false);
}
window.ssPager = { click: pagerClick, key: pagerKey, filter: (e) => { if (e.target.matches && e.target.matches('.pager-filter')) filterMenu(e.target); }, place, rows };
// h or k steps to the frame before, l or j to the next, from anywhere on the page but a field, a menu or the
// Prototype bar, with no modifier held, and while no menu shows (one in a hidden frame doesn't count). Heard last (the
// document, bubbling), so a key a frame takes is left to it.
function hop(e) {
const p = pagerNow(), t = e.target, k = e.key;
if (!p || !/^[hjkl]$/.test(k) || e.defaultPrevented || e.metaKey || e.ctrlKey || e.altKey || e.shiftKey || e.isComposing
|| document.body.getAttribute('data-ss-edit') === 'paper' || [...document.querySelectorAll('.menu:not([hidden])')].some((m) => m.getClientRects().length)) return; // a menu shown
if (t && (t.isContentEditable || (t.closest && t.closest('input,textarea,select,[contenteditable],[role=textbox],[role=menu],.menu,.tweaks,[data-ss-ui]')))) return;
e.preventDefault();
p.querySelector(k === 'h' || k === 'k' ? '.pager-prev' : '.pager-next').click();
}
window.ssPager = { click: pagerClick, key: pagerKey, filter: (e) => { if (e.target.matches && e.target.matches('.pager-filter')) filterMenu(e.target); }, place, rows, hop };
if (!window.ssPagerHeard) {
window.ssPagerHeard = true;
document.addEventListener('click', (e) => window.ssPager.click(e), true);
Expand All @@ -750,6 +771,7 @@
document.addEventListener('scroll', () => window.ssPager.place(), true); // the menu follows the pager
window.addEventListener('resize', () => window.ssPager.place());
}
if (!window.ssPagerHops) { window.ssPagerHops = true; document.addEventListener('keydown', (e) => window.ssPager.hop(e)); }
// The bar's line: the direction's data-line, or, while a direction (or one of its views) is open full page, the
// intro of its about block, so a phone, where the blocks hide, still says what it is for and how to try it.
const opened = () => {
Expand Down
28 changes: 25 additions & 3 deletions design/assets/starter.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@
.switcher[data-pager] .switcher-tabs { display: none; }
.pager { position: relative; flex: 0 1 auto; min-width: 0; display: flex; gap: 4px; }
.switcher.switcher .pager-now { min-width: 0; max-width: 340px; justify-content: flex-start; }
.pager-name { overflow: hidden; text-overflow: ellipsis; }
/* the name and the place keep one width, the longest of all they can say (each cell's hidden .pager-fit, laid over
it), so ‹ and › stay put while you step; a name over 24ch ends in … and the name's title holds it whole */
.pager-cell { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; }
.pager-cell > * { grid-area: 1 / 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.pager-cell:first-child { max-width: 24ch; }
.pager-fit { visibility: hidden; height: 0; white-space: pre; }
.pager-of, .pager-caret { flex: none; color: var(--bar-muted); font-weight: 500; } .pager-of:empty { display: none; }
.pager-of, .pager-of + .pager-fit { font-variant-numeric: tabular-nums; }
.switcher.switcher :is(.pager-prev, .pager-next) { width: 28px; padding: 0; font-size: 17px; }
.pager-menu { position: absolute; z-index: 2; top: calc(100% + 6px); left: 0; display: grid; width: min(300px, calc(100vw - 24px));
max-height: min(60vh, 480px); overflow: auto; padding: 4px; background: var(--bar-bg); color: var(--bar-ink);
Expand Down Expand Up @@ -624,9 +630,12 @@
if (!p) { p = el('div', 'pager'); tabs.before(p); }
const key = (cls, text, name) => { const b = el('button', cls, text); b.type = 'button'; if (name) b.setAttribute('aria-label', name); return b; };
const prev = key('pager-prev', '\u2039', 'Previous frame'), next = key('pager-next', '\u203a', 'Next frame'), now = key('pager-now');
prev.title = 'Previous frame (\u2190, h or k)'; next.title = 'Next frame (\u2192, l or j)';
prev.setAttribute('aria-keyshortcuts', 'h k'); next.setAttribute('aria-keyshortcuts', 'l j');
now.setAttribute('aria-haspopup', 'menu'); now.setAttribute('aria-expanded', 'false');
const caret = el('span', 'pager-caret', '\u25be'); caret.setAttribute('aria-hidden', 'true');
now.append(el('span', 'pager-name'), el('span', 'pager-of'), caret);
const n = all().length, cell = (cls, fit) => { const c = el('span', 'pager-cell'), f = el('span', 'pager-fit', fit.join('\n')); f.setAttribute('aria-hidden', 'true'); c.append(el('span', cls), f); return c; };
now.append(cell('pager-name', ['All ' + n + ' frames', ...all().map(label)]), cell('pager-of', [n + ' of ' + n]), caret);
const menu = el('div', 'pager-menu menu'); menu.setAttribute('role', 'menu'); menu.setAttribute('aria-label', 'Frames'); menu.hidden = true;
if ('popover' in menu) menu.popover = 'manual'; // opened in the top layer: a frame's own fixed bar or nav can't draw over it
if (all().length > 8) { const f = el('input', 'pager-filter'); f.type = 'search'; f.placeholder = 'Filter frames'; f.setAttribute('aria-label', 'Filter frames'); menu.append(f); }
Expand All @@ -649,6 +658,7 @@
const name = all_ ? 'All ' + dirs.length + ' frames' : label(cur), of = all_ ? '' : (dirs.indexOf(cur) + 1) + ' of ' + dirs.length;
const set = (x, t) => { if (x.textContent !== t) x.textContent = t; }; // unchanged: no mutation to answer
set(p.querySelector('.pager-name'), name); set(p.querySelector('.pager-of'), of);
const now = p.querySelector('.pager-now'); if (now.title !== name) now.title = name; // whole, where the name ends in …
p.querySelectorAll('.pager-item').forEach((b) => { const on = String(!all_ && b.dataset.for === (cur && cur.dataset.ssId)); if (b.getAttribute('aria-checked') !== on) b.setAttribute('aria-checked', on); });
}
function openMenu() {
Expand Down Expand Up @@ -714,7 +724,18 @@
else if ((e.key === 'Enter' || e.key === ' ') && i >= 0) { e.preventDefault(); shutMenu(true); t.click(); }
else if (e.key === 'Tab') shutMenu(false);
}
window.ssPager = { click: pagerClick, key: pagerKey, filter: (e) => { if (e.target.matches && e.target.matches('.pager-filter')) filterMenu(e.target); }, place, rows };
// h or k steps to the frame before, l or j to the next, from anywhere on the page but a field, a menu or the
// Prototype bar, with no modifier held, and while no menu shows (one in a hidden frame doesn't count). Heard last (the
// document, bubbling), so a key a frame takes is left to it.
function hop(e) {
const p = pagerNow(), t = e.target, k = e.key;
if (!p || !/^[hjkl]$/.test(k) || e.defaultPrevented || e.metaKey || e.ctrlKey || e.altKey || e.shiftKey || e.isComposing
|| document.body.getAttribute('data-ss-edit') === 'paper' || [...document.querySelectorAll('.menu:not([hidden])')].some((m) => m.getClientRects().length)) return; // a menu shown
if (t && (t.isContentEditable || (t.closest && t.closest('input,textarea,select,[contenteditable],[role=textbox],[role=menu],.menu,.tweaks,[data-ss-ui]')))) return;
e.preventDefault();
p.querySelector(k === 'h' || k === 'k' ? '.pager-prev' : '.pager-next').click();
}
window.ssPager = { click: pagerClick, key: pagerKey, filter: (e) => { if (e.target.matches && e.target.matches('.pager-filter')) filterMenu(e.target); }, place, rows, hop };
if (!window.ssPagerHeard) {
window.ssPagerHeard = true;
document.addEventListener('click', (e) => window.ssPager.click(e), true);
Expand All @@ -723,6 +744,7 @@
document.addEventListener('scroll', () => window.ssPager.place(), true); // the menu follows the pager
window.addEventListener('resize', () => window.ssPager.place());
}
if (!window.ssPagerHops) { window.ssPagerHops = true; document.addEventListener('keydown', (e) => window.ssPager.hop(e)); }
// The bar's line: the direction's data-line, or, while a direction (or one of its views) is open full page, the
// intro of its about block, so a phone, where the blocks hide, still says what it is for and how to try it.
const opened = () => {
Expand Down
Loading