|
15 | 15 | */
|
16 | 16 | (function( $, undefined ) {
|
17 | 17 |
|
18 |
| -var currentEventTarget = null; |
| 18 | +var mouseHandled = false; |
19 | 19 |
|
20 | 20 | $.widget( "ui.menu", {
|
21 | 21 | version: "@VERSION",
|
@@ -73,24 +73,16 @@ $.widget( "ui.menu", {
|
73 | 73 | },
|
74 | 74 | "click .ui-menu-item:has(a)": function( event ) {
|
75 | 75 | 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 ); |
94 | 86 | }
|
95 | 87 | },
|
96 | 88 | "mouseenter .ui-menu-item": function( event ) {
|
@@ -127,6 +119,9 @@ $.widget( "ui.menu", {
|
127 | 119 | if ( !$( event.target ).closest( ".ui-menu" ).length ) {
|
128 | 120 | this.collapseAll( event );
|
129 | 121 | }
|
| 122 | + |
| 123 | + // Reset the mouseHandled flag |
| 124 | + mouseHandled = false; |
130 | 125 | }
|
131 | 126 | });
|
132 | 127 | },
|
@@ -166,9 +161,6 @@ $.widget( "ui.menu", {
|
166 | 161 |
|
167 | 162 | // Destroy menu dividers
|
168 | 163 | 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" ); |
172 | 164 | },
|
173 | 165 |
|
174 | 166 | _keydown: function( event ) {
|
|
0 commit comments