Skip to content

Commit 847ea2b

Browse files
Fixed "sub menu out of position #533 "
1 parent 8427585 commit 847ea2b

7 files changed

+94
-17
lines changed

dist/jquery.contextMenu.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Licensed under
1313
* MIT License http://www.opensource.org/licenses/mit-license
1414
*
15-
* Date: 2017-08-30T12:16:04.938Z
15+
* Date: 2017-10-26T16:51:13.541Z
1616
*/
1717
@-webkit-keyframes cm-spin {
1818
0% {
@@ -54,8 +54,8 @@
5454
font-style: normal;
5555
font-weight: normal;
5656

57-
src: url("font/context-menu-icons.eot?1915n");
58-
src: url("font/context-menu-icons.eot?1915n#iefix") format("embedded-opentype"), url("font/context-menu-icons.woff2?1915n") format("woff2"), url("font/context-menu-icons.woff?1915n") format("woff"), url("font/context-menu-icons.ttf?1915n") format("truetype");
57+
src: url("font/context-menu-icons.eot?12di9");
58+
src: url("font/context-menu-icons.eot?12di9#iefix") format("embedded-opentype"), url("font/context-menu-icons.woff2?12di9") format("woff2"), url("font/context-menu-icons.woff?12di9") format("woff"), url("font/context-menu-icons.ttf?12di9") format("truetype");
5959
}
6060

6161
.context-menu-icon-add:before {

dist/jquery.contextMenu.js

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Licensed under
1212
* MIT License http://www.opensource.org/licenses/mit-license
1313
*
14-
* Date: 2017-08-30T12:16:04.336Z
14+
* Date: 2017-10-26T16:51:13.459Z
1515
*/
1616

1717
// jscs:disable
@@ -116,6 +116,10 @@
116116
// flag denoting if a second trigger should simply move (true) or rebuild (false) an open menu
117117
// as long as the trigger happened on one of the trigger-element's child nodes
118118
reposition: true,
119+
// Flag denoting if a second trigger should close the menu, as long as
120+
// the trigger happened on one of the trigger-element's child nodes.
121+
// This overrides the reposition option.
122+
hideOnSecondTrigger: false,
119123

120124
//ability to select submenu
121125
selectableSubMenu: false,
@@ -217,12 +221,14 @@
217221
collision: 'flipfit fit'
218222
}).css('display', '');
219223
} else {
224+
var parentOffset = this.offset();
220225
// determine contextMenu position
221226
var offset = {
222-
top: -9,
223-
left: this.outerWidth() - 5
227+
top: parentOffset.top,
228+
left: parentOffset.left + this.outerWidth()
224229
};
225230
$menu.css(offset);
231+
op.activated($menu);
226232
}
227233
},
228234
// offset to add to zIndex
@@ -236,7 +242,8 @@
236242
// events
237243
events: {
238244
show: $.noop,
239-
hide: $.noop
245+
hide: $.noop,
246+
activated: $.noop
240247
},
241248
// default callback
242249
callback: null,
@@ -471,7 +478,12 @@
471478
$(target).trigger(e);
472479
root.$layer.show();
473480
}
474-
481+
482+
if (root.hideOnSecondTrigger && triggerAction && root.$menu !== null && typeof root.$menu !== 'undefined') {
483+
root.$menu.trigger('contextmenu:hide');
484+
return;
485+
}
486+
475487
if (root.reposition && triggerAction) {
476488
if (document.elementFromPoint) {
477489
if (root.$trigger.is(target)) {
@@ -997,6 +1009,9 @@
9971009
// position and show context menu
9981010
opt.$menu.css(css)[opt.animation.show](opt.animation.duration, function () {
9991011
$trigger.trigger('contextmenu:visible');
1012+
1013+
op.activated(opt.$menu);
1014+
opt.events.activated();
10001015
});
10011016
// make options available and set state
10021017
$trigger
@@ -1527,6 +1542,54 @@
15271542
// Wait for promise completion. .then(success, error, notify) (we don't track notify). Bind the opt
15281543
// and root to avoid scope problems
15291544
promise.then(completedPromise.bind(this, opt, root), errorPromise.bind(this, opt, root));
1545+
},
1546+
// operation that will run after contextMenu showed on screen
1547+
activated: function(menu){
1548+
var $menu = menu;
1549+
var win = $(window);
1550+
var $menuOffset = $menu.offset();
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();
1556+
if(menuHeight > winHeight){
1557+
$menu.css({
1558+
'height': winHeight -
1559+
((parseInt($menu.css('padding-top'))*2)+(parseInt($menu.css('margin-top'))*2))+'px',
1560+
'overflow-x':'hidden',
1561+
'overflow-y':'auto',
1562+
'top':winScrollTop+'px'
1563+
});
1564+
} else if($menuOffset.top < winScrollTop){
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'))*2)+(parseInt($menu.css('margin-top'))*2))+'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+
}
1592+
}
15301593
}
15311594
};
15321595

@@ -1616,6 +1679,20 @@
16161679
}
16171680

16181681
switch (operation) {
1682+
1683+
case 'update':
1684+
// Updates visibility and such
1685+
if(_hasContext){
1686+
op.update($context);
1687+
} else {
1688+
for(var menu in menus){
1689+
if(menus.hasOwnProperty(menu)){
1690+
op.update(menus[menu]);
1691+
}
1692+
}
1693+
}
1694+
break;
1695+
16191696
case 'create':
16201697
// no selector no joy
16211698
if (!o.selector) {
@@ -1905,7 +1982,7 @@
19051982
disabled: !!$node.attr('disabled'),
19061983
callback: (function () {
19071984
return function () {
1908-
$node.get(0).click()
1985+
$node.get(0).click();
19091986
};
19101987
})()
19111988
};
@@ -1924,7 +2001,7 @@
19242001
icon: $node.attr('icon'),
19252002
callback: (function () {
19262003
return function () {
1927-
$node.get(0).click()
2004+
$node.get(0).click();
19282005
};
19292006
})()
19302007
};

dist/jquery.contextMenu.min.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)