+ theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
+
+ refillTheExtraList();
+ };
+
+ refillTheExtraList = function(ev) {
+ var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val();
+
+ if (! args.paged)
+ args.paged = 1;
+
+ if (args.paged > total_pages) {
+ return;
+ }
+
+ if (ev) {
+ theExtraList.empty();
+ args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php
+ } else {
+ args.number = 1;
+ args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list
+ }
+
+ args.no_placeholder = true;
+
+ args.paged ++;
+
+ // $.query.get() needs some correction to be sent into an ajax request
+ if ( true === args.comment_type )
+ args.comment_type = '';
+
+ args = $.extend(args, {
+ 'action': 'fetch-list',
+ 'list_args': list_args,
+ '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val()
+ });
+
+ $.ajax({
+ url: ajaxurl,
+ global: false,
+ dataType: 'json',
+ data: args,
+ success: function(response) {
+ theExtraList.get(0).wpList.add( response.rows );
+ }
+ });
+ };
+
+ theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
+ theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
+ .bind('wpListDelEnd', function(e, s){
+ var wpListsData = $(s.target).attr('data-wp-lists'), id = s.element.replace(/[^0-9]+/g, '');
+
+ if ( wpListsData.indexOf(':trash=1') != -1 || wpListsData.indexOf(':spam=1') != -1 )
+ $('#undo-' + id).fadeIn(300, function(){ $(this).show() });
+ });
+};
+
+commentReply = {
+ cid : '',
+ act : '',
+
+ init : function() {
+ var row = $('#replyrow');
+
+ $('a.cancel', row).click(function() { return commentReply.revert(); });
+ $('a.save', row).click(function() { return commentReply.send(); });
+ $('input#author, input#author-email, input#author-url', row).keypress(function(e){
+ if ( e.which == 13 ) {
+ commentReply.send();
+ e.preventDefault();
+ return false;
+ }
+ });
+
+ // add events
+ $('#the-comment-list .column-comment > p').dblclick(function(){
+ commentReply.toggle($(this).parent());
+ });
+
+ $('#doaction, #doaction2, #post-query-submit').click(function(e){
+ if ( $('#the-comment-list #replyrow').length > 0 )
+ commentReply.close();
+ });
+
+ this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
+
+ /* $(listTable).bind('beforeChangePage', function(){
+ commentReply.close();
+ }); */
+ },
+
+ addEvents : function(r) {
+ r.each(function() {
+ $(this).find('.column-comment > p').dblclick(function(){
+ commentReply.toggle($(this).parent());
+ });
+ });
+ },
+
+ toggle : function(el) {
+ if ( $(el).css('display') != 'none' )
+ $(el).find('a.vim-q').click();
+ },
+
+ revert : function() {
+
+ if ( $('#the-comment-list #replyrow').length < 1 )
+ return false;
+
+ $('#replyrow').fadeOut('fast', function(){
+ commentReply.close();
+ });
+
+ return false;
+ },
+
+ close : function() {
+ var c, replyrow = $('#replyrow');
+
+ // replyrow is not showing?
+ if ( replyrow.parent().is('#com-reply') )
+ return;
+
+ if ( this.cid && this.act == 'edit-comment' ) {
+ c = $('#comment-' + this.cid);
+ c.fadeIn(300, function(){ c.show() }).css('backgroundColor', '');
+ }
+
+ // reset the Quicktags buttons
+ if ( typeof QTags != 'undefined' )
+ QTags.closeAllTags('replycontent');
+
+ $('#add-new-comment').css('display', '');
+
+ replyrow.hide();
+ $('#com-reply').append( replyrow );
+ $('#replycontent').css('height', '').val('');
+ $('#edithead input').val('');
+ $('.error', replyrow).html('').hide();
+ $('.spinner', replyrow).hide();
+
+ this.cid = '';
+ },
+
+ open : function(comment_id, post_id, action) {
+ var t = this, editRow, rowData, act, c = $('#comment-' + comment_id), h = c.height(), replyButton;
+
+ t.close();
+ t.cid = comment_id;
+
+ editRow = $('#replyrow');
+ rowData = $('#inline-'+comment_id);
+ action = action || 'replyto';
+ act = 'edit' == action ? 'edit' : 'replyto';
+ act = t.act = act + '-comment';
+
+ $('#action', editRow).val(act);
+ $('#comment_post_ID', editRow).val(post_id);
+ $('#comment_ID', editRow).val(comment_id);
+
+ if ( h > 120 )
+ $('#replycontent', editRow).css('height', (35+h) + 'px');
+
+ if ( action == 'edit' ) {
+ $('#author', editRow).val( $('div.author', rowData).text() );
+ $('#author-email', editRow).val( $('div.author-email', rowData).text() );
+ $('#author-url', editRow).val( $('div.author-url', rowData).text() );
+ $('#status', editRow).val( $('div.comment_status', rowData).text() );
+ $('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
+ $('#edithead, #savebtn', editRow).show();
+ $('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide();
+
+ c.after( editRow ).fadeOut('fast', function(){
+ $('#replyrow').fadeIn(300, function(){ $(this).show() });
+ });
+ } else if ( action == 'add' ) {
+ $('#addhead, #addbtn', editRow).show();
+ $('#replyhead, #replybtn, #edithead, #editbtn', editRow).hide();
+ $('#the-comment-list').prepend(editRow);
+ $('#replyrow').fadeIn(300);
+ } else {
+ replyButton = $('#replybtn', editRow);
+ $('#edithead, #savebtn, #addhead, #addbtn', editRow).hide();
+ $('#replyhead, #replybtn', editRow).show();
+ c.after(editRow);
+
+ if ( c.hasClass('unapproved') ) {
+ replyButton.text(adminCommentsL10n.replyApprove);
+ } else {
+ replyButton.text(adminCommentsL10n.reply);
+ }
+
+ $('#replyrow').fadeIn(300, function(){ $(this).show() });
+ }
+
+ setTimeout(function() {
+ var rtop, rbottom, scrollTop, vp, scrollBottom;
+
+ rtop = $('#replyrow').offset().top;
+ rbottom = rtop + $('#replyrow').height();
+ scrollTop = window.pageYOffset || document.documentElement.scrollTop;
+ vp = document.documentElement.clientHeight || self.innerHeight || 0;
+ scrollBottom = scrollTop + vp;
+
+ if ( scrollBottom - 20 < rbottom )
+ window.scroll(0, rbottom - vp + 35);
+ else if ( rtop - 20 < scrollTop )
+ window.scroll(0, rtop - 35);
+
+ $('#replycontent').focus().keyup(function(e){
+ if ( e.which == 27 )
+ commentReply.revert(); // close on Escape
+ });
+ }, 600);
+
+ return false;
+ },
+
+ send : function() {
+ var post = {};
+
+ $('#replysubmit .error').hide();
+ $('#replysubmit .spinner').show();
+
+ $('#replyrow input').not(':button').each(function() {
+ var t = $(this);
+ post[ t.attr('name') ] = t.val();
+ });
+
+ post.content = $('#replycontent').val();
+ post.id = post.comment_post_ID;
+ post.comments_listing = this.comments_listing;
+ post.p = $('[name="p"]').val();
+
+ if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') )
+ post.approve_parent = 1;
+
+ $.ajax({
+ type : 'POST',
+ url : ajaxurl,
+ data : post,
+ success : function(x) { commentReply.show(x); },
+ error : function(r) { commentReply.error(r); }
+ });
+
+ return false;
+ },
+
+ show : function(xml) {
+ var t = this, r, c, id, bg, pid;
+
+ if ( typeof(xml) == 'string' ) {
+ t.error({'responseText': xml});
+ return false;
+ }
+
+ r = wpAjax.parseAjaxResponse(xml);
+ if ( r.errors ) {
+ t.error({'responseText': wpAjax.broken});
+ return false;
+ }
+
+ t.revert();
+
+ r = r.responses[0];
+ id = '#comment-' + r.id;
+
+ if ( 'edit-comment' == t.act )
+ $(id).remove();
+
+ if ( r.supplemental.parent_approved ) {
+ pid = $('#comment-' + r.supplemental.parent_approved);
+ updatePending( -1 );
+
+ if ( this.comments_listing == 'moderated' ) {
+ pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){
+ pid.fadeOut();
+ });
+ return;
+ }
+ }
+
+ c = $.trim(r.data); // Trim leading whitespaces
+ $(c).hide()
+ $('#replyrow').after(c);
+
+ id = $(id);
+ t.addEvents(id);
+ bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor');
+
+ id.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
+ .animate( { 'backgroundColor': bg }, 300, function() {
+ if ( pid && pid.length ) {
+ pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
+ .animate( { 'backgroundColor': bg }, 300 )
+ .removeClass('unapproved').addClass('approved')
+ .find('div.comment_status').html('1');
+ }
+ });
+
+ },
+
+ error : function(r) {
+ var er = r.statusText;
+
+ $('#replysubmit .spinner').hide();
+
+ if ( r.responseText )
+ er = r.responseText.replace( /<.[^<>]*?>/g, '' );
+
+ if ( er )
+ $('#replysubmit .error').html(er).show();
+
+ },
+
+ addcomment: function(post_id) {
+ var t = this;
+
+ $('#add-new-comment').fadeOut(200, function(){
+ t.open(0, post_id, 'add');
+ $('table.comments-box').css('display', '');
+ $('#no-comments').remove();
+ });