2008-02-28 01:50:25 -05:00
|
|
|
var theList; var theExtraList;
|
2008-08-29 01:07:40 -04:00
|
|
|
(function($) {
|
|
|
|
|
|
|
|
setCommentsList = function() {
|
|
|
|
var dimAfter = function( r, settings ) {
|
|
|
|
$('li span.comment-count').each( function() {
|
|
|
|
var a = $(this);
|
|
|
|
var n = parseInt(a.html(),10);
|
|
|
|
n = n + ( $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1 );
|
|
|
|
if ( n < 0 ) { n = 0; }
|
|
|
|
a.html( n.toString() );
|
|
|
|
$('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
|
|
|
|
});
|
|
|
|
$('.post-com-count span.comment-count').each( function() {
|
|
|
|
var a = $(this);
|
|
|
|
var n = parseInt(a.html(),10);
|
2008-03-04 12:07:47 -05:00
|
|
|
var t = parseInt(a.parent().attr('title'), 10);
|
2008-08-29 01:07:40 -04:00
|
|
|
if ( $('#' + settings.element).is('.unapproved') ) { // we unapproved a formerly approved comment
|
|
|
|
n = n - 1;
|
|
|
|
t = t + 1;
|
|
|
|
} else { // we approved a formerly unapproved comment
|
|
|
|
n = n + 1;
|
|
|
|
t = t - 1;
|
|
|
|
}
|
|
|
|
if ( n < 0 ) { n = 0; }
|
|
|
|
if ( t < 0 ) { t = 0; }
|
|
|
|
if ( t >= 0 ) { a.parent().attr('title', adminCommentsL10n.pending.replace( /%i%/, t.toString() ) ); }
|
2008-03-04 12:07:47 -05:00
|
|
|
if ( 0 === t ) { a.parents('strong:first').replaceWith( a.parents('strong:first').html() ); }
|
2008-08-29 01:07:40 -04:00
|
|
|
a.html( n.toString() );
|
|
|
|
});
|
|
|
|
};
|
2008-10-07 21:18:16 -04:00
|
|
|
|
2008-08-29 01:07:40 -04:00
|
|
|
var delAfter = function( r, settings ) {
|
|
|
|
$('li span.comment-count').each( function() {
|
|
|
|
var a = $(this);
|
|
|
|
var n = parseInt(a.html(),10);
|
|
|
|
if ( $('#' + settings.element).is('.unapproved') ) { // we deleted a formerly unapproved comment
|
|
|
|
n = n - 1;
|
|
|
|
} else if ( $(settings.target).parents( 'span.unapprove' ).size() ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
|
|
|
|
n = n + 1;
|
|
|
|
}
|
|
|
|
if ( n < 0 ) { n = 0; }
|
|
|
|
a.html( n.toString() );
|
|
|
|
$('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
|
|
|
|
});
|
|
|
|
$('.post-com-count span.comment-count').each( function() {
|
|
|
|
var a = $(this);
|
|
|
|
if ( $('#' + settings.element).is('.unapproved') ) { // we deleted a formerly unapproved comment
|
|
|
|
var t = parseInt(a.parent().attr('title'), 10);
|
|
|
|
if ( t < 1 ) { return; }
|
|
|
|
t = t - 1;
|
|
|
|
a.parent().attr('title', adminCommentsL10n.pending.replace( /%i%/, t.toString() ) );
|
|
|
|
if ( 0 === t ) { a.parents('strong:first').replaceWith( a.parents('strong:first').html() ); }
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var n = parseInt(a.html(),10) - 1;
|
|
|
|
a.html( n.toString() );
|
|
|
|
});
|
|
|
|
$('li span.spam-comment-count' ).each( function() {
|
|
|
|
var a = $(this);
|
|
|
|
var n = parseInt(a.html(),10);
|
|
|
|
if ( $(settings.target).parents( 'span.spam' ).size() ) { // we marked a comment as spam
|
|
|
|
n = n + 1;
|
|
|
|
} else if ( $('#' + settings.element).is('.spam') ) { // we approved or deleted a comment marked as spam
|
|
|
|
n = n - 1;
|
|
|
|
}
|
|
|
|
if ( n < 0 ) { n = 0; }
|
|
|
|
a.html( n.toString() );
|
|
|
|
});
|
2008-10-07 21:18:16 -04:00
|
|
|
|
2008-08-29 01:07:40 -04:00
|
|
|
if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 ) {
|
2008-03-04 12:07:47 -05:00
|
|
|
return;
|
|
|
|
}
|
2008-10-07 21:18:16 -04:00
|
|
|
|
2008-08-29 01:07:40 -04:00
|
|
|
theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
|
|
|
|
$('#get-extra-comments').submit();
|
|
|
|
};
|
2007-03-27 17:20:16 -04:00
|
|
|
|
2008-08-29 01:07:40 -04:00
|
|
|
theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
|
|
|
|
theList = $('#the-comment-list').wpList( { alt: '', dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } );
|
2008-10-07 21:18:16 -04:00
|
|
|
|
2008-08-29 01:07:40 -04:00
|
|
|
};
|
2006-06-06 00:14:04 -04:00
|
|
|
|
2008-08-29 01:07:40 -04:00
|
|
|
$(document).ready(function(){
|
|
|
|
setCommentsList();
|
2008-08-24 02:56:22 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
commentReply = {
|
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
init : function() {
|
|
|
|
this.rows = $('#the-comment-list tr');
|
2008-10-16 18:35:53 -04:00
|
|
|
if ( !this.rows.size() )
|
|
|
|
this.rows = $('#the-comment-list > div.comment-item');
|
2008-10-07 21:18:16 -04:00
|
|
|
var row = $('#replyrow');
|
2008-08-24 02:56:22 -04:00
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
$('a.cancel', row).click(function() { return commentReply.revert(); });
|
|
|
|
$('a.save', row).click(function() { return commentReply.send(this); });
|
2008-08-24 02:56:22 -04:00
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
// add events
|
|
|
|
this.addEvents(this.rows);
|
|
|
|
|
|
|
|
$('#doaction, #doaction2, #post-query-submit').click(function(e){
|
|
|
|
if ( $('#the-comment-list #replyrow').length > 0 )
|
|
|
|
t.close();
|
2008-08-24 02:56:22 -04:00
|
|
|
});
|
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
addEvents : function(r) {
|
|
|
|
r.each(function() {
|
|
|
|
$(this).dblclick(function(){
|
2008-10-23 12:34:21 -04:00
|
|
|
commentReply.toggle(this);
|
2008-10-07 21:18:16 -04:00
|
|
|
});
|
2008-08-24 02:56:22 -04:00
|
|
|
});
|
2008-10-07 21:18:16 -04:00
|
|
|
},
|
2008-08-24 02:56:22 -04:00
|
|
|
|
2008-10-23 12:34:21 -04:00
|
|
|
toggle : function(el) {
|
|
|
|
if ( $(el).css('display') != 'none' )
|
|
|
|
$(el).find('a.vim-q').click();
|
2008-10-07 21:18:16 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
revert : function() {
|
|
|
|
|
2008-10-23 12:34:21 -04:00
|
|
|
if ( $('#the-comment-list #replyrow').length < 1 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$('#replyrow').fadeOut('fast', function(){
|
|
|
|
commentReply.close();
|
|
|
|
});
|
2008-08-24 02:56:22 -04:00
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
return false;
|
2008-08-24 02:56:22 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
close : function() {
|
2008-10-07 21:18:16 -04:00
|
|
|
$(this.o).fadeIn('fast').css('backgroundColor', '');
|
|
|
|
$('#com-reply').append( $('#replyrow') );
|
2008-08-24 02:56:22 -04:00
|
|
|
$('#replycontent').val('');
|
2008-10-07 21:18:16 -04:00
|
|
|
$('#edithead input').val('');
|
|
|
|
$('#replysubmit .error').html('').hide();
|
|
|
|
$('#replysubmit .waiting').hide();
|
|
|
|
if ( $.browser.msie )
|
|
|
|
$('#replycontainer, #replycontent').css('height', '120px');
|
|
|
|
else
|
|
|
|
$('#replycontainer').resizable('destroy').css('height', '120px');
|
|
|
|
},
|
|
|
|
|
|
|
|
open : function(id, p, a) {
|
|
|
|
var t = this;
|
2008-10-23 12:34:21 -04:00
|
|
|
t.close();
|
2008-10-07 21:18:16 -04:00
|
|
|
t.o = '#comment-'+id;
|
|
|
|
|
2008-10-17 05:44:22 -04:00
|
|
|
$('#replyrow td').attr('colspan', $('.widefat thead th:visible').length);
|
2008-10-07 21:18:16 -04:00
|
|
|
var editRow = $('#replyrow'), rowData = $('#inline-'+id);
|
|
|
|
var act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment';
|
|
|
|
|
|
|
|
$('#action', editRow).val(act);
|
|
|
|
$('#comment_post_ID', editRow).val(p);
|
|
|
|
$('#comment_ID', editRow).val(id);
|
|
|
|
|
|
|
|
if ( a == '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', editRow).hide();
|
|
|
|
|
|
|
|
var h = $(t.o).height();
|
|
|
|
if ( h > 220 )
|
|
|
|
if ( $.browser.msie )
|
|
|
|
$('#replycontainer, #replycontent', editRow).height(h-105);
|
|
|
|
else
|
|
|
|
$('#replycontainer', editRow).height(h-105);
|
|
|
|
|
|
|
|
$(t.o).after(editRow.hide()).fadeOut('fast', function(){
|
|
|
|
$('#replyrow').fadeIn('fast');
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$('#edithead, #savebtn', editRow).hide();
|
|
|
|
$('#replyhead, #replybtn', editRow).show();
|
|
|
|
$(t.o).after(editRow).animate( { backgroundColor: '#eefee7' }, 800);
|
|
|
|
$('#replyrow').hide().fadeIn('fast');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $.browser.msie )
|
|
|
|
$('#replycontainer').resizable({
|
|
|
|
handles : 's',
|
|
|
|
axis : 'y',
|
|
|
|
minHeight : 80,
|
|
|
|
stop : function() {
|
|
|
|
$('#replycontainer').width('auto');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
var rtop = $('#replyrow').offset().top;
|
|
|
|
var rbottom = rtop + $('#replyrow').height();
|
|
|
|
var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
|
|
|
var vp = document.documentElement.clientHeight || self.innerHeight || 0;
|
|
|
|
var 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);
|
2008-08-24 02:56:22 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
send : function() {
|
|
|
|
var post = {};
|
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
$('#replysubmit .waiting').show();
|
|
|
|
|
|
|
|
$('#replyrow input').each(function() {
|
2008-08-24 02:56:22 -04:00
|
|
|
post[ $(this).attr('name') ] = $(this).val();
|
|
|
|
});
|
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
post.content = $('#replycontent').val();
|
2008-08-24 02:56:22 -04:00
|
|
|
post.id = post.comment_post_ID;
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type : 'POST',
|
|
|
|
url : wpListL10n.url,
|
|
|
|
data : post,
|
|
|
|
success : function(x) { commentReply.show(x); },
|
|
|
|
error : function(r) { commentReply.error(r); }
|
|
|
|
});
|
2008-10-07 21:18:16 -04:00
|
|
|
|
|
|
|
return false;
|
2008-08-24 02:56:22 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
show : function(xml) {
|
|
|
|
|
|
|
|
if ( typeof(xml) == 'string' ) {
|
|
|
|
this.error({'responseText': xml});
|
2008-10-07 21:18:16 -04:00
|
|
|
return false;
|
2008-08-24 02:56:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var r = wpAjax.parseAjaxResponse(xml);
|
2008-10-07 21:18:16 -04:00
|
|
|
if ( r.errors ) {
|
2008-08-24 02:56:22 -04:00
|
|
|
this.error({'responseText': wpAjax.broken});
|
2008-10-07 21:18:16 -04:00
|
|
|
return false;
|
|
|
|
}
|
2008-08-24 02:56:22 -04:00
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
if ( 'edit-comment' == this.act )
|
|
|
|
$(this.o).remove();
|
2008-08-24 02:56:22 -04:00
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
r = r.responses[0];
|
|
|
|
var c = r.data;
|
2008-08-24 02:56:22 -04:00
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
$(c).hide()
|
|
|
|
$('#replyrow').after(c);
|
|
|
|
this.o = id = '#comment-'+r.id;
|
|
|
|
$(id+' .hide-if-no-js').removeClass('hide-if-no-js');
|
|
|
|
this.revert();
|
|
|
|
this.addEvents($(id));
|
2008-09-05 15:11:41 -04:00
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
$(id)
|
2008-09-05 15:11:41 -04:00
|
|
|
.animate( { backgroundColor:"#CCEEBB" }, 600 )
|
2008-08-24 02:56:22 -04:00
|
|
|
.animate( { backgroundColor:"transparent" }, 600 );
|
2008-10-07 21:18:16 -04:00
|
|
|
|
|
|
|
theList = theExtraList = null;
|
|
|
|
$("#get-extra-comments, a[className*=':']").unbind();
|
2008-08-29 01:07:40 -04:00
|
|
|
setCommentsList();
|
2008-10-07 21:18:16 -04:00
|
|
|
|
2008-08-24 02:56:22 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
error : function(r) {
|
|
|
|
var er = r.statusText;
|
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
$('#replysubmit .waiting').hide();
|
|
|
|
|
2008-08-24 02:56:22 -04:00
|
|
|
if ( r.responseText )
|
|
|
|
er = r.responseText.replace( /<.[^<>]*?>/g, '' );
|
|
|
|
|
2008-10-07 21:18:16 -04:00
|
|
|
if ( er )
|
|
|
|
$('#replysubmit .error').html(er).show();
|
2008-08-24 02:56:22 -04:00
|
|
|
|
|
|
|
}
|
2008-08-29 01:07:40 -04:00
|
|
|
};
|
2008-08-24 02:56:22 -04:00
|
|
|
|
|
|
|
$(document).ready(function(){
|
2008-09-25 21:05:52 -04:00
|
|
|
columns.init('comment');
|
2008-10-07 21:18:16 -04:00
|
|
|
commentReply.init();
|
2008-09-25 21:05:52 -04:00
|
|
|
|
2008-08-24 02:56:22 -04:00
|
|
|
if ( typeof QTags != 'undefined' )
|
|
|
|
ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more');
|
2008-09-05 15:11:41 -04:00
|
|
|
|
2008-09-01 01:28:41 -04:00
|
|
|
if ( typeof $.table_hotkeys != 'undefined' ) {
|
|
|
|
var make_hotkeys_redirect = function(which) {
|
|
|
|
return function() {
|
2008-10-07 21:18:16 -04:00
|
|
|
var first_last = 'next' == which? 'first' : 'last';
|
2008-09-01 01:28:41 -04:00
|
|
|
var l=$('.'+which+'.page-numbers');
|
|
|
|
if (l.length)
|
|
|
|
window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
|
|
|
|
}
|
2008-09-04 13:53:14 -04:00
|
|
|
};
|
|
|
|
var edit_comment = function(event, current_row) {
|
|
|
|
window.location = $('span.edit a', current_row).attr('href');
|
|
|
|
};
|
|
|
|
var toggle_all = function() {
|
|
|
|
var master_checkbox = $('form#comments-form .check-column :checkbox:first');
|
|
|
|
master_checkbox.attr('checked', master_checkbox.attr('checked')? '' : 'checked');
|
|
|
|
checkAll('form#comments-form');
|
2008-09-01 01:28:41 -04:00
|
|
|
}
|
2008-09-04 13:53:14 -04:00
|
|
|
var make_bulk = function(value) {
|
|
|
|
return function(event, _) {
|
|
|
|
$('option[value='+value+']').attr('selected', 'selected');
|
|
|
|
$('form#comments-form')[0].submit();
|
2008-09-01 01:28:41 -04:00
|
|
|
}
|
2008-09-04 13:53:14 -04:00
|
|
|
};
|
2008-10-23 12:34:21 -04:00
|
|
|
$.table_hotkeys($('table.widefat'),['a', 'u', 's', 'd', 'r', 'q', ['e', edit_comment],
|
2008-09-04 13:53:14 -04:00
|
|
|
['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')],
|
2008-10-16 18:23:32 -04:00
|
|
|
['shift+d', make_bulk('delete')], ['shift+x', toggle_all],
|
|
|
|
['shift+u', make_bulk('unapprove')]],
|
2008-09-04 13:53:14 -04:00
|
|
|
{highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
|
|
|
|
prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next')}
|
2008-09-01 01:28:41 -04:00
|
|
|
);
|
|
|
|
}
|
2008-08-24 02:56:22 -04:00
|
|
|
});
|
|
|
|
|
2008-09-05 15:11:41 -04:00
|
|
|
})(jQuery);
|