Make WordPress Core

Changeset 33821


Ignore:
Timestamp:
08/31/2015 05:57:32 PM (11 years ago)
Author:
wonderboymusic
Message:

Comments: dynamically update the document title text of the Comments List Table page when dynamically updating the number of comments awaiting moderation.

Fixes #33414.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-comments.php

    r33589 r33821  
    105105enqueue_comment_hotkeys_js();
    106106
    107 if ( $post_id )
    108         $title = sprintf( __( 'Comments on “%s”' ), wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' ) );
    109 else
    110         $title = __('Comments');
     107if ( $post_id ) {
     108        $comments_count = wp_count_comments( $post_id );
     109        $draft_or_post_title = wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' );
     110        if ( $comments_count->moderated > 0 ) {
     111                $title = sprintf(
     112                        __( 'Comments (%s) on “%s”' ),
     113                        number_format_i18n( $comments_count->moderated ),
     114                        $draft_or_post_title
     115                );
     116        } else {
     117                $title = sprintf( __( 'Comments on “%s”' ), $draft_or_post_title );
     118        }
     119} else {
     120        $comments_count = wp_count_comments();
     121        if ( $comments_count->moderated > 0 ) {
     122                $title = sprintf(
     123                        __( 'Comments (%s)' ),
     124                        number_format_i18n( $comments_count->moderated )
     125                );
     126        } else {
     127                $title = __( 'Comments' );
     128        }
     129}
    111130
    112131add_screen_option( 'per_page' );
  • trunk/src/wp-admin/js/edit-comments.js

    r33692 r33821  
    33
    44(function($) {
    5 var getCount, updateCount, updateCountText, updatePending, updateApproved;
     5var getCount, updateCount, updateCountText, updatePending, updateApproved,
     6        updateHtmlTitle, adminTitle = document.title;
    67
    78setCommentsList = function() {
    89        var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff,
    9                 lastConfidentTime = 0;
     10                lastConfidentTime = 0, titleDiv, titleRegEx,
     11                isDashboard = $('#dashboard_right_now').length;
    1012
    1113        totalInput = $('input[name="_total"]', '#comments-form');
     
    136138        };
    137139
     140        updateHtmlTitle = function ( diff ) {
     141                var newTitle, regExMatch, titleCount;
     142
     143                titleRegEx = titleRegEx || new RegExp( 'Comments (\\([0-9' + thousandsSeparator + ']+\\))?' );
     144                // count funcs operate on a $'d element
     145                titleDiv = titleDiv || $( '<div />' );
     146                newTitle = adminTitle;
     147
     148                titleDiv.html( document.title );
     149                titleCount = getCount( titleDiv ) + diff;
     150                if ( titleCount >= 1 ) {
     151                        updateCount( titleDiv, titleCount );
     152                        regExMatch = titleRegEx.exec( document.title );
     153                        if ( regExMatch ) {
     154                                newTitle = document.title.replace( regExMatch[0], 'Comments (' + titleDiv.text() + ') ' );
     155                        }
     156                } else {
     157                        regExMatch = titleRegEx.exec( newTitle );
     158                        if ( regExMatch ) {
     159                                newTitle = newTitle.replace( regExMatch[0], 'Comments' );
     160                        }
     161                }
     162                document.title = newTitle;
     163        };
     164
    138165        updatePending = function( diff, commentPostId ) {
    139166                var postSelector = '.post-com-count-' + commentPostId,
     
    143170                        pending,
    144171                        noPending;
     172
     173                if ( ! isDashboard ) {
     174                        updateHtmlTitle( diff );
     175                }
    145176
    146177                $( 'span.pending-count' ).each(function() {
     
    391422                }
    392423
    393                 if ( ! $('#dashboard_right_now').length ) {
     424                if ( ! isDashboard ) {
    394425                        total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
    395426                        if ( $(settings.target).parent().is('span.undo') )
Note: See TracChangeset for help on using the changeset viewer.