+ diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
+ if ( response ) {
+ updateDashboardText( response.supplemental );
+ updatePending( diff, response.supplemental.postId );
+ updateApproved( -1 * diff, response.supplemental.postId );
+ } else {
+ updatePending( diff );
+ updateApproved( -1 * diff );
+ }
+ };
+
+ // Send current total, page, per_page and url
+ delBefore = function( settings, list ) {
+ var note, id, el, n, h, a, author,
+ action = false,
+ wpListsData = $( settings.target ).attr( 'data-wp-lists' );
+
+ settings.data._total = totalInput.val() || 0;
+ settings.data._per_page = perPageInput.val() || 0;
+ settings.data._page = pageInput.val() || 0;
+ settings.data._url = document.location.href;
+ settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val();
+
+ if ( wpListsData.indexOf(':trash=1') != -1 )
+ action = 'trash';
+ else if ( wpListsData.indexOf(':spam=1') != -1 )
+ action = 'spam';
+
+ if ( action ) {
+ id = wpListsData.replace(/.*?comment-([0-9]+).*/, '$1');
+ el = $('#comment-' + id);
+ note = $('#' + action + '-undo-holder').html();
+
+ el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits.
+
+ if ( el.siblings('#replyrow').length && commentReply.cid == id )
+ commentReply.close();
+
+ if ( el.is('tr') ) {
+ n = el.children(':visible').length;
+ author = $('.author strong', el).text();
+ h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
+ } else {
+ author = $('.comment-author', el).text();
+ h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
+ }
+
+ el.before(h);
+
+ $('strong', '#undo-' + id).text(author);
+ a = $('.undo a', '#undo-' + id);
+ a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
+ a.attr('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1');
+ a.attr('class', 'vim-z vim-destructive');
+ $('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
+
+ a.click(function( e ){
+ e.preventDefault();
+ e.stopPropagation(); // ticket #35904
+ list.wpList.del(this);
+ $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
+ $(this).remove();
+ $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show(); });
+ });
+ });
+ }
+
+ return settings;
+ };
+
+ // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
+ delAfter = function( r, settings ) {
+ var total_items_i18n, total, animated, animatedCallback,
+ response = true === settings.parsed ? {} : settings.parsed.responses[0],
+ commentStatus = true === settings.parsed ? '' : response.supplemental.status,
+ commentPostId = true === settings.parsed ? '' : response.supplemental.postId,
+ newTotal = true === settings.parsed ? '' : response.supplemental,
+
+ targetParent = $( settings.target ).parent(),
+ commentRow = $('#' + settings.element),
+
+ spamDiff, trashDiff, pendingDiff, approvedDiff,
+
+ approved = commentRow.hasClass( 'approved' ),
+ unapproved = commentRow.hasClass( 'unapproved' ),
+ spammed = commentRow.hasClass( 'spam' ),
+ trashed = commentRow.hasClass( 'trash' ),
+ undoing = false; // ticket #35904
+
+ updateDashboardText( newTotal );
+
+ // the order of these checks is important
+ // .unspam can also have .approve or .unapprove
+ // .untrash can also have .approve or .unapprove
+
+ if ( targetParent.is( 'span.undo' ) ) {
+ // the comment was spammed
+ if ( targetParent.hasClass( 'unspam' ) ) {
+ spamDiff = -1;
+
+ if ( 'trash' === commentStatus ) {
+ trashDiff = 1;
+ } else if ( '1' === commentStatus ) {
+ approvedDiff = 1;
+ } else if ( '0' === commentStatus ) {
+ pendingDiff = 1;
+ }
+
+ // the comment was trashed
+ } else if ( targetParent.hasClass( 'untrash' ) ) {
+ trashDiff = -1;
+
+ if ( 'spam' === commentStatus ) {
+ spamDiff = 1;
+ } else if ( '1' === commentStatus ) {
+ approvedDiff = 1;
+ } else if ( '0' === commentStatus ) {
+ pendingDiff = 1;
+ }
+ }
+
+ undoing = true;
+
+ // user clicked "Spam"
+ } else if ( targetParent.is( 'span.spam' ) ) {
+ // the comment is currently approved
+ if ( approved ) {
+ approvedDiff = -1;
+ // the comment is currently pending
+ } else if ( unapproved ) {
+ pendingDiff = -1;
+ // the comment was in the trash
+ } else if ( trashed ) {
+ trashDiff = -1;
+ }
+ // you can't spam an item on the spam screen
+ spamDiff = 1;
+
+ // user clicked "Unspam"
+ } else if ( targetParent.is( 'span.unspam' ) ) {
+ if ( approved ) {
+ pendingDiff = 1;
+ } else if ( unapproved ) {
+ approvedDiff = 1;
+ } else if ( trashed ) {
+ // the comment was previously approved
+ if ( targetParent.hasClass( 'approve' ) ) {
+ approvedDiff = 1;
+ // the comment was previously pending
+ } else if ( targetParent.hasClass( 'unapprove' ) ) {
+ pendingDiff = 1;
+ }
+ } else if ( spammed ) {
+ if ( targetParent.hasClass( 'approve' ) ) {
+ approvedDiff = 1;
+
+ } else if ( targetParent.hasClass( 'unapprove' ) ) {
+ pendingDiff = 1;
+ }
+ }
+ // you can Unspam an item on the spam screen
+ spamDiff = -1;
+
+ // user clicked "Trash"
+ } else if ( targetParent.is( 'span.trash' ) ) {
+ if ( approved ) {
+ approvedDiff = -1;
+ } else if ( unapproved ) {
+ pendingDiff = -1;
+ // the comment was in the spam queue
+ } else if ( spammed ) {
+ spamDiff = -1;
+ }
+ // you can't trash an item on the trash screen
+ trashDiff = 1;
+
+ // user clicked "Restore"
+ } else if ( targetParent.is( 'span.untrash' ) ) {
+ if ( approved ) {
+ pendingDiff = 1;
+ } else if ( unapproved ) {
+ approvedDiff = 1;
+ } else if ( trashed ) {
+ if ( targetParent.hasClass( 'approve' ) ) {
+ approvedDiff = 1;
+ } else if ( targetParent.hasClass( 'unapprove' ) ) {
+ pendingDiff = 1;
+ }
+ }
+ // you can't go from trash to spam
+ // you can untrash on the trash screen
+ trashDiff = -1;
+
+ // User clicked "Approve"
+ } else if ( targetParent.is( 'span.approve:not(.unspam):not(.untrash)' ) ) {
+ approvedDiff = 1;
+ pendingDiff = -1;
+
+ // User clicked "Unapprove"
+ } else if ( targetParent.is( 'span.unapprove:not(.unspam):not(.untrash)' ) ) {
+ approvedDiff = -1;
+ pendingDiff = 1;
+
+ // User clicked "Delete Permanently"
+ } else if ( targetParent.is( 'span.delete' ) ) {
+ if ( spammed ) {
+ spamDiff = -1;
+ } else if ( trashed ) {
+ trashDiff = -1;
+ }
+ }
+
+ if ( pendingDiff ) {
+ updatePending( pendingDiff, commentPostId );
+ updateCountText( 'span.all-count', pendingDiff );
+ }
+
+ if ( approvedDiff ) {
+ updateApproved( approvedDiff, commentPostId );
+ updateCountText( 'span.all-count', approvedDiff );
+ }
+
+ if ( spamDiff ) {
+ updateCountText( 'span.spam-count', spamDiff );
+ }
+
+ if ( trashDiff ) {
+ updateCountText( 'span.trash-count', trashDiff );
+ }
+
+ if ( ! isDashboard ) {
+ total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
+ if ( $(settings.target).parent().is('span.undo') )
+ total++;
+ else
+ total--;
+
+ if ( total < 0 )
+ total = 0;
+
+ if ( 'object' === typeof r ) {
+ if ( response.supplemental.total_items_i18n && lastConfidentTime < response.supplemental.time ) {
+ total_items_i18n = response.supplemental.total_items_i18n || '';
+ if ( total_items_i18n ) {
+ $('.displaying-num').text( total_items_i18n );
+ $('.total-pages').text( response.supplemental.total_pages_i18n );
+ $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', response.supplemental.total_pages == $('.current-page').val());
+ }
+ updateTotalCount( total, response.supplemental.time, true );
+ } else if ( response.supplemental.time ) {
+ updateTotalCount( total, response.supplemental.time, false );
+ }
+ } else {
+ updateTotalCount( total, r, false );
+ }
+ }
+
+ if ( ! theExtraList || theExtraList.length === 0 || theExtraList.children().length === 0 || undoing ) {
+ return;
+ }
+
+ theList.get(0).wpList.add( theExtraList.children( ':eq(0):not(.no-items)' ).remove().clone() );
+
+ refillTheExtraList();
+
+ animated = $( ':animated', '#the-comment-list' );
+ animatedCallback = function () {
+ if ( ! $( '#the-comment-list tr:visible' ).length ) {
+ theList.get(0).wpList.add( theExtraList.find( '.no-items' ).clone() );
+ }
+ };
+
+ if ( animated.length ) {
+ animated.promise().done( animatedCallback );
+ } else {
+ animatedCallback();
+ }
+ };
+
+ refillTheExtraList = function(ev) {
+ var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val();
+
+ if (! args.paged)
+ args.paged = 1;
+
+ if (args.paged > total_pages) {
+ return;
+ }
+
+ if (ev) {
+ theExtraList.empty();
+ args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php
+ } else {
+ args.number = 1;
+ args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list
+ }
+
+ args.no_placeholder = true;
+
+ args.paged ++;
+
+ // $.query.get() needs some correction to be sent into an ajax request
+ if ( true === args.comment_type )
+ args.comment_type = '';
+
+ args = $.extend(args, {
+ 'action': 'fetch-list',
+ 'list_args': list_args,
+ '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val()
+ });
+
+ $.ajax({
+ url: ajaxurl,
+ global: false,
+ dataType: 'json',
+ data: args,
+ success: function(response) {
+ theExtraList.get(0).wpList.add( response.rows );
+ }
+ });