/* global inlineEditL10n, ajaxurl */
+window.wp = window.wp || {};
var inlineEditTax;
-(function($) {
+( function( $, wp ) {
inlineEditTax = {
init : function() {
}
});
- $( 'a.cancel', row ).click( function() {
+ $( '.cancel', row ).click( function() {
return inlineEditTax.revert();
});
- $( 'a.save', row ).click( function() {
+ $( '.save', row ).click( function() {
return inlineEditTax.save(this);
});
$( 'input, select', row ).keydown( function( e ) {
// make ajax request
$.post( ajaxurl, params,
function(r) {
- var row, new_id, option_value;
+ var row, new_id, option_value,
+ $errorSpan = $( '#edit-' + id + ' .inline-edit-save .error' );
+
$( 'table.widefat .spinner' ).removeClass( 'is-active' );
if (r) {
// Update the value in the Parent dropdown.
$( '#parent' ).find( 'option[value=' + option_value + ']' ).text( row.find( '.row-title' ).text() );
- row.hide().fadeIn();
+ row.hide().fadeIn( 400, function() {
+ // Move focus back to the taxonomy title.
+ row.find( '.row-title' ).focus();
+ wp.a11y.speak( inlineEditL10n.saved );
+ });
+
} else {
- $('#edit-'+id+' .inline-edit-save .error').html(r).show();
+ $errorSpan.html( r ).show();
+ // Some error strings may contain HTML entities (e.g. `“`), let's use the HTML element's text.
+ wp.a11y.speak( $errorSpan.text() );
}
} else {
- $('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show();
+ $errorSpan.html( inlineEditL10n.error ).show();
+ wp.a11y.speak( inlineEditL10n.error );
}
}
);
- return false;
},
revert : function() {
$( 'table.widefat .spinner' ).removeClass( 'is-active' );
$('#'+id).siblings('tr.hidden').addBack().remove();
id = id.substr( id.lastIndexOf('-') + 1 );
- $(this.what+id).show();
+ // Show the taxonomy listing and move focus back to the taxonomy title.
+ $( this.what + id ).show().find( '.row-title' ).focus();
}
-
- return false;
},
getId : function(o) {
};
$(document).ready(function(){inlineEditTax.init();});
-})(jQuery);
+})( jQuery, window.wp );