Skip to content

Commit c45629f

Browse files
authored
Merge pull request #1556 from dpvc/issue1434
Improve menu placement. #1434
2 parents 71369c3 + edc2618 commit c45629f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

unpacked/extensions/MathMenu.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@
313313
this.posted = true;
314314
if (menu.offsetWidth) menu.style.width = (menu.offsetWidth+2) + "px";
315315
var x = event.pageX, y = event.pageY;
316+
var bbox = document.body.getBoundingClientRect();
317+
var styles = (window.getComputedStyle ? window.getComputedStyle(document.body) : {marginLeft: "0px"});
318+
var bodyRight = bbox.right - Math.min(0,bbox.left) + parseFloat(styles.marginLeft);
316319
if (!x && !y && "clientX" in event) {
317320
x = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
318321
y = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
@@ -326,8 +329,8 @@
326329
x = (rect.right + rect.left) / 2 + offsetX;
327330
y = (rect.bottom + rect.top) / 2 + offsetY;
328331
}
329-
if (x + menu.offsetWidth > document.body.offsetWidth - this.margin)
330-
{x = document.body.offsetWidth - menu.offsetWidth - this.margin}
332+
if (x + menu.offsetWidth > bodyRight - this.margin)
333+
{x = bodyRight - menu.offsetWidth - this.margin}
331334
if (MENU.isMobile) {x = Math.max(5,x-Math.floor(menu.offsetWidth/2)); y -= 20}
332335
MENU.skipUp = event.isContextMenu;
333336
} else {
@@ -339,7 +342,7 @@
339342
}
340343
if (!MENU.isMobile) {
341344
if ((MENU.isRTL && x - mw - menu.offsetWidth > this.margin) ||
342-
(!MENU.isRTL && x + menu.offsetWidth > document.body.offsetWidth - this.margin))
345+
(!MENU.isRTL && x + menu.offsetWidth > bodyRight - this.margin))
343346
{side = "right"; x = Math.max(this.margin,x - mw - menu.offsetWidth + 6)}
344347
}
345348
if (!isPC) {

0 commit comments

Comments
 (0)