diff --git a/js/navigation.js b/js/navigation.js index 7b75628310..bb46edddf8 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -294,14 +294,23 @@ function expandTreeNode($expandElem, callback) * Auto-scrolls the newly chosen database * * @param object $element The element to set to view - * @param object $container The container srollable element + * @param boolean $forceToTop Whether to force scroll to top * */ -function scrollToView($element, $container) { - var pushToOffset = $element.offset().top - $container.offset().top + $container.scrollTop(); - $('#pma_navigation_tree_content').stop().animate({ - scrollTop: pushToOffset - }); +function scrollToView($element, $forceToTop) { + var $container = $('#pma_navigation_tree_content'); + var elemTop = $element.offset().top - $container.offset().top; + var textHeight = 20; + var scrollPadding = 20; // extra padding from top of bottom when scrolling to view + if (elemTop < 0 || $forceToTop) { + $container.stop().animate({ + scrollTop: elemTop + $container.scrollTop() - scrollPadding + }); + } else if (elemTop + textHeight > $container.height()) { + $container.stop().animate({ + scrollTop: elemTop + textHeight - $container.height() + $container.scrollTop() + scrollPadding + }); + } } /** @@ -400,10 +409,10 @@ function PMA_showCurrentNavigation() if ($tableContainer.length > 0) { var $expander = $tableContainer.children('div:first').children('a.expander'); expandTreeNode($expander, function () { - scrollToView($dbItem, $('#pma_navigation_tree_content')); + scrollToView($dbItem, true); }); } else { - scrollToView($dbItem, $('#pma_navigation_tree_content')); + scrollToView($dbItem, true); } } } @@ -473,6 +482,9 @@ function PMA_showCurrentNavigation() } else { // no containers, highlight the item var $tableOrView = findLoadedItem($container, table, null, true); + if ($tableOrView){ + scrollToView($tableOrView, false); + } } } @@ -489,6 +501,9 @@ function PMA_showCurrentNavigation() $tableContainer.children('div.list_container'), table, 'table', true ); + if ($table) { + scrollToView($table, false); + } } else if ($viewContainer.length > 0) { highlightView($viewContainer, table); } @@ -519,12 +534,18 @@ function PMA_showCurrentNavigation() $viewContainer.children('div.list_container'), view, 'view', true ); + if ($view) { + scrollToView($view, false); + } }); } else { var $view = findLoadedItem( $viewContainer.children('div.list_container'), view, 'view', true ); + if ($view) { + scrollToView($view, false); + } } } }