+ /* $(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 editRow, rowData, act, replyButton, editHeight,
+ t = this,
+ c = $('#comment-' + comment_id),
+ h = c.height();
+
+ 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 ( 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();
+
+ if ( h > 120 ) {
+ // Limit the maximum height when editing very long comments to make it more manageable.
+ // The textarea is resizable in most browsers, so the user can adjust it if needed.
+ editHeight = h > 500 ? 500 : h;
+ $('#replycontent', editRow).css('height', editHeight + 'px');
+ }
+
+ 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 || window.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();
+ });