]> source.dussan.org Git - jquery-ui.git/commitdiff
Autocomplete: Added check to prevent accidental focus of menu-item on page load in...
authorkborchers <kris.borchers@gmail.com>
Fri, 18 May 2012 19:55:10 +0000 (15:55 -0400)
committerScott González <scott.gonzalez@gmail.com>
Fri, 18 May 2012 19:55:10 +0000 (15:55 -0400)
ui/jquery.ui.autocomplete.js

index 8ab48ba032da69f90aac3a66fbc4174f0ba7dd6c..685bbca11441fbf9a1354ee8457cf7992428e67d 100644 (file)
@@ -57,6 +57,7 @@ $.widget( "ui.autocomplete", {
 
                this.isMultiLine = this.element.is( "textarea,[contenteditable]" );
                this.valueMethod = this.element[ this.element.is( "input,textarea" ) ? "val" : "text" ];
+               this.isNewMenu = true;
 
                this.element
                        .addClass( "ui-autocomplete-input" )
@@ -220,6 +221,20 @@ $.widget( "ui.autocomplete", {
                                }
                        },
                        menufocus: function( event, ui ) {
+                               // #7024 - Prevent accidental activation of menu items in Firefox
+                               if ( this.isNewMenu ) {
+                                       this.isNewMenu = false;
+                                       if ( event.originalEvent && /^mouse/.test(event.originalEvent.type) ) {
+                                               this.menu.blur();
+
+                                               this.document.one( "mousemove", function() {
+                                                       $( event.target ).trigger( event.originalEvent );
+                                               });
+
+                                               return;
+                                       }
+                               }
+
                                // back compat for _renderItem using item.autocomplete, via #7810
                                // TODO remove the fallback, see #8156
                                var item = ui.item.data( "ui-autocomplete-item" ) || ui.item.data( "item.autocomplete" );
@@ -422,6 +437,7 @@ $.widget( "ui.autocomplete", {
                if ( this.menu.element.is(":visible") ) {
                        this.menu.element.hide();
                        this.menu.blur();
+                       this.isNewMenu = true;
                        this._trigger( "close", event );
                }
        },