mp-wp_genesis 1 var theList; var theExtraList;
mp-wp_genesis 2 (function($) {
mp-wp_genesis 3
mp-wp_genesis 4 setCommentsList = function() {
mp-wp_genesis 5 var dimAfter = function( r, settings ) {
mp-wp_genesis 6 var c = $('#' + settings.element);
mp-wp_genesis 7
mp-wp_genesis 8 if ( c.is('.unapproved') )
mp-wp_genesis 9 c.find('div.comment_status').html('0')
mp-wp_genesis 10 else
mp-wp_genesis 11 c.find('div.comment_status').html('1')
mp-wp_genesis 12
mp-wp_genesis 13 $('span.pending-count').each( function() {
mp-wp_genesis 14 var a = $(this);
mp-wp_genesis 15 var n = a.html().replace(/[ ,.]+/g, '');
mp-wp_genesis 16 n = parseInt(n,10);
mp-wp_genesis 17 if ( isNaN(n) ) return;
mp-wp_genesis 18 n = n + ( $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1 );
mp-wp_genesis 19 if ( n < 0 ) { n = 0; }
mp-wp_genesis 20 $('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
mp-wp_genesis 21 n = n.toString();
mp-wp_genesis 22 if ( n.length > 3 )
mp-wp_genesis 23 n = n.substr(0, n.length-3)+' '+n.substr(-3);
mp-wp_genesis 24 a.html(n);
mp-wp_genesis 25 });
mp-wp_genesis 26 };
mp-wp_genesis 27
mp-wp_genesis 28 var delAfter = function( r, settings ) {
mp-wp_genesis 29 $('span.pending-count').each( function() {
mp-wp_genesis 30 var a = $(this);
mp-wp_genesis 31 var n = a.html().replace(/[ ,.]+/g, '');
mp-wp_genesis 32 n = parseInt(n,10);
mp-wp_genesis 33 if ( isNaN(n) ) return;
mp-wp_genesis 34 if ( $('#' + settings.element).is('.unapproved') ) { // we deleted a formerly unapproved comment
mp-wp_genesis 35 n = n - 1;
mp-wp_genesis 36 } else if ( $(settings.target).parents( 'span.unapprove' ).size() ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
mp-wp_genesis 37 n = n + 1;
mp-wp_genesis 38 }
mp-wp_genesis 39 if ( n < 0 ) { n = 0; }
mp-wp_genesis 40 $('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
mp-wp_genesis 41 n = n.toString();
mp-wp_genesis 42 if ( n.length > 3 )
mp-wp_genesis 43 n = n.substr(0, n.length-3)+' '+n.substr(-3);
mp-wp_genesis 44 a.html(n);
mp-wp_genesis 45 });
mp-wp_genesis 46
mp-wp_genesis 47 $('span.spam-count' ).each( function() {
mp-wp_genesis 48 var a = $(this);
mp-wp_genesis 49 var n = a.html().replace(/[ ,.]+/g, '');
mp-wp_genesis 50 n = parseInt(n,10);
mp-wp_genesis 51 if ( isNaN(n) ) return;
mp-wp_genesis 52 if ( $(settings.target).parents( 'span.spam' ).size() ) { // we marked a comment as spam
mp-wp_genesis 53 n = n + 1;
mp-wp_genesis 54 } else if ( $('#' + settings.element).is('.spam') ) { // we approved or deleted a comment marked as spam
mp-wp_genesis 55 n = n - 1;
mp-wp_genesis 56 }
mp-wp_genesis 57 if ( n < 0 ) { n = 0; }
mp-wp_genesis 58 n = n.toString();
mp-wp_genesis 59 if ( n.length > 3 )
mp-wp_genesis 60 n = n.substr(0, n.length-3)+' '+n.substr(-3);
mp-wp_genesis 61 a.html(n);
mp-wp_genesis 62 });
mp-wp_genesis 63
mp-wp_genesis 64 if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 ) {
mp-wp_genesis 65 return;
mp-wp_genesis 66 }
mp-wp_genesis 67
mp-wp_genesis 68 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
mp-wp_genesis 69 $('#get-extra-comments').submit();
mp-wp_genesis 70 };
mp-wp_genesis 71
mp-wp_genesis 72 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
mp-wp_genesis 73 theList = $('#the-comment-list').wpList( { alt: '', dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } );
mp-wp_genesis 74
mp-wp_genesis 75 };
mp-wp_genesis 76
mp-wp_genesis 77 $(document).ready(function(){
mp-wp_genesis 78 setCommentsList();
mp-wp_genesis 79 });
mp-wp_genesis 80
mp-wp_genesis 81 commentReply = {
mp-wp_genesis 82
mp-wp_genesis 83 init : function() {
mp-wp_genesis 84 var row = $('#replyrow');
mp-wp_genesis 85
mp-wp_genesis 86 $('a.cancel', row).click(function() { return commentReply.revert(); });
mp-wp_genesis 87 $('a.save', row).click(function() { return commentReply.send(this); });
mp-wp_genesis 88
mp-wp_genesis 89 // add events
mp-wp_genesis 90 $('#the-comment-list .column-comment > p').dblclick(function(){
mp-wp_genesis 91 commentReply.toggle($(this).parent());
mp-wp_genesis 92 });
mp-wp_genesis 93
mp-wp_genesis 94 $('#doaction, #doaction2, #post-query-submit').click(function(e){
mp-wp_genesis 95 if ( $('#the-comment-list #replyrow').length > 0 )
mp-wp_genesis 96 t.close();
mp-wp_genesis 97 });
mp-wp_genesis 98
mp-wp_genesis 99 },
mp-wp_genesis 100
mp-wp_genesis 101 addEvents : function(r) {
mp-wp_genesis 102 r.each(function() {
mp-wp_genesis 103 $(this).find('.column-comment > p').dblclick(function(){
mp-wp_genesis 104 commentReply.toggle($(this).parent());
mp-wp_genesis 105 });
mp-wp_genesis 106 });
mp-wp_genesis 107 },
mp-wp_genesis 108
mp-wp_genesis 109 toggle : function(el) {
mp-wp_genesis 110 if ( $(el).css('display') != 'none' )
mp-wp_genesis 111 $(el).find('a.vim-q').click();
mp-wp_genesis 112 },
mp-wp_genesis 113
mp-wp_genesis 114 revert : function() {
mp-wp_genesis 115
mp-wp_genesis 116 if ( $('#the-comment-list #replyrow').length < 1 )
mp-wp_genesis 117 return false;
mp-wp_genesis 118
mp-wp_genesis 119 $('#replyrow').fadeOut('fast', function(){
mp-wp_genesis 120 commentReply.close();
mp-wp_genesis 121 });
mp-wp_genesis 122
mp-wp_genesis 123 return false;
mp-wp_genesis 124 },
mp-wp_genesis 125
mp-wp_genesis 126 close : function() {
mp-wp_genesis 127 $(this.o).fadeIn('fast').css('backgroundColor', '');
mp-wp_genesis 128 $('#com-reply').append( $('#replyrow') );
mp-wp_genesis 129 $('#replycontent').val('');
mp-wp_genesis 130 $('#edithead input').val('');
mp-wp_genesis 131 $('#replysubmit .error').html('').hide();
mp-wp_genesis 132 $('#replysubmit .waiting').hide();
mp-wp_genesis 133 if ( $.browser.msie )
mp-wp_genesis 134 $('#replycontainer, #replycontent').css('height', '120px');
mp-wp_genesis 135 else
mp-wp_genesis 136 $('#replycontainer').resizable('destroy').css('height', '120px');
mp-wp_genesis 137 },
mp-wp_genesis 138
mp-wp_genesis 139 open : function(id, p, a) {
mp-wp_genesis 140 var t = this;
mp-wp_genesis 141 t.close();
mp-wp_genesis 142 t.o = '#comment-'+id;
mp-wp_genesis 143
mp-wp_genesis 144 $('#replyrow td').attr('colspan', $('.widefat thead th:visible').length);
mp-wp_genesis 145 var editRow = $('#replyrow'), rowData = $('#inline-'+id);
mp-wp_genesis 146 var act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment';
mp-wp_genesis 147
mp-wp_genesis 148 $('#action', editRow).val(act);
mp-wp_genesis 149 $('#comment_post_ID', editRow).val(p);
mp-wp_genesis 150 $('#comment_ID', editRow).val(id);
mp-wp_genesis 151
mp-wp_genesis 152 if ( a == 'edit' ) {
mp-wp_genesis 153 $('#author', editRow).val( $('div.author', rowData).text() );
mp-wp_genesis 154 $('#author-email', editRow).val( $('div.author-email', rowData).text() );
mp-wp_genesis 155 $('#author-url', editRow).val( $('div.author-url', rowData).text() );
mp-wp_genesis 156 $('#status', editRow).val( $('div.comment_status', rowData).text() );
mp-wp_genesis 157 $('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
mp-wp_genesis 158 $('#edithead, #savebtn', editRow).show();
mp-wp_genesis 159 $('#replyhead, #replybtn', editRow).hide();
mp-wp_genesis 160
mp-wp_genesis 161 var h = $(t.o).height();
mp-wp_genesis 162 if ( h > 220 )
mp-wp_genesis 163 if ( $.browser.msie )
mp-wp_genesis 164 $('#replycontainer, #replycontent', editRow).height(h-105);
mp-wp_genesis 165 else
mp-wp_genesis 166 $('#replycontainer', editRow).height(h-105);
mp-wp_genesis 167
mp-wp_genesis 168 $(t.o).after(editRow.hide()).fadeOut('fast', function(){
mp-wp_genesis 169 $('#replyrow').fadeIn('fast');
mp-wp_genesis 170 });
mp-wp_genesis 171 } else {
mp-wp_genesis 172 $('#edithead, #savebtn', editRow).hide();
mp-wp_genesis 173 $('#replyhead, #replybtn', editRow).show();
mp-wp_genesis 174 $(t.o).after(editRow);
mp-wp_genesis 175 $('#replyrow').hide().fadeIn('fast');
mp-wp_genesis 176 }
mp-wp_genesis 177
mp-wp_genesis 178 if ( ! $.browser.msie )
mp-wp_genesis 179 $('#replycontainer').resizable({
mp-wp_genesis 180 handles : 's',
mp-wp_genesis 181 axis : 'y',
mp-wp_genesis 182 minHeight : 80,
mp-wp_genesis 183 stop : function() {
mp-wp_genesis 184 $('#replycontainer').width('auto');
mp-wp_genesis 185 }
mp-wp_genesis 186 });
mp-wp_genesis 187
mp-wp_genesis 188 setTimeout(function() {
mp-wp_genesis 189 var rtop = $('#replyrow').offset().top;
mp-wp_genesis 190 var rbottom = rtop + $('#replyrow').height();
mp-wp_genesis 191 var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
mp-wp_genesis 192 var vp = document.documentElement.clientHeight || self.innerHeight || 0;
mp-wp_genesis 193 var scrollBottom = scrollTop + vp;
mp-wp_genesis 194
mp-wp_genesis 195 if ( scrollBottom - 20 < rbottom )
mp-wp_genesis 196 window.scroll(0, rbottom - vp + 35);
mp-wp_genesis 197 else if ( rtop - 20 < scrollTop )
mp-wp_genesis 198 window.scroll(0, rtop - 35);
mp-wp_genesis 199
mp-wp_genesis 200 $('#replycontent').focus().keyup(function(e){
mp-wp_genesis 201 if (e.which == 27) commentReply.revert(); // close on Escape
mp-wp_genesis 202 });
mp-wp_genesis 203 }, 600);
mp-wp_genesis 204
mp-wp_genesis 205 return false;
mp-wp_genesis 206 },
mp-wp_genesis 207
mp-wp_genesis 208 send : function() {
mp-wp_genesis 209 var post = {};
mp-wp_genesis 210
mp-wp_genesis 211 $('#replysubmit .waiting').show();
mp-wp_genesis 212
mp-wp_genesis 213 $('#replyrow input').each(function() {
mp-wp_genesis 214 post[ $(this).attr('name') ] = $(this).val();
mp-wp_genesis 215 });
mp-wp_genesis 216
mp-wp_genesis 217 post.content = $('#replycontent').val();
mp-wp_genesis 218 post.id = post.comment_post_ID;
mp-wp_genesis 219
mp-wp_genesis 220 $.ajax({
mp-wp_genesis 221 type : 'POST',
mp-wp_genesis 222 url : wpListL10n.url,
mp-wp_genesis 223 data : post,
mp-wp_genesis 224 success : function(x) { commentReply.show(x); },
mp-wp_genesis 225 error : function(r) { commentReply.error(r); }
mp-wp_genesis 226 });
mp-wp_genesis 227
mp-wp_genesis 228 return false;
mp-wp_genesis 229 },
mp-wp_genesis 230
mp-wp_genesis 231 show : function(xml) {
mp-wp_genesis 232
mp-wp_genesis 233 if ( typeof(xml) == 'string' ) {
mp-wp_genesis 234 this.error({'responseText': xml});
mp-wp_genesis 235 return false;
mp-wp_genesis 236 }
mp-wp_genesis 237
mp-wp_genesis 238 var r = wpAjax.parseAjaxResponse(xml);
mp-wp_genesis 239 if ( r.errors ) {
mp-wp_genesis 240 this.error({'responseText': wpAjax.broken});
mp-wp_genesis 241 return false;
mp-wp_genesis 242 }
mp-wp_genesis 243
mp-wp_genesis 244 if ( 'edit-comment' == this.act )
mp-wp_genesis 245 $(this.o).remove();
mp-wp_genesis 246
mp-wp_genesis 247 r = r.responses[0];
mp-wp_genesis 248 var c = r.data;
mp-wp_genesis 249
mp-wp_genesis 250 $(c).hide()
mp-wp_genesis 251 $('#replyrow').after(c);
mp-wp_genesis 252 this.o = id = '#comment-'+r.id;
mp-wp_genesis 253 $(id+' .hide-if-no-js').removeClass('hide-if-no-js');
mp-wp_genesis 254 this.revert();
mp-wp_genesis 255 this.addEvents($(id));
mp-wp_genesis 256 var bg = $(id).hasClass('unapproved') ? '#ffffe0' : '#fff';
mp-wp_genesis 257
mp-wp_genesis 258 $(id)
mp-wp_genesis 259 .animate( { 'backgroundColor':'#CCEEBB' }, 600 )
mp-wp_genesis 260 .animate( { 'backgroundColor': bg }, 600 );
mp-wp_genesis 261
mp-wp_genesis 262 $.fn.wpList.process($(id))
mp-wp_genesis 263 },
mp-wp_genesis 264
mp-wp_genesis 265 error : function(r) {
mp-wp_genesis 266 var er = r.statusText;
mp-wp_genesis 267
mp-wp_genesis 268 $('#replysubmit .waiting').hide();
mp-wp_genesis 269
mp-wp_genesis 270 if ( r.responseText )
mp-wp_genesis 271 er = r.responseText.replace( /<.[^<>]*?>/g, '' );
mp-wp_genesis 272
mp-wp_genesis 273 if ( er )
mp-wp_genesis 274 $('#replysubmit .error').html(er).show();
mp-wp_genesis 275
mp-wp_genesis 276 }
mp-wp_genesis 277 };
mp-wp_genesis 278 toggleWithKeyboard = false;
mp-wp_genesis 279 $(document).ready(function(){
mp-wp_genesis 280 columns.init('edit-comments');
mp-wp_genesis 281 commentReply.init();
mp-wp_genesis 282
mp-wp_genesis 283 if ( typeof QTags != 'undefined' )
mp-wp_genesis 284 ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more');
mp-wp_genesis 285
mp-wp_genesis 286 if ( typeof $.table_hotkeys != 'undefined' ) {
mp-wp_genesis 287 var make_hotkeys_redirect = function(which) {
mp-wp_genesis 288 return function() {
mp-wp_genesis 289 var first_last = 'next' == which? 'first' : 'last';
mp-wp_genesis 290 var l=$('.'+which+'.page-numbers');
mp-wp_genesis 291 if (l.length)
mp-wp_genesis 292 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
mp-wp_genesis 293 }
mp-wp_genesis 294 };
mp-wp_genesis 295 var edit_comment = function(event, current_row) {
mp-wp_genesis 296 window.location = $('span.edit a', current_row).attr('href');
mp-wp_genesis 297 };
mp-wp_genesis 298 var toggle_all = function() {
mp-wp_genesis 299 toggleWithKeyboard = true;
mp-wp_genesis 300 var master_checkbox = $('form#comments-form .check-column :checkbox:first');
mp-wp_genesis 301 master_checkbox.click().attr('checked', '');
mp-wp_genesis 302 toggleWithKeyboard = false;
mp-wp_genesis 303 }
mp-wp_genesis 304 var make_bulk = function(value) {
mp-wp_genesis 305 return function(event, _) {
mp-wp_genesis 306 $('option[value='+value+']').attr('selected', 'selected');
mp-wp_genesis 307 $('form#comments-form')[0].submit();
mp-wp_genesis 308 }
mp-wp_genesis 309 };
mp-wp_genesis 310 $.table_hotkeys($('table.widefat'),['a', 'u', 's', 'd', 'r', 'q', ['e', edit_comment],
mp-wp_genesis 311 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')],
mp-wp_genesis 312 ['shift+d', make_bulk('delete')], ['shift+x', toggle_all],
mp-wp_genesis 313 ['shift+u', make_bulk('unapprove')]],
mp-wp_genesis 314 {highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
mp-wp_genesis 315 prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next')}
mp-wp_genesis 316 );
mp-wp_genesis 317 }
mp-wp_genesis 318 });
mp-wp_genesis 319
mp-wp_genesis 320 })(jQuery);