Skip to content

Commit 260c9f0

Browse files
author
Konrad Michalik
authored
Merge pull request #23 from xima-media/fix-position
fix: improve dropdown menu positioning based on element's page context
2 parents f953950 + fdb2176 commit 260c9f0

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Resources/Public/JavaScript/frontend_edit.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ document.addEventListener('DOMContentLoaded', function () {
9999

100100
element.addEventListener('mouseover', function () {
101101
let rect = element.getBoundingClientRect();
102+
let rectInPageContext = {
103+
top: rect.top + document.documentElement.scrollTop,
104+
left: rect.left + document.documentElement.scrollLeft,
105+
width: rect.width,
106+
height: rect.height
107+
};
108+
102109

103110
let defaultEditButtonMargin = 10;
104111
let defaultEditButtonHeight = 30;
@@ -109,7 +116,7 @@ document.addEventListener('DOMContentLoaded', function () {
109116

110117
// if the dropdown menu is too close to the bottom of the page, move it to the top
111118
// currently it's not possible to fetch the height of the dropdown menu before it's visible once, so we have to use a fixed value
112-
if (document.documentElement.clientHeight - rect.top - rect.height < 500) {
119+
if (document.documentElement.scrollHeight - rectInPageContext.top - rect.height < 500 && rect.height < 700) {
113120
dropdownMenu.style.bottom = `19px`;
114121
} else {
115122
dropdownMenu.style.top = `${defaultEditButtonMargin + 30}px`;

0 commit comments

Comments
 (0)