1 var theList, theExtraList, toggleWithKeyboard = false;
4 setCommentsList = function() {
5 var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter;
7 totalInput = $('.tablenav input[name="_total"]', '#comments-form');
8 perPageInput = $('.tablenav input[name="_per_page"]', '#comments-form');
9 pageInput = $('.tablenav 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;
42 if ( cl.indexOf(':trash=1') != -1 )
44 else if ( cl.indexOf(':spam=1') != -1 )
48 id = cl.replace(/.*?comment-([0-9]+).*/, '$1');
49 el = $('#comment-' + id);
50 note = $('#' + action + '-undo-holder').html();
52 el.find('.check-column :checkbox').attr('checked', ''); // Uncheck the row so as not to be affected by Bulk Edits.
54 if ( el.siblings('#replyrow').length && commentReply.cid == id )
58 n = el.children(':visible').length;
59 author = $('.author strong', el).text();
60 h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
62 author = $('.comment-author', el).text();
63 h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
68 $('strong', '#undo-' + id).text(author + ' ');
69 a = $('.undo a', '#undo-' + id);
70 a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
71 a.attr('className', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1 vim-z vim-destructive');
72 $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
75 list.wpList.del(this);
76 $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
78 $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() });
87 // Updates the current total (as displayed visibly)
88 updateTotalCount = function( total, time, setConfidentTime ) {
89 if ( time < lastConfidentTime )
92 if ( setConfidentTime )
93 lastConfidentTime = time;
95 totalInput.val( total.toString() );
96 $('span.total-type-count').each( function() {
97 updateCount( $(this), total );
101 function dashboardTotals(n) {
102 var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
105 if ( isNaN(n) || !dash.length )
108 total = $('span.total-count', dash);
109 appr = $('span.approved-count', dash);
110 totalN = getCount(total);
113 apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) );
114 updateCount(total, totalN);
115 updateCount(appr, apprN);
119 function getCount(el) {
120 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
126 function updateCount(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 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
142 delAfter = function( r, settings ) {
143 var total, pageLinks, N, untrash = $(settings.target).parent().is('span.untrash'), unspam = $(settings.target).parent().is('span.unspam'), spam, trash;
145 function getUpdate(s) {
146 if ( $(settings.target).parent().is('span.' + s) )
148 else if ( $('#' + settings.element).is('.' + s) )
153 spam = getUpdate('spam');
154 trash = getUpdate('trash');
161 $('span.pending-count').each( function() {
162 var a = $(this), n = getCount(a), unapproved = $('#' + settings.element).is('.unapproved');
164 if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
166 } else if ( unapproved ) { // we deleted a formerly unapproved comment
169 if ( n < 0 ) { n = 0; }
170 a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
175 $('span.spam-count').each( function() {
176 var a = $(this), n = getCount(a) + spam;
180 $('span.trash-count').each( function() {
181 var a = $(this), n = getCount(a) + trash;
185 if ( $('#dashboard_right_now').length ) {
186 N = trash ? -1 * trash : 0;
189 total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
190 total = total - spam - trash;
194 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
195 pageLinks = settings.parsed.responses[0].supplemental.pageLinks || '';
196 if ( $.trim( pageLinks ) )
197 $('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( pageLinks ) );
199 $('.tablenav-pages').find( '.page-numbers' ).remove();
201 updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
203 updateTotalCount( total, r, false );
207 if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash ) {
211 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
212 $('#get-extra-comments').submit();
215 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
216 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
217 .bind('wpListDelEnd', function(e, s){
218 var id = s.element.replace(/[^0-9]+/g, '');
220 if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 )
221 $('#undo-' + id).fadeIn(300, function(){ $(this).show() });
230 var row = $('#replyrow');
232 $('a.cancel', row).click(function() { return commentReply.revert(); });
233 $('a.save', row).click(function() { return commentReply.send(); });
234 $('input#author, input#author-email, input#author-url', row).keypress(function(e){
235 if ( e.which == 13 ) {
243 $('#the-comment-list .column-comment > p').dblclick(function(){
244 commentReply.toggle($(this).parent());
247 $('#doaction, #doaction2, #post-query-submit').click(function(e){
248 if ( $('#the-comment-list #replyrow').length > 0 )
249 commentReply.close();
252 this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
256 addEvents : function(r) {
258 $(this).find('.column-comment > p').dblclick(function(){
259 commentReply.toggle($(this).parent());
264 toggle : function(el) {
265 if ( $(el).css('display') != 'none' )
266 $(el).find('a.vim-q').click();
269 revert : function() {
271 if ( $('#the-comment-list #replyrow').length < 1 )
274 $('#replyrow').fadeOut('fast', function(){
275 commentReply.close();
285 c = $('#comment-' + this.cid);
287 if ( this.act == 'edit-comment' )
288 c.fadeIn(300, function(){ c.show() }).css('backgroundColor', '');
290 $('#replyrow').hide();
291 $('#com-reply').append( $('#replyrow') );
292 $('#replycontent').val('');
293 $('input', '#edithead').val('');
294 $('.error', '#replysubmit').html('').hide();
295 $('.waiting', '#replysubmit').hide();
297 if ( $.browser.msie )
298 $('#replycontainer, #replycontent').css('height', '120px');
300 $('#replycontainer').resizable('destroy').css('height', '120px');
306 open : function(id, p, a) {
307 var t = this, editRow, rowData, act, h, c = $('#comment-' + id);
311 $('td', '#replyrow').attr('colspan', $('table.widefat thead th:visible').length);
312 editRow = $('#replyrow');
313 rowData = $('#inline-'+id);
314 act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment';
316 $('#action', editRow).val(act);
317 $('#comment_post_ID', editRow).val(p);
318 $('#comment_ID', editRow).val(id);
321 $('#author', editRow).val( $('div.author', rowData).text() );
322 $('#author-email', editRow).val( $('div.author-email', rowData).text() );
323 $('#author-url', editRow).val( $('div.author-url', rowData).text() );
324 $('#status', editRow).val( $('div.comment_status', rowData).text() );
325 $('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
326 $('#edithead, #savebtn', editRow).show();
327 $('#replyhead, #replybtn', editRow).hide();
331 if ( $.browser.msie )
332 $('#replycontainer, #replycontent', editRow).height(h-105);
334 $('#replycontainer', editRow).height(h-105);
336 c.after( editRow ).fadeOut('fast', function(){
337 $('#replyrow').fadeIn(300, function(){ $(this).show() });
340 $('#edithead, #savebtn', editRow).hide();
341 $('#replyhead, #replybtn', editRow).show();
343 $('#replyrow').fadeIn(300, function(){ $(this).show() });
346 if ( ! $.browser.msie )
347 $('#replycontainer').resizable({
352 $('#replycontainer').width('auto');
356 setTimeout(function() {
357 var rtop, rbottom, scrollTop, vp, scrollBottom;
359 rtop = $('#replyrow').offset().top;
360 rbottom = rtop + $('#replyrow').height();
361 scrollTop = window.pageYOffset || document.documentElement.scrollTop;
362 vp = document.documentElement.clientHeight || self.innerHeight || 0;
363 scrollBottom = scrollTop + vp;
365 if ( scrollBottom - 20 < rbottom )
366 window.scroll(0, rbottom - vp + 35);
367 else if ( rtop - 20 < scrollTop )
368 window.scroll(0, rtop - 35);
370 $('#replycontent').focus().keyup(function(e){
372 commentReply.revert(); // close on Escape
382 $('#replysubmit .waiting').show();
384 $('#replyrow input').each(function() {
385 post[ $(this).attr('name') ] = $(this).val();
388 post.content = $('#replycontent').val();
389 post.id = post.comment_post_ID;
390 post.comments_listing = this.comments_listing;
396 success : function(x) { commentReply.show(x); },
397 error : function(r) { commentReply.error(r); }
403 show : function(xml) {
406 if ( typeof(xml) == 'string' ) {
407 this.error({'responseText': xml});
411 r = wpAjax.parseAjaxResponse(xml);
413 this.error({'responseText': wpAjax.broken});
419 id = '#comment-' + r.id;
420 if ( 'edit-comment' == this.act )
424 $('#replyrow').after(c);
427 this.addEvents($(id));
428 bg = $(id).hasClass('unapproved') ? '#ffffe0' : '#fff';
431 .animate( { 'backgroundColor':'#CCEEBB' }, 600 )
432 .animate( { 'backgroundColor': bg }, 600 );
434 $.fn.wpList.process($(id))
437 error : function(r) {
438 var er = r.statusText;
440 $('#replysubmit .waiting').hide();
442 if ( r.responseText )
443 er = r.responseText.replace( /<.[^<>]*?>/g, '' );
446 $('#replysubmit .error').html(er).show();
451 $(document).ready(function(){
452 var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
456 $('span.delete a.delete').click(function(){return false;});
458 if ( typeof QTags != 'undefined' )
459 ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more');
461 if ( typeof $.table_hotkeys != 'undefined' ) {
462 make_hotkeys_redirect = function(which) {
466 first_last = 'next' == which? 'first' : 'last';
467 l = $('.'+which+'.page-numbers');
469 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
473 edit_comment = function(event, current_row) {
474 window.location = $('span.edit a', current_row).attr('href');
477 toggle_all = function() {
478 toggleWithKeyboard = true;
479 $('input:checkbox', '#cb').click().attr('checked', '');
480 toggleWithKeyboard = false;
483 make_bulk = function(value) {
485 var scope = $('select[name="action"]');
486 $('option[value='+value+']', scope).attr('selected', 'selected');
487 $('#comments-form').submit();
493 ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all],
494 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')],
495 ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')],
496 ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]],
497 { highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
498 prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') }