diff options
author | Scott González <scott.gonzalez@gmail.com> | 2010-08-05 08:51:54 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2010-08-05 08:51:54 -0400 |
commit | de266a1275efa405eb7147469fa25274a6b7254b (patch) | |
tree | d2f0da9cbecaf229d137a2cf2a8d2a2ee636205d | |
parent | ed07f0a05656d2c66db453c8f6d664f69ec1a04d (diff) | |
download | jquery-ui-de266a1275efa405eb7147469fa25274a6b7254b.tar.gz jquery-ui-de266a1275efa405eb7147469fa25274a6b7254b.zip |
Autocomplete: Handle clicks outside the autocomplete after scrolling the results (which causes the body to gain focus). Fixes #5903 - Autocomplete doesn't close after scrolling.
-rw-r--r-- | ui/jquery.ui.autocomplete.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 98130ab50..8380df8ad 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -119,7 +119,24 @@ $.widget( "ui.autocomplete", { .addClass( "ui-autocomplete" ) .appendTo( $( this.options.appendTo || "body", doc )[0] ) // prevent the close-on-blur in case of a "slow" click on the menu (long mousedown) - .mousedown(function() { + .mousedown(function( event ) { + // clicking on the scrollbar causes focus to shift to the body + // but we can't detect a mouseup or a click immediately afterward + // so we have to track the next mousedown and close the menu if + // the user clicks somewhere outside of the autocomplete + var menuElement = self.menu.element[ 0 ]; + if ( event.target === menuElement ) { + setTimeout(function() { + $( document ).one( 'mousedown', function( event ) { + if ( event.target !== self.element[ 0 ] && + event.target !== menuElement && + !$.ui.contains( menuElement, event.target ) ) { + self.close(); + } + }); + }, 1 ); + } + // use another timeout to make sure the blur-event-handler on the input was already triggered setTimeout(function() { clearTimeout( self.closing ); |