2 (function($) { |
2 (function($) { |
3 |
3 |
4 setCommentsList = function() { |
4 setCommentsList = function() { |
5 var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter; |
5 var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter; |
6 |
6 |
7 totalInput = $('#comments-form .tablenav :input[name="_total"]'); |
7 totalInput = $('.tablenav input[name="_total"]', '#comments-form'); |
8 perPageInput = $('#comments-form .tablenav :input[name="_per_page"]'); |
8 perPageInput = $('.tablenav input[name="_per_page"]', '#comments-form'); |
9 pageInput = $('#comments-form .tablenav :input[name="_page"]'); |
9 pageInput = $('.tablenav input[name="_page"]', '#comments-form'); |
10 |
10 |
11 dimAfter = function( r, settings ) { |
11 dimAfter = function( r, settings ) { |
12 var c = $('#' + settings.element); |
12 var c = $('#' + settings.element); |
13 |
13 |
14 if ( c.is('.unapproved') ) |
14 if ( c.is('.unapproved') ) |
15 c.find('div.comment_status').html('0') |
15 c.find('div.comment_status').html('0') |
16 else |
16 else |
17 c.find('div.comment_status').html('1') |
17 c.find('div.comment_status').html('1') |
18 |
18 |
19 $('span.pending-count').each( function() { |
19 $('span.pending-count').each( function() { |
20 var a = $(this), n; |
20 var a = $(this), n, dif; |
21 n = a.html().replace(/[ ,.]+/g, ''); |
21 n = a.html().replace(/[^0-9]+/g, ''); |
22 n = parseInt(n,10); |
22 n = parseInt(n,10); |
23 if ( isNaN(n) ) return; |
23 if ( isNaN(n) ) return; |
24 n = n + ( $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1 ); |
24 dif = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; |
|
25 n = n + dif; |
25 if ( n < 0 ) { n = 0; } |
26 if ( n < 0 ) { n = 0; } |
26 a.parents('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); |
27 a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); |
27 n = n.toString(); |
28 updateCount(a, n); |
28 if ( n.length > 3 ) |
29 dashboardTotals(); |
29 n = n.substr(0, n.length-3)+' '+n.substr(-3); |
|
30 a.html(n); |
|
31 }); |
30 }); |
32 }; |
31 }; |
33 |
32 |
34 // Send current total, page, per_page and url |
33 // Send current total, page, per_page and url |
35 delBefore = function( settings ) { |
34 delBefore = function( settings, list ) { |
36 settings.data._total = totalInput.val(); |
35 var cl = $(settings.target).attr('className'), id, el, n, h, a, author, action = false; |
37 settings.data._per_page = perPageInput.val(); |
36 |
38 settings.data._page = pageInput.val(); |
37 settings.data._total = totalInput.val() || 0; |
|
38 settings.data._per_page = perPageInput.val() || 0; |
|
39 settings.data._page = pageInput.val() || 0; |
39 settings.data._url = document.location.href; |
40 settings.data._url = document.location.href; |
40 |
41 |
41 if ( 'undefined' != showNotice && settings.data.action && settings.data.action == 'delete-comment' && !settings.data.spam ) |
42 if ( cl.indexOf(':trash=1') != -1 ) |
42 return showNotice.warn() ? settings : false; |
43 action = 'trash'; |
|
44 else if ( cl.indexOf(':spam=1') != -1 ) |
|
45 action = 'spam'; |
|
46 |
|
47 if ( action ) { |
|
48 id = cl.replace(/.*?comment-([0-9]+).*/, '$1'); |
|
49 el = $('#comment-' + id); |
|
50 note = $('#' + action + '-undo-holder').html(); |
|
51 |
|
52 if ( el.siblings('#replyrow').length && commentReply.cid == id ) |
|
53 commentReply.close(); |
|
54 |
|
55 if ( el.is('tr') ) { |
|
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>'); |
|
59 } else { |
|
60 author = $('.comment-author', el).text(); |
|
61 h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>'); |
|
62 } |
|
63 |
|
64 el.before(h); |
|
65 |
|
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'); |
|
71 |
|
72 a.click(function(){ |
|
73 list.wpList.del(this); |
|
74 $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){ |
|
75 $(this).remove(); |
|
76 $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() }); |
|
77 }); |
|
78 return false; |
|
79 }); |
|
80 } |
43 |
81 |
44 return settings; |
82 return settings; |
45 }; |
83 }; |
46 |
84 |
47 /* Updates the current total (as displayed visibly) |
85 // Updates the current total (as displayed visibly) |
48 */ |
|
49 updateTotalCount = function( total, time, setConfidentTime ) { |
86 updateTotalCount = function( total, time, setConfidentTime ) { |
50 if ( time < lastConfidentTime ) { |
87 if ( time < lastConfidentTime ) |
51 return; |
88 return; |
52 } |
89 |
|
90 if ( setConfidentTime ) |
|
91 lastConfidentTime = time; |
|
92 |
53 totalInput.val( total.toString() ); |
93 totalInput.val( total.toString() ); |
54 if ( setConfidentTime ) { |
|
55 lastConfidentTime = time; |
|
56 } |
|
57 $('span.total-type-count').each( function() { |
94 $('span.total-type-count').each( function() { |
58 var a = $(this), n; |
95 updateCount( $(this), total ); |
59 n = totalInput.val().toString(); |
96 }); |
60 if ( n.length > 3 ) |
|
61 n = n.substr(0, n.length-3)+' '+n.substr(-3); |
|
62 a.html(n); |
|
63 }); |
|
64 |
|
65 }; |
97 }; |
|
98 |
|
99 function dashboardTotals(n) { |
|
100 var dash = $('#dashboard_right_now'), total, appr, totalN, apprN; |
|
101 |
|
102 n = n || 0; |
|
103 if ( isNaN(n) || !dash.length ) |
|
104 return; |
|
105 |
|
106 total = $('span.total-count', dash); |
|
107 appr = $('span.approved-count', dash); |
|
108 totalN = getCount(total); |
|
109 |
|
110 totalN = totalN + n; |
|
111 apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) ); |
|
112 updateCount(total, totalN); |
|
113 updateCount(appr, apprN); |
|
114 |
|
115 } |
|
116 |
|
117 function getCount(el) { |
|
118 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 ); |
|
119 if ( isNaN(n) ) |
|
120 return 0; |
|
121 return n; |
|
122 } |
|
123 |
|
124 function updateCount(el, n) { |
|
125 var n1 = ''; |
|
126 if ( isNaN(n) ) |
|
127 return; |
|
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); |
|
133 } |
|
134 n = n + n1; |
|
135 } |
|
136 el.html(n); |
|
137 } |
66 |
138 |
67 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success |
139 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success |
68 delAfter = function( r, settings ) { |
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; |
|
142 |
|
143 function getUpdate(s) { |
|
144 if ( $(settings.target).parent().is('span.' + s) ) |
|
145 return 1; |
|
146 else if ( $('#' + settings.element).is('.' + s) ) |
|
147 return -1; |
|
148 |
|
149 return 0; |
|
150 } |
|
151 spam = getUpdate('spam'); |
|
152 trash = getUpdate('trash'); |
|
153 |
|
154 if ( untrash ) |
|
155 trash = -1; |
|
156 if ( unspam ) |
|
157 spam = -1; |
|
158 |
69 $('span.pending-count').each( function() { |
159 $('span.pending-count').each( function() { |
70 var a = $(this), n; |
160 var a = $(this), n = getCount(a), unapproved = $('#' + settings.element).is('.unapproved'); |
71 n = a.html().replace(/[ ,.]+/g, ''); |
161 |
72 n = parseInt(n,10); |
162 if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove" |
73 if ( isNaN(n) ) return; |
163 n = n + 1; |
74 if ( $('#' + settings.element).is('.unapproved') ) { // we deleted a formerly unapproved comment |
164 } else if ( unapproved ) { // we deleted a formerly unapproved comment |
75 n = n - 1; |
165 n = n - 1; |
76 } else if ( $(settings.target).parents( 'span.unapprove' ).size() ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove" |
|
77 n = n + 1; |
|
78 } |
166 } |
79 if ( n < 0 ) { n = 0; } |
167 if ( n < 0 ) { n = 0; } |
80 a.parents('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); |
168 a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); |
81 n = n.toString(); |
169 updateCount(a, n); |
82 if ( n.length > 3 ) |
170 dashboardTotals(); |
83 n = n.substr(0, n.length-3)+' '+n.substr(-3); |
|
84 a.html(n); |
|
85 }); |
171 }); |
86 |
172 |
87 $('span.spam-count').each( function() { |
173 $('span.spam-count').each( function() { |
88 var a = $(this), n; |
174 var a = $(this), n = getCount(a) + spam; |
89 n = a.html().replace(/[ ,.]+/g, ''); |
175 updateCount(a, n); |
90 n = parseInt(n,10); |
176 }); |
91 if ( isNaN(n) ) return; |
177 |
92 if ( $(settings.target).parents( 'span.spam' ).size() ) { // we marked a comment as spam |
178 $('span.trash-count').each( function() { |
93 n = n + 1; |
179 var a = $(this), n = getCount(a) + trash; |
94 } else if ( $('#' + settings.element).is('.spam') ) { // we approved or deleted a comment marked as spam |
180 updateCount(a, n); |
95 n = n - 1; |
181 }); |
96 } |
182 |
97 if ( n < 0 ) { n = 0; } |
183 if ( $('#dashboard_right_now').length ) { |
98 n = n.toString(); |
184 N = trash ? -1 * trash : 0; |
99 if ( n.length > 3 ) |
185 dashboardTotals(N); |
100 n = n.substr(0, n.length-3)+' '+n.substr(-3); |
|
101 a.html(n); |
|
102 }); |
|
103 |
|
104 |
|
105 // XML response |
|
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(); |
|
113 } |
|
114 } else { |
186 } else { |
115 // Decrement the total |
187 total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0; |
116 var total = parseInt( totalInput.val(), 10 ); |
188 total = total - spam - trash; |
117 if ( total-- < 0 ) |
189 if ( total < 0 ) |
118 total = 0; |
190 total = 0; |
119 updateTotalCount( total, r, false ); |
191 |
120 } |
192 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) { |
121 |
193 pageLinks = settings.parsed.responses[0].supplemental.pageLinks || ''; |
122 if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 ) { |
194 if ( $.trim( pageLinks ) ) |
|
195 $('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( pageLinks ) ); |
|
196 else |
|
197 $('.tablenav-pages').find( '.page-numbers' ).remove(); |
|
198 |
|
199 updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true ); |
|
200 } else { |
|
201 updateTotalCount( total, r, false ); |
|
202 } |
|
203 } |
|
204 |
|
205 if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash ) { |
123 return; |
206 return; |
124 } |
207 } |
125 |
208 |
126 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() ); |
209 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() ); |
127 $('#get-extra-comments').submit(); |
210 $('#get-extra-comments').submit(); |
128 }; |
211 }; |
129 |
212 |
130 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } ); |
213 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' } ); |
214 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } ) |
132 |
215 .bind('wpListDelEnd', function(e, s){ |
|
216 var id = s.element.replace(/[^0-9]+/g, ''); |
|
217 |
|
218 if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 ) |
|
219 $('#undo-' + id).fadeIn(300, function(){ $(this).show() }); |
|
220 }); |
133 }; |
221 }; |
134 |
222 |
135 commentReply = { |
223 commentReply = { |
|
224 cid : '', |
|
225 act : '', |
136 |
226 |
137 init : function() { |
227 init : function() { |
138 var row = $('#replyrow'); |
228 var row = $('#replyrow'); |
139 |
229 |
140 $('a.cancel', row).click(function() { return commentReply.revert(); }); |
230 $('a.cancel', row).click(function() { return commentReply.revert(); }); |
185 |
275 |
186 return false; |
276 return false; |
187 }, |
277 }, |
188 |
278 |
189 close : function() { |
279 close : function() { |
190 $(this.o).fadeIn('fast').css('backgroundColor', ''); |
280 var c; |
191 $('#com-reply').append( $('#replyrow') ); |
281 |
192 $('#replycontent').val(''); |
282 if ( this.cid ) { |
193 $('#edithead input').val(''); |
283 c = $('#comment-' + this.cid); |
194 $('#replysubmit .error').html('').hide(); |
284 |
195 $('#replysubmit .waiting').hide(); |
285 if ( this.act == 'edit-comment' ) |
196 if ( $.browser.msie ) |
286 c.fadeIn(300, function(){ c.show() }).css('backgroundColor', ''); |
197 $('#replycontainer, #replycontent').css('height', '120px'); |
287 |
198 else |
288 $('#replyrow').hide(); |
199 $('#replycontainer').resizable('destroy').css('height', '120px'); |
289 $('#com-reply').append( $('#replyrow') ); |
|
290 $('#replycontent').val(''); |
|
291 $('input', '#edithead').val(''); |
|
292 $('.error', '#replysubmit').html('').hide(); |
|
293 $('.waiting', '#replysubmit').hide(); |
|
294 |
|
295 if ( $.browser.msie ) |
|
296 $('#replycontainer, #replycontent').css('height', '120px'); |
|
297 else |
|
298 $('#replycontainer').resizable('destroy').css('height', '120px'); |
|
299 |
|
300 this.cid = ''; |
|
301 } |
200 }, |
302 }, |
201 |
303 |
202 open : function(id, p, a) { |
304 open : function(id, p, a) { |
203 var t = this, editRow, act, h; |
305 var t = this, editRow, rowData, act, h, c = $('#comment-' + id); |
204 t.close(); |
306 t.close(); |
205 t.o = '#comment-'+id; |
307 t.cid = id; |
206 |
308 |
207 $('#replyrow td').attr('colspan', $('.widefat thead th:visible').length); |
309 $('td', '#replyrow').attr('colspan', $('table.widefat thead th:visible').length); |
208 editRow = $('#replyrow'), rowData = $('#inline-'+id); |
310 editRow = $('#replyrow'); |
|
311 rowData = $('#inline-'+id); |
209 act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment'; |
312 act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment'; |
210 |
313 |
211 $('#action', editRow).val(act); |
314 $('#action', editRow).val(act); |
212 $('#comment_post_ID', editRow).val(p); |
315 $('#comment_post_ID', editRow).val(p); |
213 $('#comment_ID', editRow).val(id); |
316 $('#comment_ID', editRow).val(id); |
362 l = $('.'+which+'.page-numbers'); |
465 l = $('.'+which+'.page-numbers'); |
363 if (l.length) |
466 if (l.length) |
364 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1'; |
467 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1'; |
365 } |
468 } |
366 }; |
469 }; |
|
470 |
367 edit_comment = function(event, current_row) { |
471 edit_comment = function(event, current_row) { |
368 window.location = $('span.edit a', current_row).attr('href'); |
472 window.location = $('span.edit a', current_row).attr('href'); |
369 }; |
473 }; |
|
474 |
370 toggle_all = function() { |
475 toggle_all = function() { |
371 toggleWithKeyboard = true; |
476 toggleWithKeyboard = true; |
372 $('#comments-form thead #cb input:checkbox').click().attr('checked', ''); |
477 $('input:checkbox', '#cb').click().attr('checked', ''); |
373 toggleWithKeyboard = false; |
478 toggleWithKeyboard = false; |
374 } |
479 }; |
|
480 |
375 make_bulk = function(value) { |
481 make_bulk = function(value) { |
376 return function(event, _) { |
482 return function() { |
377 $('option[value='+value+']').attr('selected', 'selected'); |
483 var scope = $('select[name="action"]'); |
378 $('form#comments-form')[0].submit(); |
484 $('option[value='+value+']', scope).attr('selected', 'selected'); |
|
485 $('#comments-form').submit(); |
379 } |
486 } |
380 }; |
487 }; |
381 $.table_hotkeys($('table.widefat'),['a', 'u', 's', 'd', 'r', 'q', ['e', edit_comment], |
488 |
382 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')], |
489 $.table_hotkeys( |
383 ['shift+d', make_bulk('delete')], ['shift+x', toggle_all], |
490 $('table.widefat'), |
384 ['shift+u', make_bulk('unapprove')]], |
491 ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all], |
385 {highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last, |
492 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')], |
386 prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next')} |
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') } |
387 ); |
497 ); |
388 } |
498 } |
389 }); |
499 }); |
390 |
500 |
391 })(jQuery); |
501 })(jQuery); |