Skip to content

Commit d189cd2

Browse files
sub menu out of position #533
1 parent 2da615a commit d189cd2

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

src/jquery.contextMenu.js

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,26 +1546,49 @@
15461546
// operation that will run after contextMenu showed on screen
15471547
activated: function(menu){
15481548
var $menu = menu;
1549+
var win = $(window);
15491550
var $menuOffset = $menu.offset();
1550-
var winHeight = $(window).height();
1551-
var winScrollTop = $(window).scrollTop();
1552-
var menuHeight = $menu.height();
1551+
var winHeight = win.height();
1552+
var winWidth = win.width();
1553+
var winScrollTop = win.scrollTop();
1554+
var menuHeight = $menu.outerHeight();
1555+
var menuWidth = $menu.outerWidth();
15531556
if(menuHeight > winHeight){
15541557
$menu.css({
1555-
'height' : winHeight + 'px',
1556-
'overflow-x': 'hidden',
1557-
'overflow-y': 'auto',
1558-
'top': winScrollTop + 'px'
1559-
});
1558+
'height': winHeight -
1559+
(parseInt($menu.css('padding-top'))+parseInt($menu.css('margin-top')))+'px',
1560+
'overflow-x':'hidden',
1561+
'overflow-y':'auto',
1562+
'top':winScrollTop+'px'
1563+
});
15601564
} else if($menuOffset.top < winScrollTop){
1561-
$menu.css({
1562-
'top': '0px'
1563-
});
1564-
} else if($menuOffset.top + menuHeight > winScrollTop + winHeight){
1565-
$menu.css({
1566-
'top':$menuOffset.top- Math.abs((winScrollTop+winHeight) - ($menuOffset.top+menuHeight))
1567-
});
1568-
}
1565+
$menu.css({
1566+
'top':'0px'
1567+
});
1568+
} else if($menuOffset.top+menuHeight > winScrollTop + winHeight){
1569+
$menu.css({
1570+
'top':$menuOffset.top - Math.abs((winScrollTop+winHeight)-($menuOffset.top+menuHeight)) -(parseInt($menu.css('padding-top'))+parseInt($menu.css('margin-top')))+'px'
1571+
});
1572+
}
1573+
if($menuOffset.left + menuWidth > winWidth){
1574+
var newLeftPosition = $menuOffset.left - Math.abs(($menuOffset.left+menuWidth) - winWidth);
1575+
var parent = $menu.parents('ul.context-menu-list').first();
1576+
if(parent.length){
1577+
if(newLeftPosition <= parent.offset().left + parent.outerWidth()
1578+
&& newLeftPosition >= parent.offset().left){
1579+
$menu.css({
1580+
'left':parent.offset().left - $menu.outerWidth() + 'px'
1581+
});
1582+
}else{
1583+
$menu.css({
1584+
'left':$menuOffset.left-Math.abs(($menuOffset.left+menuWidth) - winWidth) + 'px'
1585+
});
1586+
}
1587+
}else{
1588+
$menu.css({
1589+
'left':$menuOffset.left-Math.abs(($menuOffset.left+menuWidth) - winWidth) + 'px'
1590+
});
1591+
}
15691592
}
15701593
};
15711594

0 commit comments

Comments
 (0)