Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding reposition config flag - Issue #104

  • Loading branch information...
commit 6b0e2bda779bbf6287c1790c937801e0449ee888 1 parent c5ba852
@rodneyrehm rodneyrehm authored
Showing with 23 additions and 10 deletions.
  1. +9 −1 docs.html
  2. +14 −9 src/jquery.contextMenu.js
View
10 docs.html
@@ -95,7 +95,15 @@ <h3 id="options">options (at registration)</h3>
<p>Specifies the event to show the contextMenu</p>
<p>Possible values: "right", "left", "hover", "none"</p>
</dd>
-
+
+ <dt id="options-reposition"><em>(boolean)</em> reposition</dt>
+ <dd>
+ <p>
+ Specifies if a menu should be repositioned (true) or rebuilt (false) if a second trigger event (like a right click) is performed
+ on the same trigger element (or its children) while the menu is still visible.
+ </p>
+ </dd>
+
<dt id="options-delay"><em>(int)</em> delay</dt>
<dd>
<p>default: <em>200</em></p>
View
23 src/jquery.contextMenu.js
@@ -85,6 +85,9 @@ var // currently active contextMenu trigger
autoHide: false,
// ms to wait before showing a hover-triggered context menu
delay: 200,
+ // flag denoting if a second trigger should simply move (true) or rebuild (false) an open menu
+ // as long as the trigger happened on one of the trigger-element's child nodes
+ reposition: true,
// determine position to show menu at
determinePosition: function($menu) {
// position to the lower middle of the trigger element
@@ -352,13 +355,16 @@ var // currently active contextMenu trigger
setTimeout(function() {
var $window, hideshow, possibleTarget;
- // test if we need to reposition the menu
- if ((root.trigger == 'left' && button == 0) || (root.trigger == 'right' && button == 2)) {
+
+ // find the element that would've been clicked, wasn't the layer in the way
+ if (document.elementFromPoint) {
+ root.$layer.hide();
+ target = document.elementFromPoint(x - $win.scrollLeft(), y - $win.scrollTop());
+ root.$layer.show();
+ }
+
+ if (root.reposition && ((root.trigger == 'left' && button == 0) || (root.trigger == 'right' && button == 2))) {
if (document.elementFromPoint) {
- root.$layer.hide();
- target = document.elementFromPoint(x - $win.scrollLeft(), y - $win.scrollTop());
- root.$layer.show();
-
if (root.$trigger.is(target) || root.$trigger.has(target).length) {
root.position.call(root.$trigger, root, x, y);
return;
@@ -385,9 +391,8 @@ var // currently active contextMenu trigger
}
}
}
-
- if (target && target.length) {
- target.contextMenu({x: x, y: y});
+ if (target) {
+ $(target).contextMenu({x: x, y: y});
} else {
// TODO: it would be nice if we could prevent animations here
root.$menu.trigger('contextmenu:hide');
Please sign in to comment.
Something went wrong with that request. Please try again.