]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Handle clicking on a menu item without hovering it first. Fixes #7085 - Menu...
authorScott González <scott.gonzalez@gmail.com>
Tue, 15 Mar 2011 18:02:18 +0000 (14:02 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 15 Mar 2011 18:02:18 +0000 (14:02 -0400)
ui/jquery.ui.menu.js

index cd07b64180db70c9bd3c0af9d151b64fcdd67007..2addba37e3035ca0833d4da7cc9e412f7b9b8ad4 100644 (file)
@@ -34,14 +34,19 @@ $.widget("ui.menu", {
                                role: "listbox"
                        })
                        .bind( "click.menu", function( event ) {
+                               var item = $( event.target ).closest( ".ui-menu-item:has(a)" );
                                if ( self.options.disabled ) {
                                        return false;
                                }
-                               if ( !$( event.target ).closest( ".ui-menu-item a" ).length ) {
+                               if ( !item.length ) {
                                        return;
                                }
                                // temporary
                                event.preventDefault();
+                               // it's possible to click an item without hovering it (#7085)
+                               if ( !self.active || ( self.active[ 0 ] !== item[ 0 ] ) ) {
+                                       self.focus( event, item );
+                               }
                                self.select( event );
                        })
                        .bind( "mouseover.menu", function( event ) {
@@ -102,7 +107,7 @@ $.widget("ui.menu", {
                                event.preventDefault();
                                break;
                        case $.ui.keyCode.ENTER:
-                               self.select();
+                               self.select( event );
                                event.preventDefault();
                                event.stopImmediatePropagation();
                                break;