From b8ad711deedab11da1f181b486ee67f259a3ef7c Mon Sep 17 00:00:00 2001 From: kborchers Date: Thu, 12 Jul 2012 22:45:56 -0500 Subject: [PATCH] Menu: Add a flag and remove previous attempt to prevent select events from being fired by click events bubbling up through nested menus --- ui/jquery.ui.menu.js | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index 81fef2e7c..e8b8ed1fc 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -15,7 +15,7 @@ */ (function( $, undefined ) { -var currentEventTarget = null; +var mouseHandled = false; $.widget( "ui.menu", { version: "@VERSION", @@ -73,24 +73,16 @@ $.widget( "ui.menu", { }, "click .ui-menu-item:has(a)": function( event ) { var target = $( event.target ); - if ( target[0] !== currentEventTarget ) { - currentEventTarget = target[0]; - // TODO: What are we trying to accomplish with this check? - // Clicking a menu item twice results in a select event with - // an empty ui.item. - target.one( "click" + this.eventNamespace, function( event ) { - currentEventTarget = null; - }); - // Don't select disabled menu items - if ( !target.closest( ".ui-menu-item" ).is( ".ui-state-disabled" ) ) { - this.select( event ); - // Redirect focus to the menu with a delay for firefox - this._delay(function() { - if ( !this.element.is(":focus") ) { - this.element.focus(); - } - }, 20 ); - } + if ( !mouseHandled && target.closest( ".ui-menu-item" ).not( ".ui-state-disabled" ).length ) { + mouseHandled = true; + + this.select( event ); + // Redirect focus to the menu with a delay for firefox + this._delay(function() { + if ( !this.element.is(":focus") ) { + this.element.focus(); + } + }, 20 ); } }, "mouseenter .ui-menu-item": function( event ) { @@ -127,6 +119,9 @@ $.widget( "ui.menu", { if ( !$( event.target ).closest( ".ui-menu" ).length ) { this.collapseAll( event ); } + + // Reset the mouseHandled flag + mouseHandled = false; } }); }, @@ -166,9 +161,6 @@ $.widget( "ui.menu", { // Destroy menu dividers this.element.find( ".ui-menu-divider" ).removeClass( "ui-menu-divider ui-widget-content" ); - - // Unbind currentEventTarget click event handler - this._off( $( currentEventTarget ), "click" ); }, _keydown: function( event ) { -- 2.39.5