/* global inlineEditL10n, ajaxurl, typenow */
+window.wp = window.wp || {};
var inlineEditPost;
-(function($) {
+( function( $, wp ) {
inlineEditPost = {
init : function(){
$('select[name="_status"] option[value="future"]', bulkRow).remove();
$('#doaction, #doaction2').click(function(e){
- var n = $(this).attr('id').substr(2);
+ var n;
+
+ t.whichBulkButtonId = $( this ).attr( 'id' );
+ n = t.whichBulkButtonId.substr( 2 );
+
if ( 'edit' === $( 'select[name="' + n + '"]' ).val() ) {
e.preventDefault();
t.setBulk();
},
edit : function(id) {
- var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, cur_format, f, val, pw;
+ var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, f, val, pw;
t.revert();
if ( typeof(id) === 'object' ) {
$('label.inline-edit-author', editRow).hide();
}
- // hide unsupported formats, but leave the current format alone
- cur_format = $('.post_format', rowData).text();
- $('option.unsupported', editRow).each(function() {
- var $this = $(this);
- if ( $this.val() !== cur_format ) {
- $this.remove();
- }
- });
-
for ( f = 0; f < fields.length; f++ ) {
val = $('.'+fields[f], rowData);
// Deal with Twemoji
return false;
},
+ // Ajax saving is only for Quick Edit.
save : function(id) {
var params, fields, page = $('.post_status_page').val() || '';
// make ajax request
$.post( ajaxurl, params,
function(r) {
+ var $errorSpan = $( '#edit-' + id + ' .inline-edit-save .error' );
+
$( 'table.widefat .spinner' ).removeClass( 'is-active' );
$( '.ac_results' ).hide();
if ( -1 !== r.indexOf( '<tr' ) ) {
$(inlineEditPost.what+id).siblings('tr.hidden').addBack().remove();
$('#edit-'+id).before(r).remove();
- $(inlineEditPost.what+id).hide().fadeIn();
+ $( inlineEditPost.what + id ).hide().fadeIn( 400, function() {
+ // Move focus back to the Quick Edit link. $( this ) is the row being animated.
+ $( this ).find( '.editinline' ).focus();
+ wp.a11y.speak( inlineEditL10n.saved );
+ });
} else {
r = r.replace( /<.[^<>]*?>/g, '' );
- $('#edit-'+id+' .inline-edit-save .error').html(r).show();
+ $errorSpan.html( r ).show();
+ 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 );
}
},
'html');
+ // Prevent submitting the form when pressing Enter on a focused field.
return false;
},
+ // Revert is for both Quick Edit and Bulk Edit.
revert : function(){
var $tableWideFat = $( '.widefat' ),
id = $( '.inline-editor', $tableWideFat ).attr( 'id' );
$( '#bulk-edit', $tableWideFat ).removeClass( 'inline-editor' ).hide().siblings( '.hidden' ).remove();
$('#bulk-titles').empty();
$('#inlineedit').append( $('#bulk-edit') );
+ // Move focus back to the Bulk Action button that was activated.
+ $( '#' + inlineEditPost.whichBulkButtonId ).focus();
} else {
$('#'+id).siblings('tr.hidden').addBack().remove();
id = id.substr( id.lastIndexOf('-') + 1 );
- $(this.what+id).show();
+ // Show the post row and move focus back to the Quick Edit link.
+ $( this.what + id ).show().find( '.editinline' ).focus();
}
}
}
});
-}(jQuery));
+})( jQuery, window.wp );