Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions src/js/_enqueues/admin/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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('<div class="notice notice-error"><p>' + message + '</p></div>');
Expand Down Expand Up @@ -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(
'<tr class="no-items"><td class="colspanchange" colspan="5">' +
wp.i18n.__( 'No tags found.' ) +
'</td></tr>'
);

$('.tablenav').hide();
$('p.search-box').hide();
}
}

/**
* Adds a deletion confirmation when removing a tag.
*
Expand Down Expand Up @@ -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;
Expand Down
Loading