Make WordPress Core

Changeset 33662


Ignore:
Timestamp:
08/20/2015 04:35:21 PM (11 years ago)
Author:
wonderboymusic
Message:

Comment List Tables:

  • Ensure that dynamic bubble counts are in sync by comment_post_ID
  • Scope :animated to #the-comment-list

See #11200.

Location:
trunk/src/wp-admin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r33655 r33662  
    358358                        'supplemental' => array(
    359359                                'status' => $comment ? $comment->comment_approved : '',
     360                                'postId' => $comment ? $comment->comment_post_ID : '',
    360361                                'time' => $time
    361362                        )
    … …  
    399400                'supplemental' => array(
    400401                        'status' => $comment ? $comment->comment_approved : '',
     402                        'postId' => $comment ? $comment->comment_post_ID : '',
    401403                        'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ),
    402404                        'total_pages' => ceil( $total / $per_page ),
    … …  
    10431045
    10441046        if ( $comment_auto_approved )
    1045                 $response['supplemental'] = array( 'parent_approved' => $parent->comment_ID );
     1047                $response['supplemental'] = array( 'parent_approved' => $parent->comment_ID, 'parent_post_id' => $parent->comment_post_ID );
    10461048
    10471049        $x = new WP_Ajax_Response();
  • trunk/src/wp-admin/includes/class-wp-comments-list-table.php

    r33657 r33662  
    412412                <?php
    413413                        $this->items = $this->extra_items;
    414                         $this->display_rows_or_placeholder(); 
     414                        $this->display_rows_or_placeholder();
    415415                ?>
    416416        </tbody>
    … …  
    699699                $post_type_object = get_post_type_object( $post->post_type );
    700700                echo "<a href='" . get_permalink( $post->ID ) . "' class='comments-view-item-link'>" . $post_type_object->labels->view_item . '</a>';
    701                 echo '<span class="post-com-count-wrapper">';
     701                echo '<span class="post-com-count-wrapper post-com-count-', $post->ID, '">';
    702702                $this->comments_bubble( $post->ID, $pending_comments );
    703703                echo '</span> ';
  • trunk/src/wp-admin/includes/class-wp-list-table.php

    r33623 r33662  
    648648                                $pending_comments_number,
    649649                                $pending_phrase
     650                        );
     651                } else {
     652                        printf( '<span class="post-com-count post-com-count-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
     653                                $pending_comments_number,
     654                                $approved_comments ? __( 'No pending comments' ) : __( 'No comments' )
    650655                        );
    651656                }
  • trunk/src/wp-admin/js/edit-comments.js

    r33660 r33662  
    33
    44(function($) {
    5 var getCount, updateCount, updateCountText, updatePending;
     5var getCount, updateCount, updateCountText, updatePending, updateApproved;
    66
    77setCommentsList = function() {
    … …  
    1515        // this fires when viewing "All"
    1616        dimAfter = function( r, settings ) {
    17                 var editRow, replyID, replyButton,
     17                var editRow, replyID, replyButton, response,
    1818                        c = $( '#' + settings.element );
    1919
    … …  
    3535
    3636                diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
    37                 updatePending( diff );
    38                 updateCountText( 'span.approved-count', -1 * diff  );
    39                 updateCountText( 'span.comment-count-approved', -1 * diff );
     37                if ( true !== settings.parsed && settings.parsed.responses.length ) {
     38                        response = settings.parsed.responses[0].supplemental;
     39                        updatePending( diff, response.postId );
     40                        updateApproved( -1 * diff, response.postId );
     41                } else {
     42                        updatePending( diff );
     43                        updateApproved( -1 * diff  );
     44                }
    4045        };
    4146
    … …  
    131136        };
    132137
    133         updatePending = function( diff ) {
    134                 $('span.pending-count, .comment-count-pending').each(function() {
     138        updatePending = function( diff, commentPostId ) {
     139                var postSelector = '.post-com-count-' + commentPostId,
     140                        noClass = 'comment-count-no-pending',
     141                        pendingClass = 'comment-count-pending',
     142                        counts = $( 'span.pending-count' ),
     143                        pending,
     144                        noPending;
     145
     146                counts.each(function() {
    135147                        var a = $(this), n = getCount(a) + diff;
    136148                        if ( n < 1 )
    … …  
    139151                        updateCount( a, n );
    140152                });
     153
     154                if ( ! commentPostId ) {
     155                        return;
     156                }
     157
     158                // cache selectors to not get dupes
     159                pending = $( 'span.' + pendingClass, postSelector );
     160                noPending = $( 'span.' + noClass, postSelector );
     161
     162                pending.each(function() {
     163                        var a = $(this), n = getCount(a) + diff;
     164                        if ( n < 1 )
     165                                n = 0;
     166
     167                        if ( 0 === n ) {
     168                                a.removeClass( pendingClass ).addClass( noClass );
     169                        }
     170                        updateCount( a, n );
     171                });
     172
     173                noPending.each(function() {
     174                        var a = $(this);
     175                        if ( diff > 0 ) {
     176                                a.removeClass( noClass ).addClass( pendingClass );
     177                        }
     178                        updateCount( a, diff );
     179                });
     180        };
     181
     182        updateApproved = function( diff, commentPostId ) {
     183                var postSelector = '.post-com-count-' + commentPostId,
     184                        noClass = 'comment-count-no-comments',
     185                        approvedClass = 'comment-count-approved',
     186                        approved,
     187                        noComments;
     188
     189                updateCountText( 'span.approved-count', diff );
     190
     191                if ( ! commentPostId ) {
     192                        return;
     193                }
     194
     195                // cache selectors to not get dupes
     196                approved = $( 'span.' + approvedClass, postSelector );
     197                noComments = $( 'span.' + noClass, postSelector );
     198
     199                approved.each(function() {
     200                        var a = $(this), n = getCount(a) + diff;
     201                        if ( n < 1 )
     202                                n = 0;
     203
     204                        if ( 0 === n ) {
     205                                a.removeClass( approvedClass ).addClass( noClass );
     206                        }
     207                        updateCount( a, n );
     208                });
     209
     210                noComments.each(function() {
     211                        var a = $(this);
     212                        if ( diff > 0 ) {
     213                                a.removeClass( noClass ).addClass( approvedClass );
     214                        }
     215                        updateCount( a, diff );
     216                });
    141217        };
    142218
    … …  
    153229        // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
    154230        delAfter = function( r, settings ) {
    155                 var total_items_i18n, total, animated, animatedCallback,
     231                var total_items_i18n, total, animated, animatedCallback, postSelector,
    156232                        response = true === settings.parsed ? {} : settings.parsed.responses[0],
    157233                        commentStatus = true === settings.parsed ? '' : response.supplemental.status,
     234                        commentPostId = true === settings.parsed ? '' : response.supplemental.postId,
    158235
    159236                        targetParent = $( settings.target ).parent(),
    … …  
    286363                }
    287364
     365                postSelector = '.post-com-count-' + commentPostId;
     366
    288367                if ( pendingDiff ) {
    289                         updatePending( pendingDiff );
     368                        updatePending( pendingDiff, commentPostId );
    290369                }
    291370
    292371                if ( approvedDiff ) {
    293                         updateCountText( 'span.approved-count', approvedDiff  );
    294                         updateCountText( 'span.comment-count-approved', approvedDiff );
     372                        updateApproved( approvedDiff, commentPostId );
    295373                }
    296374
    … …  
    338416                refillTheExtraList();
    339417
    340                 animated = $( ':animated' );
     418                animated = $( ':animated', '#the-comment-list' );
    341419                animatedCallback = function () {
    342420                        if ( ! $( '#the-comment-list tr:visible' ).length ) {
    … …  
    628706                if ( r.supplemental.parent_approved ) {
    629707                        pid = $('#comment-' + r.supplemental.parent_approved);
    630                         updatePending( -1 );
     708                        updatePending( -1, r.supplemental.parent_post_id );
    631709
    632710                        if ( this.comments_listing == 'moderated' ) {
Note: See TracChangeset for help on using the changeset viewer.