1 var theList, theExtraList, toggleWithKeyboard = false;
4 setCommentsList = function() {
5 var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter;
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);
14 if ( c.is('.unapproved') )
15 c.find('div.comment_status').html('0')
17 c.find('div.comment_status').html('1')
19 $('span.pending-count').each( function() {
20 var a = $(this), n, dif;
21 n = a.html().replace(/[^0-9]+/g, '');
23 if ( isNaN(n) ) return;
24 dif = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
26 if ( n < 0 ) { n = 0; }
27 a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
33 // Send current total, page, per_page and url
34 delBefore = function( settings, list ) {
35 var cl = $(settings.target).attr('className'), id, el, n, h, a, author, action = false;
37 settings.data._total = totalInput.val() || 0;
38 settings.data._per_page = perPageInput.val() || 0;
39 settings.data._page = pageInput.val() || 0;
40 settings.data._url = document.location.href;
41 settings.data.comment_status = $('input[name=comment_status]', '#comments-form').val();
43 if ( cl.indexOf(':trash=1') != -1 )
45 else if ( cl.indexOf(':spam=1') != -1 )
49 id = cl.replace(/.*?comment-([0-9]+).*/, '$1');
50 el = $('#comment-' + id);
51 note = $('#' + action + '-undo-holder').html();
53 el.find('.check-column :checkbox').attr('checked', ''); // Uncheck the row so as not to be affected by Bulk Edits.
55 if ( el.siblings('#replyrow').length && commentReply.cid == id )
59 n = el.children(':visible').length;
60 author = $('.author strong', el).text();
61 h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
63 author = $('.comment-author', el).text();
64 h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
69 $('strong', '#undo-' + id).text(author + ' ');
70 a = $('.undo a', '#undo-' + id);
71 a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
72 a.attr('className', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1 vim-z vim-destructive');
73 $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
76 list.wpList.del(this);
77 $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
79 $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() });
88 // Updates the current total (as displayed visibly)
89 updateTotalCount = function( total, time, setConfidentTime ) {
90 if ( time < lastConfidentTime )
93 if ( setConfidentTime )
94 lastConfidentTime = time;
96 totalInput.val( total.toString() );
97 $('span.total-type-count').each( function() {
98 updateCount( $(this), total );
102 function dashboardTotals(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);
120 function getCount(el) {
121 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
127 function updateCount(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 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
143 delAfter = function( r, settings ) {
144 var total, pageLinks, N, untrash = $(settings.target).parent().is('span.untrash'), unspam = $(settings.target).parent().is('span.unspam'), spam, trash;
146 function getUpdate(s) {
147 if ( $(settings.target).parent().is('span.' + s) )
149 else if ( $('#' + settings.element).is('.' + s) )
154 spam = getUpdate('spam');
155 trash = getUpdate('trash');
162 $('span.pending-count').each( function() {
163 var a = $(this), n = getCount(a), unapproved = $('#' + settings.element).is('.unapproved');
165 if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
167 } else if ( unapproved ) { // we deleted a formerly unapproved comment
170 if ( n < 0 ) { n = 0; }
171 a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
176 $('span.spam-count').each( function() {
177 var a = $(this), n = getCount(a) + spam;
181 $('span.trash-count').each( function() {
182 var a = $(this), n = getCount(a) + trash;
186 if ( $('#dashboard_right_now').length ) {
187 N = trash ? -1 * trash : 0;
190 total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
191 total = total - spam - trash;
195 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
196 total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
197 if ( total_items_i18n ) {
198 $('.displaying-num').text( total_items_i18n );
199 $('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
200 $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
202 updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
204 updateTotalCount( total, r, false );
209 if ( ! theExtraList || theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash || unspam ) {
213 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
215 refillTheExtraList();
218 var refillTheExtraList = function(ev) {
219 // var args = $.query.get(), total_pages = listTable.get_total_pages(), per_page = $('input[name=_per_page]', '#comments-form').val(), r;
220 var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name=_per_page]', '#comments-form').val(), r;
225 if (args.paged > total_pages) {
230 theExtraList.empty();
231 args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php
234 args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list
237 args.no_placeholder = true;
241 // $.query.get() needs some correction to be sent into an ajax request
242 if ( true === args.comment_type )
243 args.comment_type = '';
245 args = $.extend(args, {
246 'action': 'fetch-list',
247 'list_args': list_args,
248 '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val()
256 success: function(response) {
257 theExtraList.get(0).wpList.add( response.rows );
262 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
263 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
264 .bind('wpListDelEnd', function(e, s){
265 var id = s.element.replace(/[^0-9]+/g, '');
267 if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 )
268 $('#undo-' + id).fadeIn(300, function(){ $(this).show() });
270 // $(listTable).bind('changePage', refillTheExtraList);
278 var row = $('#replyrow');
280 $('a.cancel', row).click(function() { return commentReply.revert(); });
281 $('a.save', row).click(function() { return commentReply.send(); });
282 $('input#author, input#author-email, input#author-url', row).keypress(function(e){
283 if ( e.which == 13 ) {
291 $('#the-comment-list .column-comment > p').dblclick(function(){
292 commentReply.toggle($(this).parent());
295 $('#doaction, #doaction2, #post-query-submit').click(function(e){
296 if ( $('#the-comment-list #replyrow').length > 0 )
297 commentReply.close();
300 this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
302 /* $(listTable).bind('beforeChangePage', function(){
303 commentReply.close();
307 addEvents : function(r) {
309 $(this).find('.column-comment > p').dblclick(function(){
310 commentReply.toggle($(this).parent());
315 toggle : function(el) {
316 if ( $(el).css('display') != 'none' )
317 $(el).find('a.vim-q').click();
320 revert : function() {
322 if ( $('#the-comment-list #replyrow').length < 1 )
325 $('#replyrow').fadeOut('fast', function(){
326 commentReply.close();
336 c = $('#comment-' + this.cid);
338 if ( this.act == 'edit-comment' )
339 c.fadeIn(300, function(){ c.show() }).css('backgroundColor', '');
341 $('#replyrow').hide();
342 $('#com-reply').append( $('#replyrow') );
343 $('#replycontent').val('');
344 $('input', '#edithead').val('');
345 $('.error', '#replysubmit').html('').hide();
346 $('.waiting', '#replysubmit').hide();
348 if ( $.browser.msie )
349 $('#replycontainer, #replycontent').css('height', '120px');
351 $('#replycontainer').resizable('destroy').css('height', '120px');
357 open : function(id, p, a) {
358 var t = this, editRow, rowData, act, h, c = $('#comment-' + id);
362 editRow = $('#replyrow');
363 rowData = $('#inline-'+id);
364 act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment';
366 $('#action', editRow).val(act);
367 $('#comment_post_ID', editRow).val(p);
368 $('#comment_ID', editRow).val(id);
371 $('#author', editRow).val( $('div.author', rowData).text() );
372 $('#author-email', editRow).val( $('div.author-email', rowData).text() );
373 $('#author-url', editRow).val( $('div.author-url', rowData).text() );
374 $('#status', editRow).val( $('div.comment_status', rowData).text() );
375 $('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
376 $('#edithead, #savebtn', editRow).show();
377 $('#replyhead, #replybtn', editRow).hide();
381 if ( $.browser.msie )
382 $('#replycontainer, #replycontent', editRow).height(h-105);
384 $('#replycontainer', editRow).height(h-105);
386 c.after( editRow ).fadeOut('fast', function(){
387 $('#replyrow').fadeIn(300, function(){ $(this).show() });
390 $('#edithead, #savebtn', editRow).hide();
391 $('#replyhead, #replybtn', editRow).show();
393 $('#replyrow').fadeIn(300, function(){ $(this).show() });
396 if ( ! $.browser.msie )
397 $('#replycontainer').resizable({
402 $('#replycontainer').width('auto');
406 setTimeout(function() {
407 var rtop, rbottom, scrollTop, vp, scrollBottom;
409 rtop = $('#replyrow').offset().top;
410 rbottom = rtop + $('#replyrow').height();
411 scrollTop = window.pageYOffset || document.documentElement.scrollTop;
412 vp = document.documentElement.clientHeight || self.innerHeight || 0;
413 scrollBottom = scrollTop + vp;
415 if ( scrollBottom - 20 < rbottom )
416 window.scroll(0, rbottom - vp + 35);
417 else if ( rtop - 20 < scrollTop )
418 window.scroll(0, rtop - 35);
420 $('#replycontent').focus().keyup(function(e){
422 commentReply.revert(); // close on Escape
432 $('#replysubmit .error').hide();
433 $('#replysubmit .waiting').show();
435 $('#replyrow input').each(function() {
436 post[ $(this).attr('name') ] = $(this).val();
439 post.content = $('#replycontent').val();
440 post.id = post.comment_post_ID;
441 post.comments_listing = this.comments_listing;
442 post.p = $('[name=p]').val();
448 success : function(x) { commentReply.show(x); },
449 error : function(r) { commentReply.error(r); }
455 show : function(xml) {
458 if ( typeof(xml) == 'string' ) {
459 this.error({'responseText': xml});
463 r = wpAjax.parseAjaxResponse(xml);
465 this.error({'responseText': wpAjax.broken});
471 id = '#comment-' + r.id;
472 if ( 'edit-comment' == this.act )
476 $('#replyrow').after(c);
479 this.addEvents($(id));
480 bg = $(id).hasClass('unapproved') ? '#ffffe0' : '#fff';
483 .animate( { 'backgroundColor':'#CCEEBB' }, 600 )
484 .animate( { 'backgroundColor': bg }, 600 );
486 // $.fn.wpList.process($(id));
489 error : function(r) {
490 var er = r.statusText;
492 $('#replysubmit .waiting').hide();
494 if ( r.responseText )
495 er = r.responseText.replace( /<.[^<>]*?>/g, '' );
498 $('#replysubmit .error').html(er).show();
503 $(document).ready(function(){
504 var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
508 $(document).delegate('span.delete a.delete', 'click', function(){return false;});
510 if ( typeof QTags != 'undefined' )
511 ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more');
513 if ( typeof $.table_hotkeys != 'undefined' ) {
514 make_hotkeys_redirect = function(which) {
518 first_last = 'next' == which? 'first' : 'last';
519 l = $('.tablenav-pages .'+which+'-page:not(.disabled)');
521 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
525 edit_comment = function(event, current_row) {
526 window.location = $('span.edit a', current_row).attr('href');
529 toggle_all = function() {
530 toggleWithKeyboard = true;
531 $('input:checkbox', '#cb').click().attr('checked', '');
532 toggleWithKeyboard = false;
535 make_bulk = function(value) {
537 var scope = $('select[name="action"]');
538 $('option[value='+value+']', scope).attr('selected', 'selected');
539 $('#doaction').click();
545 ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all],
546 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')],
547 ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')],
548 ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]],
549 { highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
550 prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') }