vendor/assets/javascripts/jquery.ui.autocomplete.js in jquery-ui-rails-0.2.2 vs vendor/assets/javascripts/jquery.ui.autocomplete.js in jquery-ui-rails-0.3.0
- old
+ new
@@ -1,13 +1,13 @@
//= require jquery.ui.core
//= require jquery.ui.widget
//= require jquery.ui.position
/*!
- * jQuery UI Autocomplete 1.8.18
+ * jQuery UI Autocomplete 1.8.19pre
*
- * 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
*
* http://docs.jquery.com/UI/Autocomplete
*
@@ -39,10 +39,11 @@
_create: function() {
var self = this,
doc = this.element[ 0 ].ownerDocument,
suppressKeyPress;
+ this.isMultiLine = this.element.is( "textarea" );
this.element
.addClass( "ui-autocomplete-input" )
.attr( "autocomplete", "off" )
// TODO verify these actually work as intended
@@ -64,18 +65,14 @@
break;
case keyCode.PAGE_DOWN:
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:
// when menu is open and has focus
if ( self.menu.active ) {
@@ -133,13 +130,10 @@
self.close( event );
self._change( event );
}, 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] )
// prevent the close-on-blur in case of a "slow" click on the menu (long mousedown)
.mousedown(function( event ) {
@@ -270,22 +264,15 @@
}
self.xhr = $.ajax({
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( [] );
}
});
};
} else {
this.source = this.options.source;
@@ -312,25 +299,37 @@
_search: function( value ) {
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 );
this._trigger( "open" );
} else {
this.close();
}
- this.pending--;
- if ( !this.pending ) {
- this.element.removeClass( "ui-autocomplete-loading" );
- }
},
close: function( event ) {
clearTimeout( this.closing );
if ( this.menu.element.is(":visible") ) {
@@ -424,10 +423,18 @@
this.menu[ direction ]( event );
},
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();
+ }
}
});
$.extend( $.ui.autocomplete, {
escapeRegex: function( value ) {
@@ -596,10 +603,10 @@
this.activate(event, this.element.children(".ui-menu-item:last"));
return;
}
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
return close < 10 && close > -10;
});