2
2
var setCommentsList, theList, theExtraList, commentReply;
5
var getCount, updateCount, updatePending;
5
var getCount, updateCount, updateCountText, updatePending, updateApproved,
6
updateHtmlTitle, updateDashboardText, adminTitle = document.title,
7
isDashboard = $('#dashboard_right_now').length,
10
getCount = function(el) {
11
var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
18
updateCount = function(el, n) {
23
n = n < 1 ? '0' : n.toString();
25
while ( n.length > 3 ) {
26
n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
27
n = n.substr(0, n.length - 3);
34
updateApproved = function( diff, commentPostId ) {
35
var postSelector = '.post-com-count-' + commentPostId,
36
noClass = 'comment-count-no-comments',
37
approvedClass = 'comment-count-approved',
41
updateCountText( 'span.approved-count', diff );
43
if ( ! commentPostId ) {
47
// cache selectors to not get dupes
48
approved = $( 'span.' + approvedClass, postSelector );
49
noComments = $( 'span.' + noClass, postSelector );
51
approved.each(function() {
52
var a = $(this), n = getCount(a) + diff;
57
a.removeClass( approvedClass ).addClass( noClass );
59
a.addClass( approvedClass ).removeClass( noClass );
64
noComments.each(function() {
67
a.removeClass( noClass ).addClass( approvedClass );
69
a.addClass( noClass ).removeClass( approvedClass );
71
updateCount( a, diff );
75
updateCountText = function( selector, diff ) {
76
$( selector ).each(function() {
77
var a = $(this), n = getCount(a) + diff;
85
updateDashboardText = function ( response ) {
86
if ( ! isDashboard || ! response || ! response.i18n_comments_text ) {
90
var rightNow = $( '#dashboard_right_now' );
92
$( '.comment-count a', rightNow ).text( response.i18n_comments_text );
93
$( '.comment-mod-count a', rightNow ).text( response.i18n_moderation_text )
95
[ response.in_moderation > 0 ? 'removeClass' : 'addClass' ]( 'hidden' );
98
updateHtmlTitle = function ( diff ) {
99
var newTitle, regExMatch, titleCount, commentFrag;
101
titleRegEx = titleRegEx || new RegExp( adminCommentsL10n.docTitleCommentsCount.replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' );
102
// count funcs operate on a $'d element
103
titleDiv = titleDiv || $( '<div />' );
104
newTitle = adminTitle;
106
commentFrag = titleRegEx.exec( document.title );
108
commentFrag = commentFrag[0];
109
titleDiv.html( commentFrag );
110
titleCount = getCount( titleDiv ) + diff;
116
if ( titleCount >= 1 ) {
117
updateCount( titleDiv, titleCount );
118
regExMatch = titleRegEx.exec( document.title );
120
newTitle = document.title.replace( regExMatch[0], adminCommentsL10n.docTitleCommentsCount.replace( '%s', titleDiv.text() ) + ' ' );
123
regExMatch = titleRegEx.exec( newTitle );
125
newTitle = newTitle.replace( regExMatch[0], adminCommentsL10n.docTitleComments );
128
document.title = newTitle;
131
updatePending = function( diff, commentPostId ) {
132
var postSelector = '.post-com-count-' + commentPostId,
133
noClass = 'comment-count-no-pending',
134
noParentClass = 'post-com-count-no-pending',
135
pendingClass = 'comment-count-pending',
139
if ( ! isDashboard ) {
140
updateHtmlTitle( diff );
143
$( 'span.pending-count' ).each(function() {
144
var a = $(this), n = getCount(a) + diff;
147
a.closest('.awaiting-mod')[ 0 === n ? 'addClass' : 'removeClass' ]('count-0');
151
if ( ! commentPostId ) {
155
// cache selectors to not get dupes
156
pending = $( 'span.' + pendingClass, postSelector );
157
noPending = $( 'span.' + noClass, postSelector );
159
pending.each(function() {
160
var a = $(this), n = getCount(a) + diff;
165
a.parent().addClass( noParentClass );
166
a.removeClass( pendingClass ).addClass( noClass );
168
a.parent().removeClass( noParentClass );
169
a.addClass( pendingClass ).removeClass( noClass );
174
noPending.each(function() {
177
a.parent().removeClass( noParentClass );
178
a.removeClass( noClass ).addClass( pendingClass );
180
a.parent().addClass( noParentClass );
181
a.addClass( noClass ).removeClass( pendingClass );
183
updateCount( a, diff );
7
187
setCommentsList = function() {
8
188
var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff,
12
192
perPageInput = $('input[name="_per_page"]', '#comments-form');
13
193
pageInput = $('input[name="_page"]', '#comments-form');
195
// Updates the current total (stored in the _total input)
196
updateTotalCount = function( total, time, setConfidentTime ) {
197
if ( time < lastConfidentTime )
200
if ( setConfidentTime )
201
lastConfidentTime = time;
203
totalInput.val( total.toString() );
206
// this fires when viewing "All"
15
207
dimAfter = function( r, settings ) {
16
var editRow, replyID, replyButton,
208
var editRow, replyID, replyButton, response,
17
209
c = $( '#' + settings.element );
211
if ( true !== settings.parsed ) {
212
response = settings.parsed.responses[0];
19
215
editRow = $('#replyrow');
20
216
replyID = $('#comment_ID', editRow).val();
21
217
replyButton = $('#replybtn', editRow);
81
284
a.attr('class', 'vim-z vim-destructive');
82
285
$('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
287
a.click(function( e ){
85
289
list.wpList.del(this);
86
290
$('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
88
292
$('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show(); });
97
// Updates the current total (stored in the _total input)
98
updateTotalCount = function( total, time, setConfidentTime ) {
99
if ( time < lastConfidentTime )
102
if ( setConfidentTime )
103
lastConfidentTime = time;
105
totalInput.val( total.toString() );
108
getCount = function(el) {
109
var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
115
updateCount = function(el, n) {
119
n = n < 1 ? '0' : n.toString();
120
if ( n.length > 3 ) {
121
while ( n.length > 3 ) {
122
n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
123
n = n.substr(0, n.length - 3);
130
updatePending = function( diff ) {
131
$('span.pending-count').each(function() {
132
var a = $(this), n = getCount(a) + diff;
135
a.closest('.awaiting-mod')[ 0 === n ? 'addClass' : 'removeClass' ]('count-0');
140
300
// In admin-ajax.php, we send back the unix time stamp instead of 1 on success
141
301
delAfter = function( r, settings ) {
142
var total_items_i18n, total, spam, trash, pending,
143
untrash = $(settings.target).parent().is('span.untrash'),
144
unspam = $(settings.target).parent().is('span.unspam'),
145
unapproved = $('#' + settings.element).is('.unapproved');
147
function getUpdate(s) {
148
if ( $(settings.target).parent().is('span.' + s) )
150
else if ( $('#' + settings.element).is('.' + s) )
159
trash = getUpdate('trash');
164
spam = getUpdate('spam');
166
if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) {
167
// a comment was 'deleted' from another list (e.g. approved, spam, trash) and moved to pending,
168
// or a trash/spam of a pending comment was undone
170
} else if ( unapproved ) {
171
// a pending comment was trashed/spammed/approved
176
updatePending(pending);
178
$('span.spam-count').each( function() {
179
var a = $(this), n = getCount(a) + spam;
183
$('span.trash-count').each( function() {
184
var a = $(this), n = getCount(a) + trash;
188
if ( ! $('#dashboard_right_now').length ) {
302
var total_items_i18n, total, animated, animatedCallback,
303
response = true === settings.parsed ? {} : settings.parsed.responses[0],
304
commentStatus = true === settings.parsed ? '' : response.supplemental.status,
305
commentPostId = true === settings.parsed ? '' : response.supplemental.postId,
306
newTotal = true === settings.parsed ? '' : response.supplemental,
308
targetParent = $( settings.target ).parent(),
309
commentRow = $('#' + settings.element),
311
spamDiff, trashDiff, pendingDiff, approvedDiff,
313
approved = commentRow.hasClass( 'approved' ),
314
unapproved = commentRow.hasClass( 'unapproved' ),
315
spammed = commentRow.hasClass( 'spam' ),
316
trashed = commentRow.hasClass( 'trash' );
318
updateDashboardText( newTotal );
320
// the order of these checks is important
321
// .unspam can also have .approve or .unapprove
322
// .untrash can also have .approve or .unapprove
324
if ( targetParent.is( 'span.undo' ) ) {
325
// the comment was spammed
326
if ( targetParent.hasClass( 'unspam' ) ) {
329
if ( 'trash' === commentStatus ) {
331
} else if ( '1' === commentStatus ) {
333
} else if ( '0' === commentStatus ) {
337
// the comment was trashed
338
} else if ( targetParent.hasClass( 'untrash' ) ) {
341
if ( 'spam' === commentStatus ) {
343
} else if ( '1' === commentStatus ) {
345
} else if ( '0' === commentStatus ) {
350
// user clicked "Spam"
351
} else if ( targetParent.is( 'span.spam' ) ) {
352
// the comment is currently approved
355
// the comment is currently pending
356
} else if ( unapproved ) {
358
// the comment was in the trash
359
} else if ( trashed ) {
362
// you can't spam an item on the spam screen
365
// user clicked "Unspam"
366
} else if ( targetParent.is( 'span.unspam' ) ) {
369
} else if ( unapproved ) {
371
} else if ( trashed ) {
372
// the comment was previously approved
373
if ( targetParent.hasClass( 'approve' ) ) {
375
// the comment was previously pending
376
} else if ( targetParent.hasClass( 'unapprove' ) ) {
379
} else if ( spammed ) {
380
if ( targetParent.hasClass( 'approve' ) ) {
383
} else if ( targetParent.hasClass( 'unapprove' ) ) {
387
// you can Unspam an item on the spam screen
390
// user clicked "Trash"
391
} else if ( targetParent.is( 'span.trash' ) ) {
394
} else if ( unapproved ) {
396
// the comment was in the spam queue
397
} else if ( spammed ) {
400
// you can't trash an item on the trash screen
403
// user clicked "Restore"
404
} else if ( targetParent.is( 'span.untrash' ) ) {
407
} else if ( unapproved ) {
409
} else if ( trashed ) {
410
if ( targetParent.hasClass( 'approve' ) ) {
412
} else if ( targetParent.hasClass( 'unapprove' ) ) {
416
// you can't go from trash to spam
417
// you can untrash on the trash screen
420
// User clicked "Approve"
421
} else if ( targetParent.is( 'span.approve:not(.unspam):not(.untrash)' ) ) {
425
// User clicked "Unapprove"
426
} else if ( targetParent.is( 'span.unapprove:not(.unspam):not(.untrash)' ) ) {
430
// User clicked "Delete Permanently"
431
} else if ( targetParent.is( 'span.delete' ) ) {
434
} else if ( trashed ) {
440
updatePending( pendingDiff, commentPostId );
441
updateCountText( 'span.all-count', pendingDiff );
444
if ( approvedDiff ) {
445
updateApproved( approvedDiff, commentPostId );
446
updateCountText( 'span.all-count', approvedDiff );
450
updateCountText( 'span.spam-count', spamDiff );
454
updateCountText( 'span.trash-count', trashDiff );
457
if ( ! isDashboard ) {
189
458
total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
190
459
if ( $(settings.target).parent().is('span.undo') )
198
if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
199
total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
200
if ( total_items_i18n ) {
201
$('.displaying-num').text( total_items_i18n );
202
$('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
203
$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
467
if ( 'object' === typeof r ) {
468
if ( response.supplemental.total_items_i18n && lastConfidentTime < response.supplemental.time ) {
469
total_items_i18n = response.supplemental.total_items_i18n || '';
470
if ( total_items_i18n ) {
471
$('.displaying-num').text( total_items_i18n );
472
$('.total-pages').text( response.supplemental.total_pages_i18n );
473
$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', response.supplemental.total_pages == $('.current-page').val());
475
updateTotalCount( total, response.supplemental.time, true );
476
} else if ( response.supplemental.time ) {
477
updateTotalCount( total, response.supplemental.time, false );
205
updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
207
480
updateTotalCount( total, r, false );
211
if ( ! theExtraList || theExtraList.size() === 0 || theExtraList.children().size() === 0 || untrash || unspam ) {
484
if ( ! theExtraList || theExtraList.size() === 0 || theExtraList.children().size() === 0 ) {
215
theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
488
theList.get(0).wpList.add( theExtraList.children( ':eq(0):not(.no-items)' ).remove().clone() );
217
490
refillTheExtraList();
492
animated = $( ':animated', '#the-comment-list' );
493
animatedCallback = function () {
494
if ( ! $( '#the-comment-list tr:visible' ).length ) {
495
theList.get(0).wpList.add( theExtraList.find( '.no-items' ).clone() );
499
if ( animated.length ) {
500
animated.promise().done( animatedCallback );
220
506
refillTheExtraList = function(ev) {