WordPress.org

Make WordPress Core

Changeset 19895


Ignore:
Timestamp:
02/09/12 23:29:24 (3 years ago)
Author:
duck_
Message:

Fix incorrect pending comment count updates for filtered views. Fixes #19905.

Pass the difference (i.e. 1 or -1) to updatePending() so that the current
pending count is changed for each element independently. Also move several
functions back out of the global scope, see r17832 for their introduction.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/edit-comments.dev.js

    r19804 r19895  
    1 var theList, theExtraList, toggleWithKeyboard = false, getCount, updateCount, updatePending, dashboardTotals; 
     1var theList, theExtraList, toggleWithKeyboard = false; 
     2 
    23(function($) { 
     4var getCount, updateCount, updatePending, dashboardTotals; 
    35 
    46setCommentsList = function() { 
     
    2830        } 
    2931 
    30         $('span.pending-count').each( function() { 
    31             var a = $(this), n, dif; 
    32  
    33             n = a.html().replace(/[^0-9]+/g, ''); 
    34             n = parseInt(n, 10); 
    35  
    36             if ( isNaN(n) ) 
    37                 return; 
    38  
    39             dif = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; 
    40             n = n + dif; 
    41  
    42             if ( n < 0 ) 
    43                 n = 0; 
    44  
    45             a.closest('.awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); 
    46             updateCount(a, n); 
    47             dashboardTotals(); 
    48         }); 
     32        var diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; 
     33        updatePending( diff ); 
    4934    }; 
    5035 
     
    130115        updateCount(total, totalN); 
    131116        updateCount(appr, apprN); 
    132  
    133117    }; 
    134118 
     
    155139    }; 
    156140 
    157     updatePending = function(n) { 
    158         $('span.pending-count').each( function() { 
    159             var a = $(this); 
    160  
    161             if ( n < 0 ) 
     141    updatePending = function( diff ) { 
     142        $('span.pending-count').each(function() { 
     143            var a = $(this), n = getCount(a) + diff; 
     144            if ( n < 1 ) 
    162145                n = 0; 
    163  
    164146            a.closest('.awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); 
    165             updateCount(a, n); 
    166             dashboardTotals(); 
    167         }); 
     147            updateCount( a, n ); 
     148        }); 
     149 
     150        dashboardTotals(); 
    168151    }; 
    169152 
     
    194177            spam = getUpdate('spam'); 
    195178 
    196         pending = getCount( $('span.pending-count').eq(0) ); 
    197  
    198         if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove" 
    199             pending = pending + 1; 
    200         } else if ( unapproved ) { // we deleted a formerly unapproved comment 
    201             pending = pending - 1; 
     179        if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) { 
     180            // a comment was 'deleted' from another list (e.g. approved, spam, trash) and moved to pending, 
     181            // or a trash/spam of a pending comment was undone 
     182            pending = 1; 
     183        } else if ( unapproved ) { 
     184            // a pending comment was trashed/spammed/approved 
     185            pending = -1; 
    202186        } 
    203187 
     
    505489        if ( r.supplemental.parent_approved ) { 
    506490            pid = $('#comment-' + r.supplemental.parent_approved); 
    507             updatePending( getCount( $('span.pending-count').eq(0) ) - 1 ); 
     491            updatePending( -1 ); 
    508492 
    509493            if ( this.comments_listing == 'moderated' ) { 
Note: See TracChangeset for help on using the changeset viewer.