From e6349c016ee87d3ceb97ab6ca02687633835ffec Mon Sep 17 00:00:00 2001 From: pewdiepie-archdaemon Date: Sat, 13 Jun 2026 20:12:30 +0900 Subject: [PATCH] Cookbook auto-fold: auto-expand when scrolling back to top MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scroll handler now tracks per-target scrollTop via WeakMap. Downward scroll on any scroller in the cookbook modal folds Direct Download; scrolling back to top (scrollTop <= 0) unfolds it. Manual chevron clicks still win — they persist to localStorage; auto-toggles don't, so the user's last explicit pick survives reload. --- static/js/cookbook.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/static/js/cookbook.js b/static/js/cookbook.js index e196e7006..ee71300f2 100644 --- a/static/js/cookbook.js +++ b/static/js/cookbook.js @@ -1415,26 +1415,30 @@ function _wireTabEvents(body) { const folded = dlFoldBody.style.display === 'none'; _setFolded(!folded); }); - // Auto-fold when the user scrolls inside any scroll container — - // the outer cookbook-body / modal-content (which moves the header - // out of view) OR the nested hwfit results list (which doesn't - // move the header but signals the user is now focused on results). - // Doesn't auto-unfold; chevron ▸ still expands manually. + // Auto-fold on any downward scroll inside the cookbook modal, + // and auto-expand when the user scrolls all the way back to the + // top of whichever scroller they're in. The chevron ▸ still + // toggles manually. const _maybeFold = () => { if (dlFoldBody.style.display === 'none') return; _setFolded(true, /* persist */ false); }; - // Catch every scroll event anywhere inside the cookbook modal - // (capture phase so even non-bubbling scrolls on nested scrollers - // like .hwfit-list hit us). + const _maybeExpand = () => { + if (dlFoldBody.style.display !== 'none') return; + _setFolded(false, /* persist */ false); + }; + // Capture phase so scrolls on nested scrollers (.hwfit-list, + // .cookbook-body, .modal-content) all hit us. const _modal = dlFold.closest('#cookbook-modal') || document; - let _lastY = 0; + const _lastY = new WeakMap(); _modal.addEventListener('scroll', (e) => { - // Only fold on scroll DOWN — ignore upward / horizontal scrolls. const tgt = e.target; - const y = (tgt && typeof tgt.scrollTop === 'number') ? tgt.scrollTop : 0; - if (y > _lastY) _maybeFold(); - _lastY = y; + if (!tgt || typeof tgt.scrollTop !== 'number') return; + const y = tgt.scrollTop; + const prev = _lastY.get(tgt) || 0; + if (y > prev) _maybeFold(); + else if (y <= 0) _maybeExpand(); + _lastY.set(tgt, y); }, true); } const hfToggle = document.getElementById('cookbook-hf-latest-toggle'); @@ -1862,13 +1866,13 @@ function _renderRecipes() { // Latest HF models that fit — collapsible card list html += `
`; html += `
`; - html += ``; html += `
`; html += ``;