diff options
author | Scott González <scott.gonzalez@gmail.com> | 2012-02-11 15:43:38 -0500 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-02-16 20:24:11 -0500 |
commit | f5b52a89a735082d06d6f6ea950efbccff0a227f (patch) | |
tree | 7fec8fed6504fe4888e0bd4dd810a58174be2efe /ui/jquery.ui.autocomplete.js | |
parent | 3d9f6b5bc74d09a08f6a116b6b31d93d72971f6d (diff) | |
download | jquery-ui-f5b52a89a735082d06d6f6ea950efbccff0a227f.tar.gz jquery-ui-f5b52a89a735082d06d6f6ea950efbccff0a227f.zip |
Autocomplete: Removed the timeout for the change event. Fixes #7550 - Autocomplete change event not triggered in time.
Thanks spekary for finding a workaround for IE.
Diffstat (limited to 'ui/jquery.ui.autocomplete.js')
-rw-r--r-- | ui/jquery.ui.autocomplete.js | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 5646eda7a..e261b9147 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -176,13 +176,14 @@ $.widget( "ui.autocomplete", { return; } + if ( self.cancelBlur ) { + delete self.cancelBlur; + return; + } + clearTimeout( self.searching ); - self.cancelSearch = true; - // clicks on the menu (or a button to trigger a search) will cause a blur event - self.closing = setTimeout(function() { - self.close( event ); - self._change( event ); - }, 150 ); + self.close( event ); + self._change( event ); }); this._initSource(); this.response = function() { @@ -193,6 +194,16 @@ $.widget( "ui.autocomplete", { .appendTo( this.document.find( this.options.appendTo || "body" )[0] ) // prevent the close-on-blur in case of a "slow" click on the menu (long mousedown) .mousedown(function( event ) { + // prevent moving focus out of the text field + event.preventDefault(); + + // IE doesn't prevent moving focus even with event.preventDefault() + // so we set a flag to know when we should ignore the blur event + self.cancelBlur = true; + setTimeout(function() { + delete self.cancelBlur; + }, 1 ); + // 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 @@ -209,11 +220,6 @@ $.widget( "ui.autocomplete", { }); }, 1 ); } - - // use another timeout to make sure the blur-event-handler on the input was already triggered - setTimeout(function() { - clearTimeout( self.closing ); - }, 13); }) .menu({ // custom key handling for now @@ -358,7 +364,6 @@ $.widget( "ui.autocomplete", { return this.close( event ); } - clearTimeout( this.closing ); if ( this._trigger( "search", event ) === false ) { return; } |