mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Quick/Bulk Edit: Fix undefined error when initializing UI Autocomplete 1.12.1 on non-existing element and then attempting to use the autocomplete instance.
Example: `jQuery( '#nonexisting' ).autocomplete().autocomplete( 'instance' ).something`. Props _luigi, sabernhardt, donmhico, azaozz. Fixes #51872. git-svn-id: https://develop.svn.wordpress.org/trunk@49703 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f4525a2e93
commit
b2d59e7c8d
@ -329,6 +329,11 @@ window.wp = window.wp || {};
|
||||
textarea = $('textarea.tax_input_' + taxname, editRow),
|
||||
comma = wp.i18n._x( ',', 'tag delimiter' ).trim();
|
||||
|
||||
// Ensure the textarea exists.
|
||||
if ( ! textarea.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
terms.find( 'img' ).replaceWith( function() { return this.alt; } );
|
||||
terms = terms.text();
|
||||
|
||||
|
||||
@ -38,6 +38,11 @@
|
||||
var last;
|
||||
var $element = $( this );
|
||||
|
||||
// Do not initialize if the element doesn't exist.
|
||||
if ( ! $element.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
var taxonomy = options.taxonomy || $element.attr( 'data-wp-taxonomy' ) || 'post_tag';
|
||||
@ -146,13 +151,18 @@
|
||||
|
||||
$element.on( 'keydown', function() {
|
||||
$element.removeAttr( 'aria-activedescendant' );
|
||||
} )
|
||||
.autocomplete( options )
|
||||
.autocomplete( 'instance' )._renderItem = function( ul, item ) {
|
||||
return $( '<li role="option" id="wp-tags-autocomplete-' + item.id + '">' )
|
||||
.text( item.name )
|
||||
.appendTo( ul );
|
||||
};
|
||||
} );
|
||||
|
||||
$element.autocomplete( options );
|
||||
|
||||
// Ensure the autocomplete instance exists.
|
||||
if ( $element.autocomplete( 'instance' ) ) {
|
||||
$element.autocomplete( 'instance' )._renderItem = function( ul, item ) {
|
||||
return $( '<li role="option" id="wp-tags-autocomplete-' + item.id + '">' )
|
||||
.text( item.name )
|
||||
.appendTo( ul );
|
||||
};
|
||||
}
|
||||
|
||||
$element.attr( {
|
||||
'role': 'combobox',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user