diff options
author | Phil Hughes <me@iamphill.com> | 2016-03-24 11:01:23 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2016-03-31 16:24:33 +0100 |
commit | 858eee9ee851e6346e38582ab4b102fc038490c0 (patch) | |
tree | 0aa2bc2447ced9892000ac7356d2f6936fec06e0 | |
parent | b244317a38f80740bd1508362316c8e70424f14c (diff) | |
download | gitlab-ce-858eee9ee851e6346e38582ab4b102fc038490c0.tar.gz |
Correctly scrolls the dropdown up & down with arrow keys
-rw-r--r-- | app/assets/javascripts/gl_dropdown.js.coffee | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index 094b1a12408..e7572e4eda9 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -436,15 +436,22 @@ class GitLabDropdown # Dropdown content scroll area $dropdownContent = $listItem.closest('.dropdown-content') - dropdownContentBottom = $dropdownContent.prop('offsetTop') + $dropdownContent.prop('offsetHeight') + dropdownScrollTop = $dropdownContent.prop('scrollTop') + dropdownContentHeight = $dropdownContent.prop('offsetHeight') + dropdownContentTop = $dropdownContent.prop('offsetTop') + dropdownContentBottom = dropdownContentTop + dropdownContentHeight # Get the offset bottom of the list item - listItemBottom = $listItem.prop('offsetTop') + $listItem.prop('offsetHeight') - console.log listItemBottom, dropdownContentBottom + listItemHeight = $listItem.prop('offsetHeight') + listItemTop = $listItem.prop('offsetTop') + listItemBottom = listItemTop + listItemHeight - if listItemBottom > dropdownContentBottom + if listItemBottom > dropdownContentBottom + dropdownScrollTop # Scroll the dropdown content down $dropdownContent.scrollTop(listItemBottom - dropdownContentBottom) + else if listItemTop < dropdownContentTop + dropdownScrollTop + # Scroll the dropdown content up + $dropdownContent.scrollTop(listItemTop - dropdownContentTop) $.fn.glDropdown = (opts) -> return @.each -> |