Skip to content

Commit

Permalink
fixing issues with fixed positioned triggers - Issue #95
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Dec 29, 2012
1 parent 0b6c31a commit 18c374b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ $.contextMenu is published under the [MIT license](http://www.opensource.org/lic
* adding [demo for TouchSwipe](http://medialize.github.com/jQuery-contextMenu/demo/trigger-swipe.html) activation
* fixing iOS "click" compatibility problem - ([Issue 83](https://github.com/medialize/jQuery-contextMenu/issues/83))
* fixing separators to not be clickable - ([Issue 85](https://github.com/medialize/jQuery-contextMenu/issues/85))

* fixing issues with fixed positioned triggers ([Issue 95](https://github.com/medialize/jQuery-contextMenu/issues/95))

### 1.5.25 ###

Expand Down
19 changes: 6 additions & 13 deletions src/jquery.contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,6 @@ var // currently active contextMenu trigger
offset = opt.$menu.position();
} else {
// x and y are given (by mouse event)
var triggerIsFixed = opt.$trigger.parents().andSelf()
.filter(function() {
return $(this).css('position') == "fixed";
}).length;

if (triggerIsFixed) {
y -= $win.scrollTop();
x -= $win.scrollLeft();
}
offset = {top: y, left: x};
}

Expand Down Expand Up @@ -826,12 +817,14 @@ var // currently active contextMenu trigger
$(document).off('keydown.contextMenu').on('keydown.contextMenu', handle.key);
// register autoHide handler
if (opt.autoHide) {
// trigger element coordinates
var pos = $trigger.position();
pos.right = pos.left + $trigger.outerWidth();
pos.bottom = pos.top + $trigger.outerHeight();
// mouse position handler
$(document).on('mousemove.contextMenuAutoHide', function(e) {
// need to capture the offset on mousemove,
// since the page might've been scrolled since activation
var pos = $trigger.offset();
pos.right = pos.left + $trigger.outerWidth();
pos.bottom = pos.top + $trigger.outerHeight();

if (opt.$layer && !opt.hovering && (!(e.pageX >= pos.left && e.pageX <= pos.right) || !(e.pageY >= pos.top && e.pageY <= pos.bottom))) {
// if mouse in menu...
opt.$menu.trigger('contextmenu:hide');
Expand Down

0 comments on commit 18c374b

Please sign in to comment.