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 += `