diff --git a/src/js/_enqueues/admin/tags.js b/src/js/_enqueues/admin/tags.js index ff7761adb8d3e..e00235496c8e1 100644 --- a/src/js/_enqueues/admin/tags.js +++ b/src/js/_enqueues/admin/tags.js @@ -59,8 +59,10 @@ jQuery( function($) { nextFocus = prevFocus; } } - - tr.fadeOut('normal', function(){ tr.remove(); }); + tr.fadeOut('normal', function() { + tr.remove(); + updateTableNavCount(); + }); /** * Removes the term from the parent box and the tag cloud. @@ -73,7 +75,7 @@ jQuery( function($) { $('a.tag-link-' + data.match(/tag_ID=(\d+)/)[1]).remove(); nextFocus.trigger( 'focus' ); message = wp.i18n.__( 'The selected tag has been deleted.' ); - + } else if ( '-1' == r ) { message = wp.i18n.__( 'Sorry, you are not allowed to do that.' ); $('#ajax-response').empty().append('

' + message + '

'); @@ -103,6 +105,33 @@ jQuery( function($) { tr.find( ':input, a' ).prop( 'disabled', false ).removeAttr( 'tabindex' ); } + /** + * Update the row count for table navigation.. + * + * @return {void} + */ + function updateTableNavCount( action = 'remove' ) { + var currentCount = parseInt( $('.tablenav-pages .displaying-num').first().text().match(/\d+/) ) || 0; + var itemCount = ( 'remove' === action ) ? currentCount - 1 || 0 : currentCount + 1; + var itemText = wp.i18n.sprintf( wp.i18n._n( '%d item', '%d items', itemCount ), itemCount ); + $('.tablenav-pages .displaying-num').text( itemText ); + // Show the tablenav if row count positive. + if ( itemCount === 1 ) { + $('.tablenav').show(); + $('p.search-box').show(); + } + if ( $('#the-list tr').length === 0 ) { + $('#the-list').append( + '' + + wp.i18n.__( 'No tags found.' ) + + '' + ); + + $('.tablenav').hide(); + $('p.search-box').hide(); + } + } + /** * Adds a deletion confirmation when removing a tag. * @@ -192,6 +221,8 @@ jQuery( function($) { } $('input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):visible, textarea:visible', form).val(''); + + updateTableNavCount( 'add' ); }); return false;