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 if ( el.siblings('#replyrow').length && commentReply.cid == id )
56 n = el.children(':visible').length;
57 author = $('.author strong', el).text();
58 h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
60 author = $('.comment-author', el).text();
61 h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
66 $('strong', '#undo-' + id).text(author + ' ');
67 a = $('.undo a', '#undo-' + id);
68 a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
69 a.attr('className', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1 vim-z vim-destructive');
70 $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
73 list.wpList.del(this);
74 $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
76 $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() });
85 // Updates the current total (as displayed visibly)
86 updateTotalCount = function( total, time, setConfidentTime ) {
87 if ( time < lastConfidentTime )
90 if ( setConfidentTime )
91 lastConfidentTime = time;
93 totalInput.val( total.toString() );
94 $('span.total-type-count').each( function() {
95 updateCount( $(this), total );
99 function dashboardTotals(n) {
100 var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
103 if ( isNaN(n) || !dash.length )
106 total = $('span.total-count', dash);
107 appr = $('span.approved-count', dash);
108 totalN = getCount(total);
111 apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) );
112 updateCount(total, totalN);
113 updateCount(appr, apprN);
117 function getCount(el) {
118 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
124 function updateCount(el, n) {
128 n = n < 1 ? '0' : n.toString();
129 if ( n.length > 3 ) {
130 while ( n.length > 3 ) {
131 n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
132 n = n.substr(0, n.length - 3);
139 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
140 delAfter = function( r, settings ) {
141 var total, pageLinks, N, untrash = $(settings.target).parent().is('span.untrash'), unspam = $(settings.target).parent().is('span.unspam'), spam, trash;
143 function getUpdate(s) {
144 if ( $(settings.target).parent().is('span.' + s) )
146 else if ( $('#' + settings.element).is('.' + s) )
151 spam = getUpdate('spam');
152 trash = getUpdate('trash');
159 $('span.pending-count').each( function() {
160 var a = $(this), n = getCount(a), unapproved = $('#' + settings.element).is('.unapproved');
162 if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
164 } else if ( unapproved ) { // we deleted a formerly unapproved comment
167 if ( n < 0 ) { n = 0; }
168 a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
173 $('span.spam-count').each( function() {
174 var a = $(this), n = getCount(a) + spam;
178 $('span.trash-count').each( function() {
179 var a = $(this), n = getCount(a) + trash;
183 if ( $('#dashboard_right_now').length ) {
184 N = trash ? -1 * trash : 0;
187 total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
188 total = total - spam - trash;
192 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
193 pageLinks = settings.parsed.responses[0].supplemental.pageLinks || '';
194 if ( $.trim( pageLinks ) )
195 $('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( pageLinks ) );
197 $('.tablenav-pages').find( '.page-numbers' ).remove();
199 updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
201 updateTotalCount( total, r, false );
205 if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash ) {
209 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
210 $('#get-extra-comments').submit();
213 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
214 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
215 .bind('wpListDelEnd', function(e, s){
216 var id = s.element.replace(/[^0-9]+/g, '');
218 if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 )
219 $('#undo-' + id).fadeIn(300, function(){ $(this).show() });
228 var row = $('#replyrow');
230 $('a.cancel', row).click(function() { return commentReply.revert(); });
231 $('a.save', row).click(function() { return commentReply.send(); });
232 $('input#author, input#author-email, input#author-url', row).keypress(function(e){
233 if ( e.which == 13 ) {
241 $('#the-comment-list .column-comment > p').dblclick(function(){
242 commentReply.toggle($(this).parent());
245 $('#doaction, #doaction2, #post-query-submit').click(function(e){
246 if ( $('#the-comment-list #replyrow').length > 0 )
247 commentReply.close();
250 this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
254 addEvents : function(r) {
256 $(this).find('.column-comment > p').dblclick(function(){
257 commentReply.toggle($(this).parent());
262 toggle : function(el) {
263 if ( $(el).css('display') != 'none' )
264 $(el).find('a.vim-q').click();
267 revert : function() {
269 if ( $('#the-comment-list #replyrow').length < 1 )
272 $('#replyrow').fadeOut('fast', function(){
273 commentReply.close();
283 c = $('#comment-' + this.cid);
285 if ( this.act == 'edit-comment' )
286 c.fadeIn(300, function(){ c.show() }).css('backgroundColor', '');
288 $('#replyrow').hide();
289 $('#com-reply').append( $('#replyrow') );
290 $('#replycontent').val('');
291 $('input', '#edithead').val('');
292 $('.error', '#replysubmit').html('').hide();
293 $('.waiting', '#replysubmit').hide();
295 if ( $.browser.msie )
296 $('#replycontainer, #replycontent').css('height', '120px');
298 $('#replycontainer').resizable('destroy').css('height', '120px');
304 open : function(id, p, a) {
305 var t = this, editRow, rowData, act, h, c = $('#comment-' + id);
309 $('td', '#replyrow').attr('colspan', $('table.widefat thead th:visible').length);
310 editRow = $('#replyrow');
311 rowData = $('#inline-'+id);
312 act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment';
314 $('#action', editRow).val(act);
315 $('#comment_post_ID', editRow).val(p);
316 $('#comment_ID', editRow).val(id);
319 $('#author', editRow).val( $('div.author', rowData).text() );
320 $('#author-email', editRow).val( $('div.author-email', rowData).text() );
321 $('#author-url', editRow).val( $('div.author-url', rowData).text() );
322 $('#status', editRow).val( $('div.comment_status', rowData).text() );
323 $('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
324 $('#edithead, #savebtn', editRow).show();
325 $('#replyhead, #replybtn', editRow).hide();
329 if ( $.browser.msie )
330 $('#replycontainer, #replycontent', editRow).height(h-105);
332 $('#replycontainer', editRow).height(h-105);
334 c.after( editRow ).fadeOut('fast', function(){
335 $('#replyrow').fadeIn(300, function(){ $(this).show() });
338 $('#edithead, #savebtn', editRow).hide();
339 $('#replyhead, #replybtn', editRow).show();
341 $('#replyrow').fadeIn(300, function(){ $(this).show() });
344 if ( ! $.browser.msie )
345 $('#replycontainer').resizable({
350 $('#replycontainer').width('auto');
354 setTimeout(function() {
355 var rtop, rbottom, scrollTop, vp, scrollBottom;
357 rtop = $('#replyrow').offset().top;
358 rbottom = rtop + $('#replyrow').height();
359 scrollTop = window.pageYOffset || document.documentElement.scrollTop;
360 vp = document.documentElement.clientHeight || self.innerHeight || 0;
361 scrollBottom = scrollTop + vp;
363 if ( scrollBottom - 20 < rbottom )
364 window.scroll(0, rbottom - vp + 35);
365 else if ( rtop - 20 < scrollTop )
366 window.scroll(0, rtop - 35);
368 $('#replycontent').focus().keyup(function(e){
370 commentReply.revert(); // close on Escape
380 $('#replysubmit .waiting').show();
382 $('#replyrow input').each(function() {
383 post[ $(this).attr('name') ] = $(this).val();
386 post.content = $('#replycontent').val();
387 post.id = post.comment_post_ID;
388 post.comments_listing = this.comments_listing;
394 success : function(x) { commentReply.show(x); },
395 error : function(r) { commentReply.error(r); }
401 show : function(xml) {
404 if ( typeof(xml) == 'string' ) {
405 this.error({'responseText': xml});
409 r = wpAjax.parseAjaxResponse(xml);
411 this.error({'responseText': wpAjax.broken});
417 id = '#comment-' + r.id;
418 if ( 'edit-comment' == this.act )
422 $('#replyrow').after(c);
425 this.addEvents($(id));
426 bg = $(id).hasClass('unapproved') ? '#ffffe0' : '#fff';
429 .animate( { 'backgroundColor':'#CCEEBB' }, 600 )
430 .animate( { 'backgroundColor': bg }, 600 );
432 $.fn.wpList.process($(id))
435 error : function(r) {
436 var er = r.statusText;
438 $('#replysubmit .waiting').hide();
440 if ( r.responseText )
441 er = r.responseText.replace( /<.[^<>]*?>/g, '' );
444 $('#replysubmit .error').html(er).show();
449 $(document).ready(function(){
450 var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
454 $('span.delete a.delete').click(function(){return false;});
456 if ( typeof QTags != 'undefined' )
457 ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more');
459 if ( typeof $.table_hotkeys != 'undefined' ) {
460 make_hotkeys_redirect = function(which) {
464 first_last = 'next' == which? 'first' : 'last';
465 l = $('.'+which+'.page-numbers');
467 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
471 edit_comment = function(event, current_row) {
472 window.location = $('span.edit a', current_row).attr('href');
475 toggle_all = function() {
476 toggleWithKeyboard = true;
477 $('input:checkbox', '#cb').click().attr('checked', '');
478 toggleWithKeyboard = false;
481 make_bulk = function(value) {
483 var scope = $('select[name="action"]');
484 $('option[value='+value+']', scope).attr('selected', 'selected');
485 $('#comments-form').submit();
491 ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all],
492 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')],
493 ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')],
494 ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]],
495 { highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
496 prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') }