Skip to content

Commit fc3cc41

Browse files
fix submenu position issue
"op.activated" changed, so submenu position will be handle in this function.
1 parent 42d9a43 commit fc3cc41

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

src/jquery.contextMenu.js

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -472,7 +478,12 @@
472478
$(target).trigger(e);
473479
root.$layer.show();
474480
}
475-
481+
482+
if (root.hideOnSecondTrigger && triggerAction && root.$menu !== null && typeof root.$menu !== 'undefined') {
483+
root.$menu.trigger('contextmenu:hide');
484+
return;
485+
}
486+
476487
if (root.reposition && triggerAction) {
477488
if (document.elementFromPoint) {
478489
if (root.$trigger.is(target)) {
@@ -999,7 +1010,7 @@
9991010
opt.$menu.css(css)[opt.animation.show](opt.animation.duration, function () {
10001011
$trigger.trigger('contextmenu:visible');
10011012

1002-
op.activated(opt);
1013+
op.activated(opt.$menu);
10031014
opt.events.activated();
10041015
});
10051016
// make options available and set state
@@ -1533,8 +1544,8 @@
15331544
promise.then(completedPromise.bind(this, opt, root), errorPromise.bind(this, opt, root));
15341545
},
15351546
// operation that will run after contextMenu showed on screen
1536-
activated: function(opt){
1537-
var $menu = opt.$menu;
1547+
activated: function(menu){
1548+
var $menu = menu;
15381549
var $menuOffset = $menu.offset();
15391550
var winHeight = $(window).height();
15401551
var winScrollTop = $(window).scrollTop();
@@ -1546,14 +1557,15 @@
15461557
'overflow-y': 'auto',
15471558
'top': winScrollTop + 'px'
15481559
});
1549-
} else if(
1550-
($menuOffset.top < winScrollTop) ||
1551-
($menuOffset.top + menuHeight > winScrollTop + winHeight)
1552-
){
1560+
} else if($menuOffset.top < winScrollTop){
15531561
$menu.css({
15541562
'top': '0px'
15551563
});
1556-
}
1564+
} else if($menuOffset.top + menuHeight > winScrollTop + winHeight){
1565+
$menu.css({
1566+
'top':$menuOffset.top- Math.abs((winScrollTop+winHeight) - ($menuOffset.top+menuHeight))
1567+
});
1568+
}
15571569
}
15581570
};
15591571

@@ -1643,6 +1655,20 @@
16431655
}
16441656

16451657
switch (operation) {
1658+
1659+
case 'update':
1660+
// Updates visibility and such
1661+
if(_hasContext){
1662+
op.update($context);
1663+
} else {
1664+
for(var menu in menus){
1665+
if(menus.hasOwnProperty(menu)){
1666+
op.update(menus[menu]);
1667+
}
1668+
}
1669+
}
1670+
break;
1671+
16461672
case 'create':
16471673
// no selector no joy
16481674
if (!o.selector) {
@@ -1932,7 +1958,7 @@
19321958
disabled: !!$node.attr('disabled'),
19331959
callback: (function () {
19341960
return function () {
1935-
$node.get(0).click()
1961+
$node.get(0).click();
19361962
};
19371963
})()
19381964
};
@@ -1951,7 +1977,7 @@
19511977
icon: $node.attr('icon'),
19521978
callback: (function () {
19531979
return function () {
1954-
$node.get(0).click()
1980+
$node.get(0).click();
19551981
};
19561982
})()
19571983
};

0 commit comments

Comments
 (0)