1 var theList, theExtraList, toggleWithKeyboard = false;
4 var getCount, updateCount, updatePending, dashboardTotals;
6 setCommentsList = function() {
7 var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList;
9 totalInput = $('input[name="_total"]', '#comments-form');
10 perPageInput = $('input[name="_per_page"]', '#comments-form');
11 pageInput = $('input[name="_page"]', '#comments-form');
13 dimAfter = function( r, settings ) {
14 var c = $('#' + settings.element), editRow, replyID, replyButton;
16 editRow = $('#replyrow');
17 replyID = $('#comment_ID', editRow).val();
18 replyButton = $('#replybtn', editRow);
20 if ( c.is('.unapproved') ) {
21 if ( settings.data.id == replyID )
22 replyButton.text(adminCommentsL10n.replyApprove);
24 c.find('div.comment_status').html('0');
26 if ( settings.data.id == replyID )
27 replyButton.text(adminCommentsL10n.reply);
29 c.find('div.comment_status').html('1');
32 var diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
33 updatePending( diff );
36 // Send current total, page, per_page and url
37 delBefore = function( settings, list ) {
38 var cl = $(settings.target).attr('class'), id, el, n, h, a, author, action = false;
40 settings.data._total = totalInput.val() || 0;
41 settings.data._per_page = perPageInput.val() || 0;
42 settings.data._page = pageInput.val() || 0;
43 settings.data._url = document.location.href;
44 settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val();
46 if ( cl.indexOf(':trash=1') != -1 )
48 else if ( cl.indexOf(':spam=1') != -1 )
52 id = cl.replace(/.*?comment-([0-9]+).*/, '$1');
53 el = $('#comment-' + id);
54 note = $('#' + action + '-undo-holder').html();
56 el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits.
58 if ( el.siblings('#replyrow').length && commentReply.cid == id )
62 n = el.children(':visible').length;
63 author = $('.author strong', el).text();
64 h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
66 author = $('.comment-author', el).text();
67 h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
72 $('strong', '#undo-' + id).text(author);
73 a = $('.undo a', '#undo-' + id);
74 a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
75 a.attr('class', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1 vim-z vim-destructive');
76 $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
79 list.wpList.del(this);
80 $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
82 $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() });
91 // Updates the current total (stored in the _total input)
92 updateTotalCount = function( total, time, setConfidentTime ) {
93 if ( time < lastConfidentTime )
96 if ( setConfidentTime )
97 lastConfidentTime = time;
99 totalInput.val( total.toString() );
102 dashboardTotals = function(n) {
103 var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
106 if ( isNaN(n) || !dash.length )
109 total = $('span.total-count', dash);
110 appr = $('span.approved-count', dash);
111 totalN = getCount(total);
114 apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) );
115 updateCount(total, totalN);
116 updateCount(appr, apprN);
119 getCount = function(el) {
120 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
126 updateCount = function(el, n) {
130 n = n < 1 ? '0' : n.toString();
131 if ( n.length > 3 ) {
132 while ( n.length > 3 ) {
133 n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
134 n = n.substr(0, n.length - 3);
141 updatePending = function( diff ) {
142 $('span.pending-count').each(function() {
143 var a = $(this), n = getCount(a) + diff;
146 a.closest('.awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
153 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
154 delAfter = function( r, settings ) {
155 var total, N, spam, trash, pending,
156 untrash = $(settings.target).parent().is('span.untrash'),
157 unspam = $(settings.target).parent().is('span.unspam'),
158 unapproved = $('#' + settings.element).is('.unapproved');
160 function getUpdate(s) {
161 if ( $(settings.target).parent().is('span.' + s) )
163 else if ( $('#' + settings.element).is('.' + s) )
172 trash = getUpdate('trash');
177 spam = getUpdate('spam');
179 if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) {
180 // a comment was 'deleted' from another list (e.g. approved, spam, trash) and moved to pending,
181 // or a trash/spam of a pending comment was undone
183 } else if ( unapproved ) {
184 // a pending comment was trashed/spammed/approved
189 updatePending(pending);
191 $('span.spam-count').each( function() {
192 var a = $(this), n = getCount(a) + spam;
196 $('span.trash-count').each( function() {
197 var a = $(this), n = getCount(a) + trash;
201 if ( $('#dashboard_right_now').length ) {
202 N = trash ? -1 * trash : 0;
205 total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
206 if ( $(settings.target).parent().is('span.undo') )
214 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
215 total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
216 if ( total_items_i18n ) {
217 $('.displaying-num').text( total_items_i18n );
218 $('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
219 $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
221 updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
223 updateTotalCount( total, r, false );
227 if ( ! theExtraList || theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash || unspam ) {
231 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
233 refillTheExtraList();
236 refillTheExtraList = function(ev) {
237 var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val();
242 if (args.paged > total_pages) {
247 theExtraList.empty();
248 args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php
251 args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list
254 args.no_placeholder = true;
258 // $.query.get() needs some correction to be sent into an ajax request
259 if ( true === args.comment_type )
260 args.comment_type = '';
262 args = $.extend(args, {
263 'action': 'fetch-list',
264 'list_args': list_args,
265 '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val()
273 success: function(response) {
274 theExtraList.get(0).wpList.add( response.rows );
279 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
280 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
281 .bind('wpListDelEnd', function(e, s){
282 var id = s.element.replace(/[^0-9]+/g, '');
284 if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 )
285 $('#undo-' + id).fadeIn(300, function(){ $(this).show() });
294 var row = $('#replyrow');
296 $('a.cancel', row).click(function() { return commentReply.revert(); });
297 $('a.save', row).click(function() { return commentReply.send(); });
298 $('input#author, input#author-email, input#author-url', row).keypress(function(e){
299 if ( e.which == 13 ) {
307 $('#the-comment-list .column-comment > p').dblclick(function(){
308 commentReply.toggle($(this).parent());
311 $('#doaction, #doaction2, #post-query-submit').click(function(e){
312 if ( $('#the-comment-list #replyrow').length > 0 )
313 commentReply.close();
316 this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
318 /* $(listTable).bind('beforeChangePage', function(){
319 commentReply.close();
323 addEvents : function(r) {
325 $(this).find('.column-comment > p').dblclick(function(){
326 commentReply.toggle($(this).parent());
331 toggle : function(el) {
332 if ( $(el).css('display') != 'none' )
333 $(el).find('a.vim-q').click();
336 revert : function() {
338 if ( $('#the-comment-list #replyrow').length < 1 )
341 $('#replyrow').fadeOut('fast', function(){
342 commentReply.close();
349 var c, replyrow = $('#replyrow');
351 // replyrow is not showing?
352 if ( replyrow.parent().is('#com-reply') )
355 if ( this.cid && this.act == 'edit-comment' ) {
356 c = $('#comment-' + this.cid);
357 c.fadeIn(300, function(){ c.show() }).css('backgroundColor', '');
360 // reset the Quicktags buttons
361 if ( typeof QTags != 'undefined' )
362 QTags.closeAllTags('replycontent');
364 $('#add-new-comment').css('display', '');
367 $('#com-reply').append( replyrow );
368 $('#replycontent').css('height', '').val('');
369 $('#edithead input').val('');
370 $('.error', replyrow).html('').hide();
371 $('.waiting', replyrow).hide();
376 open : function(comment_id, post_id, action) {
377 var t = this, editRow, rowData, act, c = $('#comment-' + comment_id), h = c.height(), replyButton;
382 editRow = $('#replyrow');
383 rowData = $('#inline-'+comment_id);
384 action = action || 'replyto';
385 act = 'edit' == action ? 'edit' : 'replyto';
386 act = t.act = act + '-comment';
388 $('#action', editRow).val(act);
389 $('#comment_post_ID', editRow).val(post_id);
390 $('#comment_ID', editRow).val(comment_id);
393 $('#replycontent', editRow).css('height', (35+h) + 'px');
395 if ( action == 'edit' ) {
396 $('#author', editRow).val( $('div.author', rowData).text() );
397 $('#author-email', editRow).val( $('div.author-email', rowData).text() );
398 $('#author-url', editRow).val( $('div.author-url', rowData).text() );
399 $('#status', editRow).val( $('div.comment_status', rowData).text() );
400 $('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
401 $('#edithead, #savebtn', editRow).show();
402 $('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide();
404 c.after( editRow ).fadeOut('fast', function(){
405 $('#replyrow').fadeIn(300, function(){ $(this).show() });
407 } else if ( action == 'add' ) {
408 $('#addhead, #addbtn', editRow).show();
409 $('#replyhead, #replybtn, #edithead, #editbtn', editRow).hide();
410 $('#the-comment-list').prepend(editRow);
411 $('#replyrow').fadeIn(300);
413 replyButton = $('#replybtn', editRow);
414 $('#edithead, #savebtn, #addhead, #addbtn', editRow).hide();
415 $('#replyhead, #replybtn', editRow).show();
418 if ( c.hasClass('unapproved') ) {
419 replyButton.text(adminCommentsL10n.replyApprove);
421 replyButton.text(adminCommentsL10n.reply);
424 $('#replyrow').fadeIn(300, function(){ $(this).show() });
427 setTimeout(function() {
428 var rtop, rbottom, scrollTop, vp, scrollBottom;
430 rtop = $('#replyrow').offset().top;
431 rbottom = rtop + $('#replyrow').height();
432 scrollTop = window.pageYOffset || document.documentElement.scrollTop;
433 vp = document.documentElement.clientHeight || self.innerHeight || 0;
434 scrollBottom = scrollTop + vp;
436 if ( scrollBottom - 20 < rbottom )
437 window.scroll(0, rbottom - vp + 35);
438 else if ( rtop - 20 < scrollTop )
439 window.scroll(0, rtop - 35);
441 $('#replycontent').focus().keyup(function(e){
443 commentReply.revert(); // close on Escape
453 $('#replysubmit .error').hide();
454 $('#replysubmit .waiting').show();
456 $('#replyrow input').not(':button').each(function() {
458 post[ t.attr('name') ] = t.val();
461 post.content = $('#replycontent').val();
462 post.id = post.comment_post_ID;
463 post.comments_listing = this.comments_listing;
464 post.p = $('[name="p"]').val();
466 if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') )
467 post.approve_parent = 1;
473 success : function(x) { commentReply.show(x); },
474 error : function(r) { commentReply.error(r); }
480 show : function(xml) {
481 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});
498 id = '#comment-' + r.id;
500 if ( 'edit-comment' == t.act )
503 if ( r.supplemental.parent_approved ) {
504 pid = $('#comment-' + r.supplemental.parent_approved);
507 if ( this.comments_listing == 'moderated' ) {
508 pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){
516 $('#replyrow').after(c);
519 bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor');
521 id.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
522 .animate( { 'backgroundColor': bg }, 300, function() {
523 if ( pid && pid.length ) {
524 pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
525 .animate( { 'backgroundColor': bg }, 300 )
526 .removeClass('unapproved').addClass('approved')
527 .find('div.comment_status').html('1');
533 error : function(r) {
534 var er = r.statusText;
536 $('#replysubmit .waiting').hide();
538 if ( r.responseText )
539 er = r.responseText.replace( /<.[^<>]*?>/g, '' );
542 $('#replysubmit .error').html(er).show();
546 addcomment: function(post_id) {
549 $('#add-new-comment').fadeOut(200, function(){
550 t.open(0, post_id, 'add');
551 $('table.comments-box').css('display', '');
552 $('#no-comments').remove();
557 $(document).ready(function(){
558 var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
562 $(document).delegate('span.delete a.delete', 'click', function(){return false;});
564 if ( typeof $.table_hotkeys != 'undefined' ) {
565 make_hotkeys_redirect = function(which) {
569 first_last = 'next' == which? 'first' : 'last';
570 l = $('.tablenav-pages .'+which+'-page:not(.disabled)');
572 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
576 edit_comment = function(event, current_row) {
577 window.location = $('span.edit a', current_row).attr('href');
580 toggle_all = function() {
581 toggleWithKeyboard = true;
582 $('input:checkbox', '#cb').click().prop('checked', false);
583 toggleWithKeyboard = false;
586 make_bulk = function(value) {
588 var scope = $('select[name="action"]');
589 $('option[value="' + value + '"]', scope).prop('selected', true);
590 $('#doaction').click();
596 ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all],
597 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')],
598 ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')],
599 ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]],
600 { highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
601 prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') }