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 wpListsData = $(settings.target).attr('data-wp-lists'), 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 ( wpListsData.indexOf(':trash=1') != -1 )
48 else if ( wpListsData.indexOf(':spam=1') != -1 )
52 id = wpListsData.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('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1');
76 a.attr('class', 'vim-z vim-destructive');
77 $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
80 list.wpList.del(this);
81 $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
83 $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() });
92 // Updates the current total (stored in the _total input)
93 updateTotalCount = function( total, time, setConfidentTime ) {
94 if ( time < lastConfidentTime )
97 if ( setConfidentTime )
98 lastConfidentTime = time;
100 totalInput.val( total.toString() );
103 dashboardTotals = function(n) {
104 var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
107 if ( isNaN(n) || !dash.length )
110 total = $('span.total-count', dash);
111 appr = $('span.approved-count', dash);
112 totalN = getCount(total);
115 apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) );
116 updateCount(total, totalN);
117 updateCount(appr, apprN);
120 getCount = function(el) {
121 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
127 updateCount = function(el, n) {
131 n = n < 1 ? '0' : n.toString();
132 if ( n.length > 3 ) {
133 while ( n.length > 3 ) {
134 n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
135 n = n.substr(0, n.length - 3);
142 updatePending = function( 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');
154 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
155 delAfter = function( r, settings ) {
156 var total, N, spam, trash, pending,
157 untrash = $(settings.target).parent().is('span.untrash'),
158 unspam = $(settings.target).parent().is('span.unspam'),
159 unapproved = $('#' + settings.element).is('.unapproved');
161 function getUpdate(s) {
162 if ( $(settings.target).parent().is('span.' + s) )
164 else if ( $('#' + settings.element).is('.' + s) )
173 trash = getUpdate('trash');
178 spam = getUpdate('spam');
180 if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) {
181 // a comment was 'deleted' from another list (e.g. approved, spam, trash) and moved to pending,
182 // or a trash/spam of a pending comment was undone
184 } else if ( unapproved ) {
185 // a pending comment was trashed/spammed/approved
190 updatePending(pending);
192 $('span.spam-count').each( function() {
193 var a = $(this), n = getCount(a) + spam;
197 $('span.trash-count').each( function() {
198 var a = $(this), n = getCount(a) + trash;
202 if ( $('#dashboard_right_now').length ) {
203 N = trash ? -1 * trash : 0;
206 total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
207 if ( $(settings.target).parent().is('span.undo') )
215 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
216 total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
217 if ( total_items_i18n ) {
218 $('.displaying-num').text( total_items_i18n );
219 $('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
220 $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
222 updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
224 updateTotalCount( total, r, false );
228 if ( ! theExtraList || theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash || unspam ) {
232 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
234 refillTheExtraList();
237 refillTheExtraList = function(ev) {
238 var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val();
243 if (args.paged > total_pages) {
248 theExtraList.empty();
249 args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php
252 args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list
255 args.no_placeholder = true;
259 // $.query.get() needs some correction to be sent into an ajax request
260 if ( true === args.comment_type )
261 args.comment_type = '';
263 args = $.extend(args, {
264 'action': 'fetch-list',
265 'list_args': list_args,
266 '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val()
274 success: function(response) {
275 theExtraList.get(0).wpList.add( response.rows );
280 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
281 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
282 .bind('wpListDelEnd', function(e, s){
283 var wpListsData = $(s.target).attr('data-wp-lists'), id = s.element.replace(/[^0-9]+/g, '');
285 if ( wpListsData.indexOf(':trash=1') != -1 || wpListsData.indexOf(':spam=1') != -1 )
286 $('#undo-' + id).fadeIn(300, function(){ $(this).show() });
295 var row = $('#replyrow');
297 $('a.cancel', row).click(function() { return commentReply.revert(); });
298 $('a.save', row).click(function() { return commentReply.send(); });
299 $('input#author, input#author-email, input#author-url', row).keypress(function(e){
300 if ( e.which == 13 ) {
308 $('#the-comment-list .column-comment > p').dblclick(function(){
309 commentReply.toggle($(this).parent());
312 $('#doaction, #doaction2, #post-query-submit').click(function(e){
313 if ( $('#the-comment-list #replyrow').length > 0 )
314 commentReply.close();
317 this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
319 /* $(listTable).bind('beforeChangePage', function(){
320 commentReply.close();
324 addEvents : function(r) {
326 $(this).find('.column-comment > p').dblclick(function(){
327 commentReply.toggle($(this).parent());
332 toggle : function(el) {
333 if ( $(el).css('display') != 'none' )
334 $(el).find('a.vim-q').click();
337 revert : function() {
339 if ( $('#the-comment-list #replyrow').length < 1 )
342 $('#replyrow').fadeOut('fast', function(){
343 commentReply.close();
350 var c, replyrow = $('#replyrow');
352 // replyrow is not showing?
353 if ( replyrow.parent().is('#com-reply') )
356 if ( this.cid && this.act == 'edit-comment' ) {
357 c = $('#comment-' + this.cid);
358 c.fadeIn(300, function(){ c.show() }).css('backgroundColor', '');
361 // reset the Quicktags buttons
362 if ( typeof QTags != 'undefined' )
363 QTags.closeAllTags('replycontent');
365 $('#add-new-comment').css('display', '');
368 $('#com-reply').append( replyrow );
369 $('#replycontent').css('height', '').val('');
370 $('#edithead input').val('');
371 $('.error', replyrow).html('').hide();
372 $('.spinner', replyrow).hide();
377 open : function(comment_id, post_id, action) {
378 var t = this, editRow, rowData, act, c = $('#comment-' + comment_id), h = c.height(), replyButton;
383 editRow = $('#replyrow');
384 rowData = $('#inline-'+comment_id);
385 action = action || 'replyto';
386 act = 'edit' == action ? 'edit' : 'replyto';
387 act = t.act = act + '-comment';
389 $('#action', editRow).val(act);
390 $('#comment_post_ID', editRow).val(post_id);
391 $('#comment_ID', editRow).val(comment_id);
394 $('#replycontent', editRow).css('height', (35+h) + 'px');
396 if ( action == 'edit' ) {
397 $('#author', editRow).val( $('div.author', rowData).text() );
398 $('#author-email', editRow).val( $('div.author-email', rowData).text() );
399 $('#author-url', editRow).val( $('div.author-url', rowData).text() );
400 $('#status', editRow).val( $('div.comment_status', rowData).text() );
401 $('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
402 $('#edithead, #savebtn', editRow).show();
403 $('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide();
405 c.after( editRow ).fadeOut('fast', function(){
406 $('#replyrow').fadeIn(300, function(){ $(this).show() });
408 } else if ( action == 'add' ) {
409 $('#addhead, #addbtn', editRow).show();
410 $('#replyhead, #replybtn, #edithead, #editbtn', editRow).hide();
411 $('#the-comment-list').prepend(editRow);
412 $('#replyrow').fadeIn(300);
414 replyButton = $('#replybtn', editRow);
415 $('#edithead, #savebtn, #addhead, #addbtn', editRow).hide();
416 $('#replyhead, #replybtn', editRow).show();
419 if ( c.hasClass('unapproved') ) {
420 replyButton.text(adminCommentsL10n.replyApprove);
422 replyButton.text(adminCommentsL10n.reply);
425 $('#replyrow').fadeIn(300, function(){ $(this).show() });
428 setTimeout(function() {
429 var rtop, rbottom, scrollTop, vp, scrollBottom;
431 rtop = $('#replyrow').offset().top;
432 rbottom = rtop + $('#replyrow').height();
433 scrollTop = window.pageYOffset || document.documentElement.scrollTop;
434 vp = document.documentElement.clientHeight || self.innerHeight || 0;
435 scrollBottom = scrollTop + vp;
437 if ( scrollBottom - 20 < rbottom )
438 window.scroll(0, rbottom - vp + 35);
439 else if ( rtop - 20 < scrollTop )
440 window.scroll(0, rtop - 35);
442 $('#replycontent').focus().keyup(function(e){
444 commentReply.revert(); // close on Escape
454 $('#replysubmit .error').hide();
455 $('#replysubmit .spinner').show();
457 $('#replyrow input').not(':button').each(function() {
459 post[ t.attr('name') ] = t.val();
462 post.content = $('#replycontent').val();
463 post.id = post.comment_post_ID;
464 post.comments_listing = this.comments_listing;
465 post.p = $('[name="p"]').val();
467 if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') )
468 post.approve_parent = 1;
474 success : function(x) { commentReply.show(x); },
475 error : function(r) { commentReply.error(r); }
481 show : function(xml) {
482 var t = this, r, c, id, bg, pid;
484 if ( typeof(xml) == 'string' ) {
485 t.error({'responseText': xml});
489 r = wpAjax.parseAjaxResponse(xml);
491 t.error({'responseText': wpAjax.broken});
499 id = '#comment-' + r.id;
501 if ( 'edit-comment' == t.act )
504 if ( r.supplemental.parent_approved ) {
505 pid = $('#comment-' + r.supplemental.parent_approved);
508 if ( this.comments_listing == 'moderated' ) {
509 pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){
517 $('#replyrow').after(c);
520 bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor');
522 id.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
523 .animate( { 'backgroundColor': bg }, 300, function() {
524 if ( pid && pid.length ) {
525 pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
526 .animate( { 'backgroundColor': bg }, 300 )
527 .removeClass('unapproved').addClass('approved')
528 .find('div.comment_status').html('1');
534 error : function(r) {
535 var er = r.statusText;
537 $('#replysubmit .spinner').hide();
539 if ( r.responseText )
540 er = r.responseText.replace( /<.[^<>]*?>/g, '' );
543 $('#replysubmit .error').html(er).show();
547 addcomment: function(post_id) {
550 $('#add-new-comment').fadeOut(200, function(){
551 t.open(0, post_id, 'add');
552 $('table.comments-box').css('display', '');
553 $('#no-comments').remove();
558 $(document).ready(function(){
559 var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
563 $(document).delegate('span.delete a.delete', 'click', function(){return false;});
565 if ( typeof $.table_hotkeys != 'undefined' ) {
566 make_hotkeys_redirect = function(which) {
570 first_last = 'next' == which? 'first' : 'last';
571 l = $('.tablenav-pages .'+which+'-page:not(.disabled)');
573 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
577 edit_comment = function(event, current_row) {
578 window.location = $('span.edit a', current_row).attr('href');
581 toggle_all = function() {
582 toggleWithKeyboard = true;
583 $('input:checkbox', '#cb').click().prop('checked', false);
584 toggleWithKeyboard = false;
587 make_bulk = function(value) {
589 var scope = $('select[name="action"]');
590 $('option[value="' + value + '"]', scope).prop('selected', true);
591 $('#doaction').click();
597 ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all],
598 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')],
599 ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')],
600 ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]],
601 { highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
602 prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') }