Skip to content

Commit b8ad711

Browse files
committed
Menu: Add a flag and remove previous attempt to prevent select events from being fired by click events bubbling up through nested menus
1 parent e054e28 commit b8ad711

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

ui/jquery.ui.menu.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
(function( $, undefined ) {
1717

18-
var currentEventTarget = null;
18+
var mouseHandled = false;
1919

2020
$.widget( "ui.menu", {
2121
version: "@VERSION",
@@ -73,24 +73,16 @@ $.widget( "ui.menu", {
7373
},
7474
"click .ui-menu-item:has(a)": function( event ) {
7575
var target = $( event.target );
76-
if ( target[0] !== currentEventTarget ) {
77-
currentEventTarget = target[0];
78-
// TODO: What are we trying to accomplish with this check?
79-
// Clicking a menu item twice results in a select event with
80-
// an empty ui.item.
81-
target.one( "click" + this.eventNamespace, function( event ) {
82-
currentEventTarget = null;
83-
});
84-
// Don't select disabled menu items
85-
if ( !target.closest( ".ui-menu-item" ).is( ".ui-state-disabled" ) ) {
86-
this.select( event );
87-
// Redirect focus to the menu with a delay for firefox
88-
this._delay(function() {
89-
if ( !this.element.is(":focus") ) {
90-
this.element.focus();
91-
}
92-
}, 20 );
93-
}
76+
if ( !mouseHandled && target.closest( ".ui-menu-item" ).not( ".ui-state-disabled" ).length ) {
77+
mouseHandled = true;
78+
79+
this.select( event );
80+
// Redirect focus to the menu with a delay for firefox
81+
this._delay(function() {
82+
if ( !this.element.is(":focus") ) {
83+
this.element.focus();
84+
}
85+
}, 20 );
9486
}
9587
},
9688
"mouseenter .ui-menu-item": function( event ) {
@@ -127,6 +119,9 @@ $.widget( "ui.menu", {
127119
if ( !$( event.target ).closest( ".ui-menu" ).length ) {
128120
this.collapseAll( event );
129121
}
122+
123+
// Reset the mouseHandled flag
124+
mouseHandled = false;
130125
}
131126
});
132127
},
@@ -166,9 +161,6 @@ $.widget( "ui.menu", {
166161

167162
// Destroy menu dividers
168163
this.element.find( ".ui-menu-divider" ).removeClass( "ui-menu-divider ui-widget-content" );
169-
170-
// Unbind currentEventTarget click event handler
171-
this._off( $( currentEventTarget ), "click" );
172164
},
173165

174166
_keydown: function( event ) {

0 commit comments

Comments
 (0)