1 var theList, theExtraList, toggleWithKeyboard = false;
4 setCommentsList = function() {
5 var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter;
7 totalInput = $('#comments-form .tablenav :input[name="_total"]');
8 perPageInput = $('#comments-form .tablenav :input[name="_per_page"]');
9 pageInput = $('#comments-form .tablenav :input[name="_page"]');
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() {
21 n = a.html().replace(/[ ,.]+/g, '');
23 if ( isNaN(n) ) return;
24 n = n + ( $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1 );
25 if ( n < 0 ) { n = 0; }
26 a.parents('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
29 n = n.substr(0, n.length-3)+' '+n.substr(-3);
34 // Send current total, page, per_page and url
35 delBefore = function( settings ) {
36 settings.data._total = totalInput.val();
37 settings.data._per_page = perPageInput.val();
38 settings.data._page = pageInput.val();
39 settings.data._url = document.location.href;
41 if ( 'undefined' != showNotice && settings.data.action && settings.data.action == 'delete-comment' && !settings.data.spam )
42 return showNotice.warn() ? settings : false;
47 /* Updates the current total (as displayed visibly)
49 updateTotalCount = function( total, time, setConfidentTime ) {
50 if ( time < lastConfidentTime ) {
53 totalInput.val( total.toString() );
54 if ( setConfidentTime ) {
55 lastConfidentTime = time;
57 $('span.total-type-count').each( function() {
59 n = totalInput.val().toString();
61 n = n.substr(0, n.length-3)+' '+n.substr(-3);
67 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
68 delAfter = function( r, settings ) {
69 $('span.pending-count').each( function() {
71 n = a.html().replace(/[ ,.]+/g, '');
73 if ( isNaN(n) ) return;
74 if ( $('#' + settings.element).is('.unapproved') ) { // we deleted a formerly unapproved comment
76 } else if ( $(settings.target).parents( 'span.unapprove' ).size() ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
79 if ( n < 0 ) { n = 0; }
80 a.parents('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
83 n = n.substr(0, n.length-3)+' '+n.substr(-3);
87 $('span.spam-count').each( function() {
89 n = a.html().replace(/[ ,.]+/g, '');
91 if ( isNaN(n) ) return;
92 if ( $(settings.target).parents( 'span.spam' ).size() ) { // we marked a comment as spam
94 } else if ( $('#' + settings.element).is('.spam') ) { // we approved or deleted a comment marked as spam
97 if ( n < 0 ) { n = 0; }
100 n = n.substr(0, n.length-3)+' '+n.substr(-3);
106 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
107 // Set the total to the known good value (even if this value is a little old, newer values should only be a few less, and so shouldn't mess up the page links)
108 updateTotalCount( settings.parsed.responses[0].supplemental.total, settings.parsed.responses[0].supplemental.time, true );
109 if ( $.trim( settings.parsed.responses[0].supplemental.pageLinks ) ) {
110 $('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( settings.parsed.responses[0].supplemental.pageLinks ) );
111 } else if ( 'undefined' != typeof settings.parsed.responses[0].supplemental.pageLinks ) {
112 $('.tablenav-pages').find( '.page-numbers' ).remove();
115 // Decrement the total
116 var total = parseInt( totalInput.val(), 10 );
119 updateTotalCount( total, r, false );
122 if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 ) {
126 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
127 $('#get-extra-comments').submit();
130 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
131 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } );
138 var row = $('#replyrow');
140 $('a.cancel', row).click(function() { return commentReply.revert(); });
141 $('a.save', row).click(function() { return commentReply.send(); });
142 $('input#author, input#author-email, input#author-url', row).keypress(function(e){
143 if ( e.which == 13 ) {
151 $('#the-comment-list .column-comment > p').dblclick(function(){
152 commentReply.toggle($(this).parent());
155 $('#doaction, #doaction2, #post-query-submit').click(function(e){
156 if ( $('#the-comment-list #replyrow').length > 0 )
157 commentReply.close();
160 this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
164 addEvents : function(r) {
166 $(this).find('.column-comment > p').dblclick(function(){
167 commentReply.toggle($(this).parent());
172 toggle : function(el) {
173 if ( $(el).css('display') != 'none' )
174 $(el).find('a.vim-q').click();
177 revert : function() {
179 if ( $('#the-comment-list #replyrow').length < 1 )
182 $('#replyrow').fadeOut('fast', function(){
183 commentReply.close();
190 $(this.o).fadeIn('fast').css('backgroundColor', '');
191 $('#com-reply').append( $('#replyrow') );
192 $('#replycontent').val('');
193 $('#edithead input').val('');
194 $('#replysubmit .error').html('').hide();
195 $('#replysubmit .waiting').hide();
196 if ( $.browser.msie )
197 $('#replycontainer, #replycontent').css('height', '120px');
199 $('#replycontainer').resizable('destroy').css('height', '120px');
202 open : function(id, p, a) {
203 var t = this, editRow, act, h;
205 t.o = '#comment-'+id;
207 $('#replyrow td').attr('colspan', $('.widefat thead th:visible').length);
208 editRow = $('#replyrow'), rowData = $('#inline-'+id);
209 act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment';
211 $('#action', editRow).val(act);
212 $('#comment_post_ID', editRow).val(p);
213 $('#comment_ID', editRow).val(id);
216 $('#author', editRow).val( $('div.author', rowData).text() );
217 $('#author-email', editRow).val( $('div.author-email', rowData).text() );
218 $('#author-url', editRow).val( $('div.author-url', rowData).text() );
219 $('#status', editRow).val( $('div.comment_status', rowData).text() );
220 $('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
221 $('#edithead, #savebtn', editRow).show();
222 $('#replyhead, #replybtn', editRow).hide();
226 if ( $.browser.msie )
227 $('#replycontainer, #replycontent', editRow).height(h-105);
229 $('#replycontainer', editRow).height(h-105);
231 $(t.o).after(editRow.hide()).fadeOut('fast', function(){
232 $('#replyrow').fadeIn('fast');
235 $('#edithead, #savebtn', editRow).hide();
236 $('#replyhead, #replybtn', editRow).show();
237 $(t.o).after(editRow);
238 $('#replyrow').hide().fadeIn('fast');
241 if ( ! $.browser.msie )
242 $('#replycontainer').resizable({
247 $('#replycontainer').width('auto');
251 setTimeout(function() {
252 var rtop, rbottom, scrollTop, vp, scrollBottom;
254 rtop = $('#replyrow').offset().top;
255 rbottom = rtop + $('#replyrow').height();
256 scrollTop = window.pageYOffset || document.documentElement.scrollTop;
257 vp = document.documentElement.clientHeight || self.innerHeight || 0;
258 scrollBottom = scrollTop + vp;
260 if ( scrollBottom - 20 < rbottom )
261 window.scroll(0, rbottom - vp + 35);
262 else if ( rtop - 20 < scrollTop )
263 window.scroll(0, rtop - 35);
265 $('#replycontent').focus().keyup(function(e){
266 if (e.which == 27) commentReply.revert(); // close on Escape
276 $('#replysubmit .waiting').show();
278 $('#replyrow input').each(function() {
279 post[ $(this).attr('name') ] = $(this).val();
282 post.content = $('#replycontent').val();
283 post.id = post.comment_post_ID;
284 post.comments_listing = this.comments_listing;
288 url : wpListL10n.url,
290 success : function(x) { commentReply.show(x); },
291 error : function(r) { commentReply.error(r); }
297 show : function(xml) {
300 if ( typeof(xml) == 'string' ) {
301 this.error({'responseText': xml});
305 r = wpAjax.parseAjaxResponse(xml);
307 this.error({'responseText': wpAjax.broken});
311 if ( 'edit-comment' == this.act )
318 $('#replyrow').after(c);
320 this.o = id = '#comment-'+r.id;
322 this.addEvents($(id));
323 bg = $(id).hasClass('unapproved') ? '#ffffe0' : '#fff';
326 .animate( { 'backgroundColor':'#CCEEBB' }, 600 )
327 .animate( { 'backgroundColor': bg }, 600 );
329 $.fn.wpList.process($(id))
332 error : function(r) {
333 var er = r.statusText;
335 $('#replysubmit .waiting').hide();
337 if ( r.responseText )
338 er = r.responseText.replace( /<.[^<>]*?>/g, '' );
341 $('#replysubmit .error').html(er).show();
346 $(document).ready(function(){
347 var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
351 $('span.delete a.delete').click(function(){return false;});
353 if ( typeof QTags != 'undefined' )
354 ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more');
356 if ( typeof $.table_hotkeys != 'undefined' ) {
357 make_hotkeys_redirect = function(which) {
361 first_last = 'next' == which? 'first' : 'last';
362 l = $('.'+which+'.page-numbers');
364 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
367 edit_comment = function(event, current_row) {
368 window.location = $('span.edit a', current_row).attr('href');
370 toggle_all = function() {
371 toggleWithKeyboard = true;
372 $('#comments-form thead #cb input:checkbox').click().attr('checked', '');
373 toggleWithKeyboard = false;
375 make_bulk = function(value) {
376 return function(event, _) {
377 $('option[value='+value+']').attr('selected', 'selected');
378 $('form#comments-form')[0].submit();
381 $.table_hotkeys($('table.widefat'),['a', 'u', 's', 'd', 'r', 'q', ['e', edit_comment],
382 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')],
383 ['shift+d', make_bulk('delete')], ['shift+x', toggle_all],
384 ['shift+u', make_bulk('unapprove')]],
385 {highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
386 prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next')}