From eef55d4b46a6c1d8e5bfeadb8d7d5d622961b656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pauli=20J=C3=A4rvinen?= Date: Sat, 26 Aug 2023 17:14:40 +0300 Subject: [PATCH] Scroll navigation pane automatically on view activation In case there are enough playlists to make the navigation pane scrollable, the link to the activated view may be off the view port. In such occasions, the navigation pane is now scrolled automatically upon view activation to make the link of the activated view visible. This is useful mostly when the view activation happens as response to some other action than clicking the navigation pane link (say, creating a new playlist or clicking the playing song name on the controls pane to jump to the playing view). refs https://github.com/owncloud/music/issues/1083 --- js/app/controllers/navigationcontroller.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/js/app/controllers/navigationcontroller.js b/js/app/controllers/navigationcontroller.js index fd919597b..96c2bf9a0 100644 --- a/js/app/controllers/navigationcontroller.js +++ b/js/app/controllers/navigationcontroller.js @@ -400,6 +400,17 @@ angular.module('Music').controller('NavigationController', [ $scope.togglePlay($rootScope.currentView, playlist); } } + // ensure that the link to the current view is visible in the navigation pane, + // in case there are so many playlists that the navigation pane is scrollable + $timeout(() => { + const navPaneContent = $('#app-navigation ul'); + const navItem = navPaneContent.find('.music-navigation-item.active'); + const navItemTop = navItem.offset().top - $('#header').height(); + const navItemBottom = navItemTop + navItem.height(); + if (navItemTop < 0 || navItemBottom > navPaneContent.innerHeight()) { + navPaneContent.scrollToElement(navItem, 0, 300); + } + }); }); } ]);