Merge "(bug 19195) Make user IDs more readily available with the API"
[lhc/web/wiklou.git] / resources / jquery.ui / jquery.ui.autocomplete.js
index 8889ca9..f95b78f 100644 (file)
@@ -1,7 +1,7 @@
-/*
- * jQuery UI Autocomplete 1.8.18
+/*!
+ * jQuery UI Autocomplete 1.8.20
  *
- * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
+ * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
  * Dual licensed under the MIT or GPL Version 2 licenses.
  * http://jquery.org/license
  *
@@ -37,6 +37,7 @@ $.widget( "ui.autocomplete", {
                var self = this,
                        doc = this.element[ 0 ].ownerDocument,
                        suppressKeyPress;
+               this.isMultiLine = this.element.is( "textarea" );
 
                this.element
                        .addClass( "ui-autocomplete-input" )
@@ -62,14 +63,10 @@ $.widget( "ui.autocomplete", {
                                        self._move( "nextPage", event );
                                        break;
                                case keyCode.UP:
-                                       self._move( "previous", event );
-                                       // prevent moving cursor to beginning of text field in some browsers
-                                       event.preventDefault();
+                                       self._keyEvent( "previous", event );
                                        break;
                                case keyCode.DOWN:
-                                       self._move( "next", event );
-                                       // prevent moving cursor to end of text field in some browsers
-                                       event.preventDefault();
+                                       self._keyEvent( "next", event );
                                        break;
                                case keyCode.ENTER:
                                case keyCode.NUMPAD_ENTER:
@@ -131,9 +128,6 @@ $.widget( "ui.autocomplete", {
                                }, 150 );
                        });
                this._initSource();
-               this.response = function() {
-                       return self._response.apply( self, arguments );
-               };
                this.menu = $( "<ul></ul>" )
                        .addClass( "ui-autocomplete" )
                        .appendTo( $( this.options.appendTo || "body", doc )[0] )
@@ -268,18 +262,11 @@ $.widget( "ui.autocomplete", {
                                        url: url,
                                        data: request,
                                        dataType: "json",
-                                       context: {
-                                               autocompleteRequest: ++requestIndex
-                                       },
                                        success: function( data, status ) {
-                                               if ( this.autocompleteRequest === requestIndex ) {
-                                                       response( data );
-                                               }
+                                               response( data );
                                        },
                                        error: function() {
-                                               if ( this.autocompleteRequest === requestIndex ) {
-                                                       response( [] );
-                                               }
+                                               response( [] );
                                        }
                                });
                        };
@@ -310,10 +297,26 @@ $.widget( "ui.autocomplete", {
                this.pending++;
                this.element.addClass( "ui-autocomplete-loading" );
 
-               this.source( { term: value }, this.response );
+               this.source( { term: value }, this._response() );
        },
 
-       _response: function( content ) {
+       _response: function() {
+               var that = this,
+                       index = ++requestIndex;
+
+               return function( content ) {
+                       if ( index === requestIndex ) {
+                               that.__response( content );
+                       }
+
+                       that.pending--;
+                       if ( !that.pending ) {
+                               that.element.removeClass( "ui-autocomplete-loading" );
+                       }
+               };
+       },
+
+       __response: function( content ) {
                if ( !this.options.disabled && content && content.length ) {
                        content = this._normalize( content );
                        this._suggest( content );
@@ -321,10 +324,6 @@ $.widget( "ui.autocomplete", {
                } else {
                        this.close();
                }
-               this.pending--;
-               if ( !this.pending ) {
-                       this.element.removeClass( "ui-autocomplete-loading" );
-               }
        },
 
        close: function( event ) {
@@ -422,6 +421,14 @@ $.widget( "ui.autocomplete", {
 
        widget: function() {
                return this.menu.element;
+       },
+       _keyEvent: function( keyEvent, event ) {
+               if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
+                       this._move( keyEvent, event );
+
+                       // prevents moving cursor to beginning/end of the text field in some browsers
+                       event.preventDefault();
+               }
        }
 });
 
@@ -594,7 +601,7 @@ $.widget("ui.menu", {
                        }
 
                        var base = this.active.offset().top,
-                               height = this.element.height();
+                               height = this.element.height(),
                                result = this.element.children(".ui-menu-item").filter(function() {
                                        var close = $(this).offset().top - base + height - $(this).height();
                                        // TODO improve approximation