Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent nested menu from obscuring parent when user clicks towards right edge of window #144

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,10 @@
topCoordinate = event.pageY - menuHeight;
/// If the element is a nested menu, adds the height of the parent li to the topCoordinate to align with the parent
if(level && level > 0) {
topCoordinate += event.event.currentTarget.offsetHeight;
// but not so much that it overflows off the bottom of the window
var maxHeight = $document[0].body.clientHeight - $window.scrollY - menuHeight - 20;
var adjustedHeight = topCoordinate + event.event.currentTarget.offsetHeight;
topCoordinate = Math.min(maxHeight, adjustedHeight);
}
} else if(winHeight <= menuHeight) {
// If it really can't fit, reset the height of the menu to one that will fit
Expand All @@ -410,7 +413,7 @@

var leftCoordinate = event.pageX;
var menuWidth = angular.element($ul[0]).prop('offsetWidth');
var winWidth = event.view.innerWidth + window.pageXOffset;
var winWidth = event.view.innerWidth + $window.pageXOffset;
var padding = 5;

if (leftOriented) {
Expand All @@ -427,7 +430,11 @@
}
} else {
if (leftCoordinate > menuWidth && winWidth - leftCoordinate - padding < menuWidth) {
leftCoordinate = winWidth - menuWidth - padding;
if(level && level > 0) {
leftCoordinate = leftCoordinate - (1.5 * menuWidth);
} else {
leftCoordinate = winWidth - menuWidth - padding;
}
} else if(winWidth - leftCoordinate < menuWidth) {
var reduceThresholdX = 5;
if(leftCoordinate < reduceThresholdX + padding) {
Expand Down