levkin.ca/stack-folder/folder-rail.js
ilia 21c75cdcba Rebuild stack-folder with sticky tab rail and site previews.
L0–L7 folders stack on scroll with aligned max depth, labeled tabs that
stay consistent when L7 joins the rail, Cal embeds, preview screenshots,
Playwright tests, and updated README.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 21:30:05 -04:00

33 lines
953 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** Fixed rail — all L0L7 visible; click to jump (syncs with scroll) */
export function initRailRoller(rail = document.querySelector('.tab-rail')) {
const tabs = rail ? [...rail.querySelectorAll('.rail-tab')] : [];
if (!rail || !tabs.length) return;
function setActive(layer) {
const n = Math.max(0, Math.min(tabs.length - 1, layer));
tabs.forEach((btn, i) => btn.classList.toggle('active', i === n));
}
function gotoLayer(layer) {
setActive(layer);
window.dispatchEvent(
new CustomEvent('stack-goto-layer', { detail: { layer } }),
);
}
tabs.forEach((btn) => {
btn.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
gotoLayer(Number(btn.dataset.layer ?? btn.dataset.goto));
});
});
window.addEventListener('stack-depth', (e) => {
const layer = Number(e.detail?.active);
if (Number.isFinite(layer)) setActive(layer);
});
setActive(0);
}