-
-
Save anonymous/2b5f137b771452282d68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('body').on('keyup.search', function(e) { | |
if ($('#search-dropdown').is(':visible')) { | |
if (e.which == 40 || e.which == 38){ | |
var searchController = Discourse.__container__.lookup("controller:search"); | |
var selectedIndex = searchController.get("selectedIndex"); | |
var $searchContainer = $("#search-dropdown"); | |
var elm = $("#search-dropdown li.selected"); //get the selected element | |
var elm_position = elm.position(); | |
var elm_bottom = elm_position.top+elm.height(); | |
if ( $searchContainer[0].scrollTop + $("#search-dropdown").height() < elm_bottom + $searchContainer[0].scrollTop ){ | |
$searchContainer[0].scrollTop = elm_bottom - $searchContainer.height()+ $searchContainer[0].scrollTop; | |
} else if ( elm_position.top < 0){ | |
$searchContainer[0].scrollTop += elm_position.top -15; | |
} | |
if ( (typeof selectedIndex !== "undefined") && selectedIndex == 0 && $searchContainer[0].scrollTop > 0){ | |
$("#search-dropdown").animate({scrollTop:0},500,'swing'); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment