X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/53f4633144ed68c8b8fb5861f992b5489894a940..bd54ad7dcd1cbf3b37f7822f71ca57b742f00a77:/wp-admin/js/inline-edit-post.js diff --git a/wp-admin/js/inline-edit-post.js b/wp-admin/js/inline-edit-post.js index 02f5c76e..3a65805e 100644 --- a/wp-admin/js/inline-edit-post.js +++ b/wp-admin/js/inline-edit-post.js @@ -1,7 +1,8 @@ /* global inlineEditL10n, ajaxurl, typenow */ +window.wp = window.wp || {}; var inlineEditPost; -(function($) { +( function( $, wp ) { inlineEditPost = { init : function(){ @@ -48,9 +49,9 @@ inlineEditPost = { }); // add events - $('#the-list').on('click', 'a.editinline', function(){ + $('#the-list').on( 'click', 'a.editinline', function( e ) { + e.preventDefault(); inlineEditPost.edit(this); - return false; }); $('#bulk-edit').find('fieldset:first').after( @@ -62,7 +63,11 @@ inlineEditPost = { $('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(); @@ -117,7 +122,7 @@ inlineEditPost = { }, 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' ) { @@ -145,15 +150,6 @@ inlineEditPost = { $('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 @@ -244,6 +240,7 @@ inlineEditPost = { return false; }, + // Ajax saving is only for Quick Edit. save : function(id) { var params, fields, page = $('.post_status_page').val() || ''; @@ -267,39 +264,55 @@ inlineEditPost = { // 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 (r) { if ( -1 !== r.indexOf( ']*?>/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 id = $('table.widefat tr.inline-editor').attr('id'); + var $tableWideFat = $( '.widefat' ), + id = $( '.inline-editor', $tableWideFat ).attr( 'id' ); if ( id ) { - $( 'table.widefat .spinner' ).removeClass( 'is-active' ); + $( '.spinner', $tableWideFat ).removeClass( 'is-active' ); + $( '.ac_results' ).hide(); if ( 'bulk-edit' === id ) { - $('table.widefat #bulk-edit').removeClass('inline-editor').hide().siblings('tr.hidden').remove(); + $( '#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(); } } @@ -329,7 +342,7 @@ $( document ).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) { row.find('.check-column checkbox').prop('checked', false); if ( lock_data.avatar_src ) { - avatar = $('').attr( 'src', lock_data.avatar_src.replace(/&/g, '&') ); + avatar = $( '' ).attr( 'src', lock_data.avatar_src.replace( /&/g, '&' ) ); row.find('.column-title .locked-avatar').empty().append( avatar ); } row.addClass('wp-locked'); @@ -358,4 +371,4 @@ $( document ).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) { } }); -}(jQuery)); +})( jQuery, window.wp );