From cc9572d9c58122a04c810db5acfc216eec3f1504 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 12 Jun 2023 13:12:28 +0200 Subject: [PATCH] Flyout menu: Render menu `bottom-up` if it exceeds the viewport height --- public/css/icinga/menu.less | 6 ++++++ public/js/icinga/behavior/navigation.js | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/public/css/icinga/menu.less b/public/css/icinga/menu.less index 98650a237..e9ed78808 100644 --- a/public/css/icinga/menu.less +++ b/public/css/icinga/menu.less @@ -270,6 +270,12 @@ left: -.6em; z-index: -1; } + + &.bottom-up:after { + top: unset; + bottom: 1em; + } + > .nav-item { display: block; padding-left: 0; diff --git a/public/js/icinga/behavior/navigation.js b/public/js/icinga/behavior/navigation.js index df0e1e6d8..bcf5bebd5 100644 --- a/public/js/icinga/behavior/navigation.js +++ b/public/js/icinga/behavior/navigation.js @@ -319,18 +319,22 @@ $target.siblings().not($target).removeClass('hover'); $target.addClass('hover'); + var targetHeight = $target.offset().top + $target.outerHeight(); $flyout.css({ bottom: 'auto', - top: $target.offset().top + $target.outerHeight() + top: targetHeight }); var rect = $flyout[0].getBoundingClientRect(); - if (rect.y + rect.height > window.innerHeight) { + if (rect.bottom > window.innerHeight) { + $flyout.addClass('bottom-up'); $flyout.css({ - bottom: 0, + bottom: window.innerHeight - targetHeight, top: 'auto' }); + } else { + $flyout.removeClass('bottom-up'); } }, delay); };