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,7 +151,11 @@ div.full-size.pdf(ng-controller="PdfController")
) )
i.fa.fa-trash-o 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( a.btn.btn-default.btn-sm(
href href
dropdown-toggle dropdown-toggle

View file

@ -15,6 +15,22 @@ define [
$scope.shouldShowLogs = false $scope.shouldShowLogs = false
$scope.wikiEnabled = window.wikiEnabled; $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 if ace.require("ace/lib/useragent").isMac
$scope.modifierKey = "Cmd" $scope.modifierKey = "Cmd"
else else