Dynamically determine if the files dropdown should drop up or drop down.

This commit is contained in:
Paulo Reis 2016-06-28 15:48:11 +01:00
parent 9e16f250f9
commit 88564ea126
2 changed files with 22 additions and 2 deletions

View file

@ -151,12 +151,16 @@ div.full-size.pdf(ng-controller="PdfController")
)
i.fa.fa-trash-o
|  
div.dropdown(style="display: inline-block;", dropdown)
div.files-dropdown(
style="display: inline-block;",
ng-class="shouldDropUp ? 'dropup' : 'dropdown'"
dropdown
)
a.btn.btn-default.btn-sm(
href
dropdown-toggle
)
| !{translate("other_logs_and_files")}
| !{translate("other_logs_and_files")}
span.caret
ul.dropdown-menu.dropdown-menu-right
li(ng-repeat="file in pdf.outputFiles")

View file

@ -15,6 +15,22 @@ define [
$scope.shouldShowLogs = false
$scope.wikiEnabled = window.wikiEnabled;
# view logic to check whether the files dropdown should "drop up" or "drop down"
$scope.shouldDropUp = false
logsContainerEl = document.querySelector ".pdf-logs"
filesDropdownEl = logsContainerEl?.querySelector ".files-dropdown"
# get the top coordinate of the files dropdown as a ratio (to the logs container height)
# logs container supports scrollable content, so it's possible that ratio > 1.
getFilesDropdownTopCoordAsRatio = () ->
filesDropdownEl?.getBoundingClientRect().top / logsContainerEl?.getBoundingClientRect().height
$scope.$watch "shouldShowLogs", (shouldShow) ->
if shouldShow
$scope.$applyAsync () ->
$scope.shouldDropUp = getFilesDropdownTopCoordAsRatio() > 0.65
if ace.require("ace/lib/useragent").isMac
$scope.modifierKey = "Cmd"
else