Skip to content

Commit 87fbf84

Browse files
Update jquery.contextMenu.js
Adding "activated" method in options so user can bind his function to run after contextMenu showed on page. Adding handler to fix contextMenu position on over boundary screen. (making contextMenu scrollable)
1 parent f240871 commit 87fbf84

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/jquery.contextMenu.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@
236236
// events
237237
events: {
238238
show: $.noop,
239-
hide: $.noop
239+
hide: $.noop,
240+
activated: $.noop
240241
},
241242
// default callback
242243
callback: null,
@@ -997,6 +998,9 @@
997998
// position and show context menu
998999
opt.$menu.css(css)[opt.animation.show](opt.animation.duration, function () {
9991000
$trigger.trigger('contextmenu:visible');
1001+
1002+
opt.activated();
1003+
opt.events.activated();
10001004
});
10011005
// make options available and set state
10021006
$trigger
@@ -1527,6 +1531,29 @@
15271531
// Wait for promise completion. .then(success, error, notify) (we don't track notify). Bind the opt
15281532
// and root to avoid scope problems
15291533
promise.then(completedPromise.bind(this, opt, root), errorPromise.bind(this, opt, root));
1534+
},
1535+
// operation that will run after contextMenu showed on screen
1536+
activated: function(opt){
1537+
var $menu = opt.$menu;
1538+
var $menuOffset = $menu.offset();
1539+
var winHeight = $(window).height();
1540+
var winScrollTop = $(window).scrollTop();
1541+
var menuHeight = $menu.height();
1542+
if(menuHeight > winHeight){
1543+
$menu.css({
1544+
'height' : winHeight + 'px',
1545+
'overflow-x': 'hidden',
1546+
'overflow-y': 'auto',
1547+
'top': winScrollTop + 'px'
1548+
});
1549+
} else if(
1550+
($menuOffset.top < winScrollTop) ||
1551+
($menuOffset.top + menuHeight > winScrollTop + winHeight)
1552+
){
1553+
$menu.css({
1554+
'top': '0px'
1555+
});
1556+
}
15301557
}
15311558
};
15321559

0 commit comments

Comments
 (0)