catalog: auto-scroll on up/down navigation via scrollIntoView (native Lampa behaviour)
This commit is contained in:
1 parent
15b42ce9b5
commit
318c45f99f
1 file changed
+7
-9
@@ -88,7 +88,6 @@
|
||||
};
|
||||
|
||||
this.destroy = function () {
|
||||
if (comp._scrollObserver) { comp._scrollObserver.disconnect(); comp._scrollObserver = null; }
|
||||
};
|
||||
|
||||
// Wire up keyboard/remote navigation (pattern from Shikimori plugin).
|
||||
@@ -104,20 +103,20 @@
|
||||
var first = !apply._inited;
|
||||
apply._inited = true;
|
||||
|
||||
// Auto-scroll the grid so the focused card stays visible (native Lampa behaviour).
|
||||
if (!comp._scrollObserver) {
|
||||
comp._scrollObserver = new MutationObserver(function () {
|
||||
var el = g.find('.card.selector.focus')[0];
|
||||
if (el && el.scrollIntoView) el.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
||||
});
|
||||
comp._scrollObserver.observe(g[0], { attributes: true, subtree: true, attributeFilter: ['class'] });
|
||||
// Auto-scroll helper: keep the focused card visible (native Lampa behaviour).
|
||||
function scrollFocused() {
|
||||
var el = g.find('.card.selector.focus')[0];
|
||||
if (el && el.scrollIntoView) el.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
||||
}
|
||||
|
||||
Lampa.Controller.add('content', {
|
||||
toggle: function () {
|
||||
Lampa.Controller.collectionSet(g);
|
||||
if (first) Lampa.Controller.collectionFocus(cards[0], g);
|
||||
setTimeout(scrollFocused, 50);
|
||||
},
|
||||
up: function () { Navigator.move('up'); setTimeout(scrollFocused, 50); },
|
||||
down: function () { Navigator.move('down'); setTimeout(scrollFocused, 50); },
|
||||
enter: function () {
|
||||
var el = g.find('.card.selector.focus')[0] || cards[0];
|
||||
if (!el) return;
|
||||
@@ -128,7 +127,6 @@
|
||||
back: function () { Lampa.Activity.backward(); },
|
||||
gone: function () {
|
||||
Lampa.Controller.clear('content');
|
||||
if (comp._scrollObserver) { comp._scrollObserver.disconnect(); comp._scrollObserver = null; }
|
||||
}
|
||||
});
|
||||
Lampa.Controller.toggle('content');
|
||||
|
||||
Reference in new issue
Block a user