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;
32 n = a.html().replace(/[^0-9]+/g, '');
34 if ( isNaN(n) ) return;
35 dif = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
37 if ( n < 0 ) { n = 0; }
38 a.closest('.awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
44 // Send current total, page, per_page and url
45 delBefore = function( settings, list ) {
46 var cl = $(settings.target).attr('class'), id, el, n, h, a, author, action = false;
48 settings.data._total = totalInput.val() || 0;
49 settings.data._per_page = perPageInput.val() || 0;
50 settings.data._page = pageInput.val() || 0;
51 settings.data._url = document.location.href;
52 settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val();
54 if ( cl.indexOf(':trash=1') != -1 )
56 else if ( cl.indexOf(':spam=1') != -1 )
60 id = cl.replace(/.*?comment-([0-9]+).*/, '$1');
61 el = $('#comment-' + id);
62 note = $('#' + action + '-undo-holder').html();
64 el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits.
66 if ( el.siblings('#replyrow').length && commentReply.cid == id )
70 n = el.children(':visible').length;
71 author = $('.author strong', el).text();
72 h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
74 author = $('.comment-author', el).text();
75 h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
80 $('strong', '#undo-' + id).text(author + ' ');
81 a = $('.undo a', '#undo-' + id);
82 a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
83 a.attr('class', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1 vim-z vim-destructive');
84 $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
87 list.wpList.del(this);
88 $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
90 $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() });
99 // Updates the current total (as displayed visibly)
100 updateTotalCount = function( total, time, setConfidentTime ) {
101 if ( time < lastConfidentTime )
104 if ( setConfidentTime )
105 lastConfidentTime = time;
107 totalInput.val( total.toString() );
108 $('span.total-type-count').each( function() {
109 updateCount( $(this), total );
113 dashboardTotals = function(n) {
114 var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
117 if ( isNaN(n) || !dash.length )
120 total = $('span.total-count', dash);
121 appr = $('span.approved-count', dash);
122 totalN = getCount(total);
125 apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) );
126 updateCount(total, totalN);
127 updateCount(appr, apprN);
131 getCount = function(el) {
132 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
138 updateCount = function(el, n) {
142 n = n < 1 ? '0' : n.toString();
143 if ( n.length > 3 ) {
144 while ( n.length > 3 ) {
145 n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
146 n = n.substr(0, n.length - 3);
153 updatePending = function(n) {
154 $('span.pending-count').each( function() {
160 a.closest('.awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
166 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
167 delAfter = function( r, settings ) {
168 var total, N, untrash = $(settings.target).parent().is('span.untrash'),
169 unspam = $(settings.target).parent().is('span.unspam'), spam, trash, pending,
170 unapproved = $('#' + settings.element).is('.unapproved');
172 function getUpdate(s) {
173 if ( $(settings.target).parent().is('span.' + s) )
175 else if ( $('#' + settings.element).is('.' + s) )
181 spam = getUpdate('spam');
182 trash = getUpdate('trash');
189 pending = getCount( $('span.pending-count').eq(0) );
191 if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
192 pending = pending + 1;
193 } else if ( unapproved ) { // we deleted a formerly unapproved comment
194 pending = pending - 1;
197 updatePending(pending);
199 $('span.spam-count').each( function() {
200 var a = $(this), n = getCount(a) + spam;
204 $('span.trash-count').each( function() {
205 var a = $(this), n = getCount(a) + trash;
209 if ( $('#dashboard_right_now').length ) {
210 N = trash ? -1 * trash : 0;
213 total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
214 total = total - spam - trash;
218 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
219 total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
220 if ( total_items_i18n ) {
221 $('.displaying-num').text( total_items_i18n );
222 $('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
223 $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
225 updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
227 updateTotalCount( total, r, false );
232 if ( ! theExtraList || theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash || unspam ) {
236 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
238 refillTheExtraList();
241 refillTheExtraList = function(ev) {
242 var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val();
247 if (args.paged > total_pages) {
252 theExtraList.empty();
253 args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php
256 args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list
259 args.no_placeholder = true;
263 // $.query.get() needs some correction to be sent into an ajax request
264 if ( true === args.comment_type )
265 args.comment_type = '';
267 args = $.extend(args, {
268 'action': 'fetch-list',
269 'list_args': list_args,
270 '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val()
278 success: function(response) {
279 theExtraList.get(0).wpList.add( response.rows );
284 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
285 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
286 .bind('wpListDelEnd', function(e, s){
287 var id = s.element.replace(/[^0-9]+/g, '');
289 if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 )
290 $('#undo-' + id).fadeIn(300, function(){ $(this).show() });
299 var row = $('#replyrow');
301 $('a.cancel', row).click(function() { return commentReply.revert(); });
302 $('a.save', row).click(function() { return commentReply.send(); });
303 $('input#author, input#author-email, input#author-url', row).keypress(function(e){
304 if ( e.which == 13 ) {
312 $('#the-comment-list .column-comment > p').dblclick(function(){
313 commentReply.toggle($(this).parent());
316 $('#doaction, #doaction2, #post-query-submit').click(function(e){
317 if ( $('#the-comment-list #replyrow').length > 0 )
318 commentReply.close();
321 this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
323 /* $(listTable).bind('beforeChangePage', function(){
324 commentReply.close();
328 addEvents : function(r) {
330 $(this).find('.column-comment > p').dblclick(function(){
331 commentReply.toggle($(this).parent());
336 toggle : function(el) {
337 if ( $(el).css('display') != 'none' )
338 $(el).find('a.vim-q').click();
341 revert : function() {
343 if ( $('#the-comment-list #replyrow').length < 1 )
346 $('#replyrow').fadeOut('fast', function(){
347 commentReply.close();
357 c = $('#comment-' + this.cid);
359 if ( this.act == 'edit-comment' )
360 c.fadeIn(300, function(){ c.show() }).css('backgroundColor', '');
362 $('#replyrow').hide();
363 $('#com-reply').append( $('#replyrow') );
364 $('#replycontent').val('');
365 $('input', '#edithead').val('');
366 $('.error', '#replysubmit').html('').hide();
367 $('.waiting', '#replysubmit').hide();
369 if ( $.browser.msie )
370 $('#replycontainer, #replycontent').css('height', '120px');
372 $('#replycontainer').resizable('destroy').css('height', '120px');
378 open : function(id, p, a) {
379 var t = this, editRow, rowData, act, h, c = $('#comment-' + id), replyButton;
384 editRow = $('#replyrow');
385 rowData = $('#inline-'+id);
386 act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment';
388 $('#action', editRow).val(act);
389 $('#comment_post_ID', editRow).val(p);
390 $('#comment_ID', editRow).val(id);
393 $('#author', editRow).val( $('div.author', rowData).text() );
394 $('#author-email', editRow).val( $('div.author-email', rowData).text() );
395 $('#author-url', editRow).val( $('div.author-url', rowData).text() );
396 $('#status', editRow).val( $('div.comment_status', rowData).text() );
397 $('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
398 $('#edithead, #savebtn', editRow).show();
399 $('#replyhead, #replybtn', editRow).hide();
403 if ( $.browser.msie )
404 $('#replycontainer, #replycontent', editRow).height(h-105);
406 $('#replycontainer', editRow).height(h-105);
408 c.after( editRow ).fadeOut('fast', function(){
409 $('#replyrow').fadeIn(300, function(){ $(this).show() });
412 replyButton = $('#replybtn', editRow);
413 $('#edithead, #savebtn', editRow).hide();
414 $('#replyhead, #replybtn', editRow).show();
417 if ( c.hasClass('unapproved') ) {
418 replyButton.text(adminCommentsL10n.replyApprove);
420 replyButton.text(adminCommentsL10n.reply);
423 $('#replyrow').fadeIn(300, function(){ $(this).show() });
426 setTimeout(function() {
427 var rtop, rbottom, scrollTop, vp, scrollBottom;
429 rtop = $('#replyrow').offset().top;
430 rbottom = rtop + $('#replyrow').height();
431 scrollTop = window.pageYOffset || document.documentElement.scrollTop;
432 vp = document.documentElement.clientHeight || self.innerHeight || 0;
433 scrollBottom = scrollTop + vp;
435 if ( scrollBottom - 20 < rbottom )
436 window.scroll(0, rbottom - vp + 35);
437 else if ( rtop - 20 < scrollTop )
438 window.scroll(0, rtop - 35);
440 $('#replycontent').focus().keyup(function(e){
442 commentReply.revert(); // close on Escape
452 $('#replysubmit .error').hide();
453 $('#replysubmit .waiting').show();
455 $('#replyrow input').not(':button').each(function() {
456 post[ $(this).attr('name') ] = $(this).val();
459 post.content = $('#replycontent').val();
460 post.id = post.comment_post_ID;
461 post.comments_listing = this.comments_listing;
462 post.p = $('[name="p"]').val();
464 if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') )
465 post.approve_parent = 1;
471 success : function(x) { commentReply.show(x); },
472 error : function(r) { commentReply.error(r); }
478 show : function(xml) {
479 var t = this, r, c, id, bg, pid;
483 if ( typeof(xml) == 'string' ) {
484 t.error({'responseText': xml});
488 r = wpAjax.parseAjaxResponse(xml);
490 t.error({'responseText': wpAjax.broken});
496 id = '#comment-' + r.id;
497 if ( 'edit-comment' == t.act )
500 if ( r.supplemental.parent_approved ) {
501 pid = $('#comment-' + r.supplemental.parent_approved);
502 updatePending( getCount( $('span.pending-count').eq(0) ) - 1 );
504 if ( this.comments_listing == 'moderated' ) {
505 pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){
513 $('#replyrow').after(c);
516 bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat').css('backgroundColor');
518 id.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
519 .animate( { 'backgroundColor': bg }, 300, function() {
520 if ( pid && pid.length ) {
521 pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
522 .animate( { 'backgroundColor': bg }, 300 )
523 .removeClass('unapproved').addClass('approved')
524 .find('div.comment_status').html('1');
530 error : function(r) {
531 var er = r.statusText;
533 $('#replysubmit .waiting').hide();
535 if ( r.responseText )
536 er = r.responseText.replace( /<.[^<>]*?>/g, '' );
539 $('#replysubmit .error').html(er).show();
544 $(document).ready(function(){
545 var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
549 $(document).delegate('span.delete a.delete', 'click', function(){return false;});
551 if ( typeof QTags != 'undefined' )
552 ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more,fullscreen');
554 if ( typeof $.table_hotkeys != 'undefined' ) {
555 make_hotkeys_redirect = function(which) {
559 first_last = 'next' == which? 'first' : 'last';
560 l = $('.tablenav-pages .'+which+'-page:not(.disabled)');
562 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
566 edit_comment = function(event, current_row) {
567 window.location = $('span.edit a', current_row).attr('href');
570 toggle_all = function() {
571 toggleWithKeyboard = true;
572 $('input:checkbox', '#cb').click().prop('checked', false);
573 toggleWithKeyboard = false;
576 make_bulk = function(value) {
578 var scope = $('select[name="action"]');
579 $('option[value="' + value + '"]', scope).prop('selected', true);
580 $('#doaction').click();
586 ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all],
587 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')],
588 ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')],
589 ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]],
590 { highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
591 prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') }