Comments: dynamically update the document title text of the Comments List Table page when dynamically updating the number of comments awaiting moderation.
Fixes #33414. Built from https://develop.svn.wordpress.org/trunk@33821 git-svn-id: http://core.svn.wordpress.org/trunk@33789 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5a97ff5206
commit
7808d5d1fa
|
@ -104,10 +104,29 @@ $wp_list_table->prepare_items();
|
|||
wp_enqueue_script('admin-comments');
|
||||
enqueue_comment_hotkeys_js();
|
||||
|
||||
if ( $post_id )
|
||||
$title = sprintf( __( 'Comments on “%s”' ), wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' ) );
|
||||
else
|
||||
$title = __('Comments');
|
||||
if ( $post_id ) {
|
||||
$comments_count = wp_count_comments( $post_id );
|
||||
$draft_or_post_title = wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' );
|
||||
if ( $comments_count->moderated > 0 ) {
|
||||
$title = sprintf(
|
||||
__( 'Comments (%s) on “%s”' ),
|
||||
number_format_i18n( $comments_count->moderated ),
|
||||
$draft_or_post_title
|
||||
);
|
||||
} else {
|
||||
$title = sprintf( __( 'Comments on “%s”' ), $draft_or_post_title );
|
||||
}
|
||||
} else {
|
||||
$comments_count = wp_count_comments();
|
||||
if ( $comments_count->moderated > 0 ) {
|
||||
$title = sprintf(
|
||||
__( 'Comments (%s)' ),
|
||||
number_format_i18n( $comments_count->moderated )
|
||||
);
|
||||
} else {
|
||||
$title = __( 'Comments' );
|
||||
}
|
||||
}
|
||||
|
||||
add_screen_option( 'per_page' );
|
||||
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
var setCommentsList, theList, theExtraList, commentReply;
|
||||
|
||||
(function($) {
|
||||
var getCount, updateCount, updateCountText, updatePending, updateApproved;
|
||||
var getCount, updateCount, updateCountText, updatePending, updateApproved,
|
||||
updateHtmlTitle, adminTitle = document.title;
|
||||
|
||||
setCommentsList = function() {
|
||||
var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff,
|
||||
lastConfidentTime = 0;
|
||||
lastConfidentTime = 0, titleDiv, titleRegEx,
|
||||
isDashboard = $('#dashboard_right_now').length;
|
||||
|
||||
totalInput = $('input[name="_total"]', '#comments-form');
|
||||
perPageInput = $('input[name="_per_page"]', '#comments-form');
|
||||
|
@ -135,6 +137,31 @@ setCommentsList = function() {
|
|||
el.html(n);
|
||||
};
|
||||
|
||||
updateHtmlTitle = function ( diff ) {
|
||||
var newTitle, regExMatch, titleCount;
|
||||
|
||||
titleRegEx = titleRegEx || new RegExp( 'Comments (\\([0-9' + thousandsSeparator + ']+\\))?' );
|
||||
// count funcs operate on a $'d element
|
||||
titleDiv = titleDiv || $( '<div />' );
|
||||
newTitle = adminTitle;
|
||||
|
||||
titleDiv.html( document.title );
|
||||
titleCount = getCount( titleDiv ) + diff;
|
||||
if ( titleCount >= 1 ) {
|
||||
updateCount( titleDiv, titleCount );
|
||||
regExMatch = titleRegEx.exec( document.title );
|
||||
if ( regExMatch ) {
|
||||
newTitle = document.title.replace( regExMatch[0], 'Comments (' + titleDiv.text() + ') ' );
|
||||
}
|
||||
} else {
|
||||
regExMatch = titleRegEx.exec( newTitle );
|
||||
if ( regExMatch ) {
|
||||
newTitle = newTitle.replace( regExMatch[0], 'Comments' );
|
||||
}
|
||||
}
|
||||
document.title = newTitle;
|
||||
};
|
||||
|
||||
updatePending = function( diff, commentPostId ) {
|
||||
var postSelector = '.post-com-count-' + commentPostId,
|
||||
noClass = 'comment-count-no-pending',
|
||||
|
@ -143,6 +170,10 @@ setCommentsList = function() {
|
|||
pending,
|
||||
noPending;
|
||||
|
||||
if ( ! isDashboard ) {
|
||||
updateHtmlTitle( diff );
|
||||
}
|
||||
|
||||
$( 'span.pending-count' ).each(function() {
|
||||
var a = $(this), n = getCount(a) + diff;
|
||||
if ( n < 1 )
|
||||
|
@ -390,7 +421,7 @@ setCommentsList = function() {
|
|||
updateCountText( 'span.trash-count', trashDiff );
|
||||
}
|
||||
|
||||
if ( ! $('#dashboard_right_now').length ) {
|
||||
if ( ! isDashboard ) {
|
||||
total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
|
||||
if ( $(settings.target).parent().is('span.undo') )
|
||||
total++;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.4-alpha-33820';
|
||||
$wp_version = '4.4-alpha-33821';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue