vendor/assets/javascripts/jquery.ui.autocomplete.js in jquery-ui-rails-3.0.1 vs vendor/assets/javascripts/jquery.ui.autocomplete.js in jquery-ui-rails-4.0.0
- old
+ new
@@ -2,14 +2,14 @@
//= require jquery.ui.widget
//= require jquery.ui.menu
//= require jquery.ui.position
/*!
- * jQuery UI Autocomplete 1.9.2
+ * jQuery UI Autocomplete 1.10.0
* http://jqueryui.com
*
- * Copyright 2012 jQuery Foundation and other contributors
+ * Copyright 2013 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*
* http://api.jqueryui.com/autocomplete/
*
@@ -23,14 +23,14 @@
// used to prevent race conditions with remote data sources
var requestIndex = 0;
$.widget( "ui.autocomplete", {
- version: "1.9.2",
+ version: "1.10.0",
defaultElement: "<input>",
options: {
- appendTo: "body",
+ appendTo: null,
autoFocus: false,
delay: 300,
minLength: 1,
position: {
my: "left top",
@@ -69,10 +69,11 @@
.addClass( "ui-autocomplete-input" )
.attr( "autocomplete", "off" );
this._on( this.element, {
keydown: function( event ) {
+ /*jshint maxcomplexity:15*/
if ( this.element.prop( "readOnly" ) ) {
suppressKeyPress = true;
suppressInput = true;
suppressKeyPressRepeat = true;
return;
@@ -184,20 +185,20 @@
});
this._initSource();
this.menu = $( "<ul>" )
.addClass( "ui-autocomplete" )
- .appendTo( this.document.find( this.options.appendTo || "body" )[ 0 ] )
+ .appendTo( this._appendTo() )
.menu({
// custom key handling for now
input: $(),
// disable ARIA support, the live region takes care of that
role: null
})
.zIndex( this.element.zIndex() + 1 )
.hide()
- .data( "menu" );
+ .data( "ui-menu" );
this._on( this.menu.element, {
mousedown: function( event ) {
// prevent moving focus out of the text field
event.preventDefault();
@@ -240,13 +241,11 @@
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" );
+ var item = ui.item.data( "ui-autocomplete-item" );
if ( false !== this._trigger( "focus", event, { item: item } ) ) {
// use value to match what will end up in the input, if it was a key event
if ( event.originalEvent && /^key/.test( event.originalEvent.type ) ) {
this._value( item.value );
}
@@ -258,13 +257,11 @@
// still notice the change and announce it.
this.liveRegion.text( item.value );
}
},
menuselect: function( event, ui ) {
- // 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" ),
+ var item = ui.item.data( "ui-autocomplete-item" ),
previous = this.previous;
// only trigger when focus was lost (click on menu)
if ( this.element[0] !== this.document[0].activeElement ) {
this.element.focus();
@@ -295,14 +292,10 @@
"aria-live": "polite"
})
.addClass( "ui-helper-hidden-accessible" )
.insertAfter( this.element );
- if ( $.fn.bgiframe ) {
- this.menu.element.bgiframe();
- }
-
// turning off autocomplete prevents the browser from remembering the
// value when navigating through history, so we re-enable autocomplete
// if the page is unloaded before the widget is destroyed. #7790
this._on( this.window, {
beforeunload: function() {
@@ -324,17 +317,37 @@
this._super( key, value );
if ( key === "source" ) {
this._initSource();
}
if ( key === "appendTo" ) {
- this.menu.element.appendTo( this.document.find( value || "body" )[0] );
+ this.menu.element.appendTo( this._appendTo() );
}
if ( key === "disabled" && value && this.xhr ) {
this.xhr.abort();
}
},
+ _appendTo: function() {
+ var element = this.options.appendTo;
+
+ if ( element ) {
+ element = element.jquery || element.nodeType ?
+ $( element ) :
+ this.document.find( element ).eq( 0 );
+ }
+
+ if ( !element ) {
+ element = this.element.closest( ".ui-front" );
+ }
+
+ if ( !element.length ) {
+ element = this.document[0].body;
+ }
+
+ return element;
+ },
+
_isMultiLine: function() {
// Textareas are always multi-line
if ( this.element.is( "textarea" ) ) {
return true;
}
@@ -600,8 +613,7 @@
message = this.options.messages.noResults;
}
this.liveRegion.text( message );
}
});
-
}( jQuery ));