1 var theList, theExtraList, toggleWithKeyboard = false, getCount, updateCount, updatePending, dashboardTotals;
4 setCommentsList = function() {
5 var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList;
7 totalInput = $('input[name="_total"]', '#comments-form');
8 perPageInput = $('input[name="_per_page"]', '#comments-form');
9 pageInput = $('input[name="_page"]', '#comments-form');
11 dimAfter = function( r, settings ) {
12 var c = $('#' + settings.element), editRow, replyID, replyButton;
14 editRow = $('#replyrow');
15 replyID = $('#comment_ID', editRow).val();
16 replyButton = $('#replybtn', editRow);
18 if ( c.is('.unapproved') ) {
19 if ( settings.data.id == replyID )
20 replyButton.text(adminCommentsL10n.replyApprove);
22 c.find('div.comment_status').html('0');
24 if ( settings.data.id == replyID )
25 replyButton.text(adminCommentsL10n.reply);
27 c.find('div.comment_status').html('1');
30 $('span.pending-count').each( function() {
31 var a = $(this), n, dif;
33 n = a.html().replace(/[^0-9]+/g, '');
39 dif = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
45 a.closest('.awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
51 // Send current total, page, per_page and url
52 delBefore = function( settings, list ) {
53 var cl = $(settings.target).attr('class'), id, el, n, h, a, author, action = false;
55 settings.data._total = totalInput.val() || 0;
56 settings.data._per_page = perPageInput.val() || 0;
57 settings.data._page = pageInput.val() || 0;
58 settings.data._url = document.location.href;
59 settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val();
61 if ( cl.indexOf(':trash=1') != -1 )
63 else if ( cl.indexOf(':spam=1') != -1 )
67 id = cl.replace(/.*?comment-([0-9]+).*/, '$1');
68 el = $('#comment-' + id);
69 note = $('#' + action + '-undo-holder').html();
71 el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits.
73 if ( el.siblings('#replyrow').length && commentReply.cid == id )
77 n = el.children(':visible').length;
78 author = $('.author strong', el).text();
79 h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
81 author = $('.comment-author', el).text();
82 h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
87 $('strong', '#undo-' + id).text(author + ' ');
88 a = $('.undo a', '#undo-' + id);
89 a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
90 a.attr('class', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1 vim-z vim-destructive');
91 $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
94 list.wpList.del(this);
95 $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
97 $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() });
106 // Updates the current total (stored in the _total input)
107 updateTotalCount = function( total, time, setConfidentTime ) {
108 if ( time < lastConfidentTime )
111 if ( setConfidentTime )
112 lastConfidentTime = time;
114 totalInput.val( total.toString() );
117 dashboardTotals = function(n) {
118 var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
121 if ( isNaN(n) || !dash.length )
124 total = $('span.total-count', dash);
125 appr = $('span.approved-count', dash);
126 totalN = getCount(total);
129 apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) );
130 updateCount(total, totalN);
131 updateCount(appr, apprN);
135 getCount = function(el) {
136 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
142 updateCount = function(el, n) {
146 n = n < 1 ? '0' : n.toString();
147 if ( n.length > 3 ) {
148 while ( n.length > 3 ) {
149 n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
150 n = n.substr(0, n.length - 3);
157 updatePending = function(n) {
158 $('span.pending-count').each( function() {
164 a.closest('.awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
170 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
171 delAfter = function( r, settings ) {
172 var total, N, spam, trash, pending,
173 untrash = $(settings.target).parent().is('span.untrash'),
174 unspam = $(settings.target).parent().is('span.unspam'),
175 unapproved = $('#' + settings.element).is('.unapproved');
177 function getUpdate(s) {
178 if ( $(settings.target).parent().is('span.' + s) )
180 else if ( $('#' + settings.element).is('.' + s) )
189 trash = getUpdate('trash');
194 spam = getUpdate('spam');
196 pending = getCount( $('span.pending-count').eq(0) );
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;
204 updatePending(pending);
206 $('span.spam-count').each( function() {
207 var a = $(this), n = getCount(a) + spam;
211 $('span.trash-count').each( function() {
212 var a = $(this), n = getCount(a) + trash;
216 if ( $('#dashboard_right_now').length ) {
217 N = trash ? -1 * trash : 0;
220 total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
221 if ( $(settings.target).parent().is('span.undo') )
229 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
230 total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
231 if ( total_items_i18n ) {
232 $('.displaying-num').text( total_items_i18n );
233 $('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
234 $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
236 updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
238 updateTotalCount( total, r, false );
243 if ( ! theExtraList || theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash || unspam ) {
247 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
249 refillTheExtraList();
252 refillTheExtraList = function(ev) {
253 var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val();
258 if (args.paged > total_pages) {
263 theExtraList.empty();
264 args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php
267 args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list
270 args.no_placeholder = true;
274 // $.query.get() needs some correction to be sent into an ajax request
275 if ( true === args.comment_type )
276 args.comment_type = '';
278 args = $.extend(args, {
279 'action': 'fetch-list',
280 'list_args': list_args,
281 '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val()
289 success: function(response) {
290 theExtraList.get(0).wpList.add( response.rows );
295 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
296 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
297 .bind('wpListDelEnd', function(e, s){
298 var id = s.element.replace(/[^0-9]+/g, '');
300 if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 )
301 $('#undo-' + id).fadeIn(300, function(){ $(this).show() });
310 var row = $('#replyrow');
312 $('a.cancel', row).click(function() { return commentReply.revert(); });
313 $('a.save', row).click(function() { return commentReply.send(); });
314 $('input#author, input#author-email, input#author-url', row).keypress(function(e){
315 if ( e.which == 13 ) {
323 $('#the-comment-list .column-comment > p').dblclick(function(){
324 commentReply.toggle($(this).parent());
327 $('#doaction, #doaction2, #post-query-submit').click(function(e){
328 if ( $('#the-comment-list #replyrow').length > 0 )
329 commentReply.close();
332 this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
334 /* $(listTable).bind('beforeChangePage', function(){
335 commentReply.close();
339 addEvents : function(r) {
341 $(this).find('.column-comment > p').dblclick(function(){
342 commentReply.toggle($(this).parent());
347 toggle : function(el) {
348 if ( $(el).css('display') != 'none' )
349 $(el).find('a.vim-q').click();
352 revert : function() {
354 if ( $('#the-comment-list #replyrow').length < 1 )
357 $('#replyrow').fadeOut('fast', function(){
358 commentReply.close();
368 c = $('#comment-' + this.cid);
370 if ( typeof QTags != 'undefined' )
371 QTags.closeAllTags('replycontent');
373 if ( this.act == 'edit-comment' )
374 c.fadeIn(300, function(){ c.show() }).css('backgroundColor', '');
376 $('#replyrow').hide();
377 $('#com-reply').append( $('#replyrow') );
378 $('#replycontent').val('');
379 $('input', '#edithead').val('');
380 $('.error', '#replysubmit').html('').hide();
381 $('.waiting', '#replysubmit').hide();
382 $('#replycontent').css('height', '');
388 open : function(id, p, a) {
389 var t = this, editRow, rowData, act, c = $('#comment-' + id), h = c.height(), replyButton;
394 editRow = $('#replyrow');
395 rowData = $('#inline-'+id);
396 act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment';
398 $('#action', editRow).val(act);
399 $('#comment_post_ID', editRow).val(p);
400 $('#comment_ID', editRow).val(id);
403 $('#replycontent', editRow).css('height', (35+h) + 'px');
406 $('#author', editRow).val( $('div.author', rowData).text() );
407 $('#author-email', editRow).val( $('div.author-email', rowData).text() );
408 $('#author-url', editRow).val( $('div.author-url', rowData).text() );
409 $('#status', editRow).val( $('div.comment_status', rowData).text() );
410 $('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
411 $('#edithead, #savebtn', editRow).show();
412 $('#replyhead, #replybtn', editRow).hide();
414 c.after( editRow ).fadeOut('fast', function(){
415 $('#replyrow').fadeIn(300, function(){ $(this).show() });
418 replyButton = $('#replybtn', editRow);
419 $('#edithead, #savebtn', editRow).hide();
420 $('#replyhead, #replybtn', editRow).show();
423 if ( c.hasClass('unapproved') ) {
424 replyButton.text(adminCommentsL10n.replyApprove);
426 replyButton.text(adminCommentsL10n.reply);
429 $('#replyrow').fadeIn(300, function(){ $(this).show() });
432 setTimeout(function() {
433 var rtop, rbottom, scrollTop, vp, scrollBottom;
435 rtop = $('#replyrow').offset().top;
436 rbottom = rtop + $('#replyrow').height();
437 scrollTop = window.pageYOffset || document.documentElement.scrollTop;
438 vp = document.documentElement.clientHeight || self.innerHeight || 0;
439 scrollBottom = scrollTop + vp;
441 if ( scrollBottom - 20 < rbottom )
442 window.scroll(0, rbottom - vp + 35);
443 else if ( rtop - 20 < scrollTop )
444 window.scroll(0, rtop - 35);
446 $('#replycontent').focus().keyup(function(e){
448 commentReply.revert(); // close on Escape
458 $('#replysubmit .error').hide();
459 $('#replysubmit .waiting').show();
461 $('#replyrow input').not(':button').each(function() {
462 post[ $(this).attr('name') ] = $(this).val();
465 post.content = $('#replycontent').val();
466 post.id = post.comment_post_ID;
467 post.comments_listing = this.comments_listing;
468 post.p = $('[name="p"]').val();
470 if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') )
471 post.approve_parent = 1;
477 success : function(x) { commentReply.show(x); },
478 error : function(r) { commentReply.error(r); }
484 show : function(xml) {
485 var t = this, r, c, id, bg, pid;
487 if ( typeof(xml) == 'string' ) {
488 t.error({'responseText': xml});
492 r = wpAjax.parseAjaxResponse(xml);
494 t.error({'responseText': wpAjax.broken});
502 id = '#comment-' + r.id;
503 if ( 'edit-comment' == t.act )
506 if ( r.supplemental.parent_approved ) {
507 pid = $('#comment-' + r.supplemental.parent_approved);
508 updatePending( getCount( $('span.pending-count').eq(0) ) - 1 );
510 if ( this.comments_listing == 'moderated' ) {
511 pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){
519 $('#replyrow').after(c);
522 bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor');
524 id.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
525 .animate( { 'backgroundColor': bg }, 300, function() {
526 if ( pid && pid.length ) {
527 pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
528 .animate( { 'backgroundColor': bg }, 300 )
529 .removeClass('unapproved').addClass('approved')
530 .find('div.comment_status').html('1');
536 error : function(r) {
537 var er = r.statusText;
539 $('#replysubmit .waiting').hide();
541 if ( r.responseText )
542 er = r.responseText.replace( /<.[^<>]*?>/g, '' );
545 $('#replysubmit .error').html(er).show();
550 $(document).ready(function(){
551 var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
555 $(document).delegate('span.delete a.delete', 'click', function(){return false;});
558 if ( typeof $.table_hotkeys != 'undefined' ) {
559 make_hotkeys_redirect = function(which) {
563 first_last = 'next' == which? 'first' : 'last';
564 l = $('.tablenav-pages .'+which+'-page:not(.disabled)');
566 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
570 edit_comment = function(event, current_row) {
571 window.location = $('span.edit a', current_row).attr('href');
574 toggle_all = function() {
575 toggleWithKeyboard = true;
576 $('input:checkbox', '#cb').click().prop('checked', false);
577 toggleWithKeyboard = false;
580 make_bulk = function(value) {
582 var scope = $('select[name="action"]');
583 $('option[value="' + value + '"]', scope).prop('selected', true);
584 $('#doaction').click();
590 ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all],
591 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')],
592 ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')],
593 ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]],
594 { highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
595 prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') }