Skip to content

Commit

Permalink
Merge pull request #19 from pumpadump/master
Browse files Browse the repository at this point in the history
fixed #17 context menu repositions if off screen to the right or bottom
  • Loading branch information
kinimesi authored Oct 26, 2017
2 parents c2576c3 + 9ec2005 commit d43e249
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cytoscape-context-menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@
var currentCxtMenuPosition = getScratchProp('cxtMenuPosition');
var cyPos = event.position || event.cyPosition;

if( currentCxtMenuPosition != cyPos ) {
if (currentCxtMenuPosition != cyPos) {
var cxtMenuWidth = $cxtMenu.width();
var cxtMenuHeight = $cxtMenu.height();
hideMenuItemComponents();
setScratchProp('anyVisibleChild', false);// we hide all children there is no visible child remaining
setScratchProp('cxtMenuPosition', cyPos);
Expand All @@ -209,6 +211,16 @@

var left = containerPos.left + renderedPos.x;
var top = containerPos.top + renderedPos.y;

var windowHeight = window.innerHeight;
var windowWidth = window.innerWidth;
if (left + cxtMenuWidth > windowWidth) {
left = left - cxtMenuWidth;
}

if (top + cxtMenuHeight > windowHeight) {
top = top - cxtMenuHeight
}

$cxtMenu.css('left', left);
$cxtMenu.css('top', top);
Expand Down

0 comments on commit d43e249

Please sign in to comment.