Skip to content

Commit 12571c1

Browse files
committed
Close mar10#1
1 parent ff5fa4a commit 12571c1

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,19 @@ structure (see [jQueryUI menu] for details):
7979
Type: <code>String</code><br>
8080
A selector to filter the elements that trigger the context menu.
8181
</dd>
82+
<dt>ignoreParentSelect</dt>
83+
<dd>
84+
Type: <code>Boolean</code>, default: <code>true</code><br>
85+
If <code>true</code>, a click on a menu item that contains a sub-menu, will <em>not</em>
86+
trigger the <code>select</code> event.
87+
</dd>
8288
<dt>menu</dt>
8389
<dd>
8490
Type: <code>String | jQuery | function</code><br>
8591
jQuery object or selector (or function returning such) of HTML markup that defines the context menu
8692
structure (see [jQueryUI menu] for details).
8793
</dd>
94+
8895
</dl>
8996

9097

jquery.contextmenu.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
version: "0.0.1",
1919
options: {
2020
delegate: "[data-menu]", // selector
21+
ignoreParentSelect: true, // Don't trigger 'select' for sub-menu parents
2122
menu: null, // selector or jQuery or a function returning such
2223
taphold: 2000, // open menu after 2000 ms long touch
2324
// Events:
@@ -100,9 +101,12 @@
100101
select: function(event, ui){
101102
// Also pass the target that the menu was triggered on:
102103
event.relatedTarget = openEvent.target;
103-
if( self._trigger.call(self, "select", event, ui) !== false ){
104-
self._closeMenu.call(self);
105-
}
104+
var isParent = (ui.item.has(">a[aria-haspopup='true']").length > 0);
105+
if( !isParent || !self.options.ignoreParentSelect){
106+
if( self._trigger.call(self, "select", event, ui) !== false ){
107+
self._closeMenu.call(self);
108+
}
109+
}
106110
}
107111
});
108112
// Register global event handlers that close the dropdown-menu
@@ -117,7 +121,7 @@
117121
}
118122
});
119123
$menu
120-
.show() // required to fix positioning error (issue #)
124+
.show() // required to fix positioning error (issue #3)
121125
.css({
122126
position: "absolute",
123127
left: 0,

sample-widget.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
$(function(){
2828
$("#container").contextmenu({
2929
delegate: ".hasmenu",
30+
// ignoreParentSelect: false,
3031
menu: "#options",
3132
focus: function(event, ui) {
3233
var menuId = ui.item.find(">a").attr("href");
@@ -36,7 +37,7 @@
3637
$("#info").text("");
3738
},
3839
beforeOpen: function(event) {
39-
// alert("beforeopen on " + $(event.relatedTarget).text());
40+
alert("beforeopen on " + $(event.relatedTarget).text());
4041
},
4142
open: function(event, ui) {
4243
// alert("open on " + $(event.relatedTarget).text());

0 commit comments

Comments
 (0)