web/wp-admin/js/edit-comments.dev.js
changeset 194 32102edaa81b
parent 136 bde1974c263b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 var theList, theExtraList, toggleWithKeyboard = false;
     1 var theList, theExtraList, toggleWithKeyboard = false;
       
     2 
     2 (function($) {
     3 (function($) {
       
     4 var getCount, updateCount, updatePending, dashboardTotals;
     3 
     5 
     4 setCommentsList = function() {
     6 setCommentsList = function() {
     5 	var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter;
     7 	var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList;
     6 
     8 
     7 	totalInput = $('.tablenav input[name="_total"]', '#comments-form');
     9 	totalInput = $('input[name="_total"]', '#comments-form');
     8 	perPageInput = $('.tablenav input[name="_per_page"]', '#comments-form');
    10 	perPageInput = $('input[name="_per_page"]', '#comments-form');
     9 	pageInput = $('.tablenav input[name="_page"]', '#comments-form');
    11 	pageInput = $('input[name="_page"]', '#comments-form');
    10 
    12 
    11 	dimAfter = function( r, settings ) {
    13 	dimAfter = function( r, settings ) {
    12 		var c = $('#' + settings.element);
    14 		var c = $('#' + settings.element), editRow, replyID, replyButton;
    13 
    15 
    14 		if ( c.is('.unapproved') )
    16 		editRow = $('#replyrow');
    15 			c.find('div.comment_status').html('0')
    17 		replyID = $('#comment_ID', editRow).val();
    16 		else
    18 		replyButton = $('#replybtn', editRow);
    17 			c.find('div.comment_status').html('1')
    19 
    18 
    20 		if ( c.is('.unapproved') ) {
    19 		$('span.pending-count').each( function() {
    21 			if ( settings.data.id == replyID )
    20 			var a = $(this), n, dif;
    22 				replyButton.text(adminCommentsL10n.replyApprove);
    21 			n = a.html().replace(/[^0-9]+/g, '');
    23 
    22 			n = parseInt(n,10);
    24 			c.find('div.comment_status').html('0');
    23 			if ( isNaN(n) ) return;
    25 		} else {
    24 			dif = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
    26 			if ( settings.data.id == replyID )
    25 			n = n + dif;
    27 				replyButton.text(adminCommentsL10n.reply);
    26 			if ( n < 0 ) { n = 0; }
    28 
    27 			a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
    29 			c.find('div.comment_status').html('1');
    28 			updateCount(a, n);
    30 		}
    29 			dashboardTotals();
    31 
    30 		});
    32 		var diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
       
    33 		updatePending( diff );
    31 	};
    34 	};
    32 
    35 
    33 	// Send current total, page, per_page and url
    36 	// Send current total, page, per_page and url
    34 	delBefore = function( settings, list ) {
    37 	delBefore = function( settings, list ) {
    35 		var cl = $(settings.target).attr('className'), id, el, n, h, a, author, action = false;
    38 		var cl = $(settings.target).attr('class'), id, el, n, h, a, author, action = false;
    36 
    39 
    37 		settings.data._total = totalInput.val() || 0;
    40 		settings.data._total = totalInput.val() || 0;
    38 		settings.data._per_page = perPageInput.val() || 0;
    41 		settings.data._per_page = perPageInput.val() || 0;
    39 		settings.data._page = pageInput.val() || 0;
    42 		settings.data._page = pageInput.val() || 0;
    40 		settings.data._url = document.location.href;
    43 		settings.data._url = document.location.href;
       
    44 		settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val();
    41 
    45 
    42 		if ( cl.indexOf(':trash=1') != -1 )
    46 		if ( cl.indexOf(':trash=1') != -1 )
    43 			action = 'trash';
    47 			action = 'trash';
    44 		else if ( cl.indexOf(':spam=1') != -1 )
    48 		else if ( cl.indexOf(':spam=1') != -1 )
    45 			action = 'spam';
    49 			action = 'spam';
    46 
    50 
    47 		if ( action ) {
    51 		if ( action ) {
    48 			id = cl.replace(/.*?comment-([0-9]+).*/, '$1');
    52 			id = cl.replace(/.*?comment-([0-9]+).*/, '$1');
    49 			el = $('#comment-' + id);
    53 			el = $('#comment-' + id);
    50 			note = $('#' + action + '-undo-holder').html();
    54 			note = $('#' + action + '-undo-holder').html();
       
    55 
       
    56 			el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits.
    51 
    57 
    52 			if ( el.siblings('#replyrow').length && commentReply.cid == id )
    58 			if ( el.siblings('#replyrow').length && commentReply.cid == id )
    53 				commentReply.close();
    59 				commentReply.close();
    54 
    60 
    55 			if ( el.is('tr') ) {
    61 			if ( el.is('tr') ) {
    61 				h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
    67 				h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
    62 			}
    68 			}
    63 
    69 
    64 			el.before(h);
    70 			el.before(h);
    65 
    71 
    66 			$('strong', '#undo-' + id).text(author + ' ');
    72 			$('strong', '#undo-' + id).text(author);
    67 			a = $('.undo a', '#undo-' + id);
    73 			a = $('.undo a', '#undo-' + id);
    68 			a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
    74 			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');
    75 			a.attr('class', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1 vim-z vim-destructive');
    70 			$('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
    76 			$('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
    71 
    77 
    72 			a.click(function(){
    78 			a.click(function(){
    73 				list.wpList.del(this);
    79 				list.wpList.del(this);
    74 				$('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
    80 				$('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
    80 		}
    86 		}
    81 
    87 
    82 		return settings;
    88 		return settings;
    83 	};
    89 	};
    84 
    90 
    85 	// Updates the current total (as displayed visibly)
    91 	// Updates the current total (stored in the _total input)
    86 	updateTotalCount = function( total, time, setConfidentTime ) {
    92 	updateTotalCount = function( total, time, setConfidentTime ) {
    87 		if ( time < lastConfidentTime )
    93 		if ( time < lastConfidentTime )
    88 			return;
    94 			return;
    89 
    95 
    90 		if ( setConfidentTime )
    96 		if ( setConfidentTime )
    91 			lastConfidentTime = time;
    97 			lastConfidentTime = time;
    92 
    98 
    93 		totalInput.val( total.toString() );
    99 		totalInput.val( total.toString() );
    94 		$('span.total-type-count').each( function() {
   100 	};
    95 			updateCount( $(this), total );
   101 
    96 		});
   102 	dashboardTotals = function(n) {
    97 	};
       
    98 
       
    99 	function dashboardTotals(n) {
       
   100 		var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
   103 		var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
   101 
   104 
   102 		n = n || 0;
   105 		n = n || 0;
   103 		if ( isNaN(n) || !dash.length )
   106 		if ( isNaN(n) || !dash.length )
   104 			return;
   107 			return;
   109 
   112 
   110 		totalN = totalN + n;
   113 		totalN = totalN + n;
   111 		apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) );
   114 		apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) );
   112 		updateCount(total, totalN);
   115 		updateCount(total, totalN);
   113 		updateCount(appr, apprN);
   116 		updateCount(appr, apprN);
   114 
   117 	};
   115 	}
   118 
   116 
   119 	getCount = function(el) {
   117 	function getCount(el) {
       
   118 		var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
   120 		var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
   119 		if ( isNaN(n) )
   121 		if ( isNaN(n) )
   120 			return 0;
   122 			return 0;
   121 		return n;
   123 		return n;
   122 	}
   124 	};
   123 
   125 
   124 	function updateCount(el, n) {
   126 	updateCount = function(el, n) {
   125 		var n1 = '';
   127 		var n1 = '';
   126 		if ( isNaN(n) )
   128 		if ( isNaN(n) )
   127 			return;
   129 			return;
   128 		n = n < 1 ? '0' : n.toString();
   130 		n = n < 1 ? '0' : n.toString();
   129 		if ( n.length > 3 ) {
   131 		if ( n.length > 3 ) {
   132 				n = n.substr(0, n.length - 3);
   134 				n = n.substr(0, n.length - 3);
   133 			}
   135 			}
   134 			n = n + n1;
   136 			n = n + n1;
   135 		}
   137 		}
   136 		el.html(n);
   138 		el.html(n);
   137 	}
   139 	};
       
   140 
       
   141 	updatePending = function( diff ) {
       
   142 		$('span.pending-count').each(function() {
       
   143 			var a = $(this), n = getCount(a) + diff;
       
   144 			if ( n < 1 )
       
   145 				n = 0;
       
   146 			a.closest('.awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
       
   147 			updateCount( a, n );
       
   148 		});
       
   149 
       
   150 		dashboardTotals();
       
   151 	};
   138 
   152 
   139 	// In admin-ajax.php, we send back the unix time stamp instead of 1 on success
   153 	// In admin-ajax.php, we send back the unix time stamp instead of 1 on success
   140 	delAfter = function( r, settings ) {
   154 	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;
   155 		var total, N, spam, trash, pending,
       
   156 			untrash = $(settings.target).parent().is('span.untrash'),
       
   157 			unspam = $(settings.target).parent().is('span.unspam'),
       
   158 			unapproved = $('#' + settings.element).is('.unapproved');
   142 
   159 
   143 		function getUpdate(s) {
   160 		function getUpdate(s) {
   144 			if ( $(settings.target).parent().is('span.' + s) )
   161 			if ( $(settings.target).parent().is('span.' + s) )
   145 				return 1;
   162 				return 1;
   146 			else if ( $('#' + settings.element).is('.' + s) )
   163 			else if ( $('#' + settings.element).is('.' + s) )
   147 				return -1;
   164 				return -1;
   148 
   165 
   149 			return 0;
   166 			return 0;
   150 		}
   167 		}
   151 		spam = getUpdate('spam');
       
   152 		trash = getUpdate('trash');
       
   153 
   168 
   154 		if ( untrash )
   169 		if ( untrash )
   155 			trash = -1;
   170 			trash = -1;
       
   171 		else
       
   172 			trash = getUpdate('trash');
       
   173 
   156 		if ( unspam )
   174 		if ( unspam )
   157 			spam = -1;
   175 			spam = -1;
   158 
   176 		else
   159 		$('span.pending-count').each( function() {
   177 			spam = getUpdate('spam');
   160 			var a = $(this), n = getCount(a), unapproved = $('#' + settings.element).is('.unapproved');
   178 
   161 
   179 		if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) {
   162 			if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
   180 			// a comment was 'deleted' from another list (e.g. approved, spam, trash) and moved to pending,
   163 				n = n + 1;
   181 			// or a trash/spam of a pending comment was undone
   164 			} else if ( unapproved ) { // we deleted a formerly unapproved comment
   182 			pending = 1;
   165 				n = n - 1;
   183 		} else if ( unapproved ) {
   166 			}
   184 			// a pending comment was trashed/spammed/approved
   167 			if ( n < 0 ) { n = 0; }
   185 			pending = -1;
   168 			a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
   186 		}
   169 			updateCount(a, n);
   187 
   170 			dashboardTotals();
   188 		if ( pending )
   171 		});
   189 			updatePending(pending);
   172 
   190 
   173 		$('span.spam-count').each( function() {
   191 		$('span.spam-count').each( function() {
   174 			var a = $(this), n = getCount(a) + spam;
   192 			var a = $(this), n = getCount(a) + spam;
   175 			updateCount(a, n);
   193 			updateCount(a, n);
   176 		});
   194 		});
   183 		if ( $('#dashboard_right_now').length ) {
   201 		if ( $('#dashboard_right_now').length ) {
   184 			N = trash ? -1 * trash : 0;
   202 			N = trash ? -1 * trash : 0;
   185 			dashboardTotals(N);
   203 			dashboardTotals(N);
   186 		} else {
   204 		} else {
   187 			total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
   205 			total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
   188 			total = total - spam - trash;
   206 			if ( $(settings.target).parent().is('span.undo') )
       
   207 				total++;
       
   208 			else
       
   209 				total--;
       
   210 
   189 			if ( total < 0 )
   211 			if ( total < 0 )
   190 				total = 0;
   212 				total = 0;
   191 
   213 
   192 			if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
   214 			if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
   193 				pageLinks = settings.parsed.responses[0].supplemental.pageLinks || '';
   215 				total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
   194 				if ( $.trim( pageLinks ) )
   216 				if ( total_items_i18n ) {
   195 					$('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( pageLinks ) );
   217 					$('.displaying-num').text( total_items_i18n );
   196 				else
   218 					$('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
   197 					$('.tablenav-pages').find( '.page-numbers' ).remove();
   219 					$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
   198 
   220 				}
   199 				updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
   221 				updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
   200 			} else {
   222 			} else {
   201 				updateTotalCount( total, r, false );
   223 				updateTotalCount( total, r, false );
   202 			}
   224 			}
   203 		}
   225 		}
   204 
   226 
   205 		if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash ) {
   227 		if ( ! theExtraList || theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash || unspam ) {
   206 			return;
   228 			return;
   207 		}
   229 		}
   208 
   230 
   209 		theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
   231 		theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
   210 		$('#get-extra-comments').submit();
   232 
       
   233 		refillTheExtraList();
       
   234 	};
       
   235 
       
   236 	refillTheExtraList = function(ev) {
       
   237 		var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val();
       
   238 
       
   239 		if (! args.paged)
       
   240 			args.paged = 1;
       
   241 
       
   242 		if (args.paged > total_pages) {
       
   243 			return;
       
   244 		}
       
   245 
       
   246 		if (ev) {
       
   247 			theExtraList.empty();
       
   248 			args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php
       
   249 		} else {
       
   250 			args.number = 1;
       
   251 			args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list
       
   252 		}
       
   253 
       
   254 		args.no_placeholder = true;
       
   255 
       
   256 		args.paged ++;
       
   257 
       
   258 		// $.query.get() needs some correction to be sent into an ajax request
       
   259 		if ( true === args.comment_type )
       
   260 			args.comment_type = '';
       
   261 
       
   262 		args = $.extend(args, {
       
   263 			'action': 'fetch-list',
       
   264 			'list_args': list_args,
       
   265 			'_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val()
       
   266 		});
       
   267 
       
   268 		$.ajax({
       
   269 			url: ajaxurl,
       
   270 			global: false,
       
   271 			dataType: 'json',
       
   272 			data: args,
       
   273 			success: function(response) {
       
   274 				theExtraList.get(0).wpList.add( response.rows );
       
   275 			}
       
   276 		});
   211 	};
   277 	};
   212 
   278 
   213 	theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
   279 	theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
   214 	theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
   280 	theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
   215 		.bind('wpListDelEnd', function(e, s){
   281 		.bind('wpListDelEnd', function(e, s){
   247 				commentReply.close();
   313 				commentReply.close();
   248 		});
   314 		});
   249 
   315 
   250 		this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
   316 		this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
   251 
   317 
       
   318 		/* $(listTable).bind('beforeChangePage', function(){
       
   319 			commentReply.close();
       
   320 		}); */
   252 	},
   321 	},
   253 
   322 
   254 	addEvents : function(r) {
   323 	addEvents : function(r) {
   255 		r.each(function() {
   324 		r.each(function() {
   256 			$(this).find('.column-comment > p').dblclick(function(){
   325 			$(this).find('.column-comment > p').dblclick(function(){
   275 
   344 
   276 		return false;
   345 		return false;
   277 	},
   346 	},
   278 
   347 
   279 	close : function() {
   348 	close : function() {
   280 		var c;
   349 		var c, replyrow = $('#replyrow');
   281 
   350 
   282 		if ( this.cid ) {
   351 		// replyrow is not showing?
       
   352 		if ( replyrow.parent().is('#com-reply') )
       
   353 			return;
       
   354 
       
   355 		if ( this.cid && this.act == 'edit-comment' ) {
   283 			c = $('#comment-' + this.cid);
   356 			c = $('#comment-' + this.cid);
   284 
   357 			c.fadeIn(300, function(){ c.show() }).css('backgroundColor', '');
   285 			if ( this.act == 'edit-comment' )
   358 		}
   286 				c.fadeIn(300, function(){ c.show() }).css('backgroundColor', '');
   359 
   287 
   360 		// reset the Quicktags buttons
   288 			$('#replyrow').hide();
   361 		if ( typeof QTags != 'undefined' )
   289 			$('#com-reply').append( $('#replyrow') );
   362 			QTags.closeAllTags('replycontent');
   290 			$('#replycontent').val('');
   363 
   291 			$('input', '#edithead').val('');
   364 		$('#add-new-comment').css('display', '');
   292 			$('.error', '#replysubmit').html('').hide();
   365 
   293 			$('.waiting', '#replysubmit').hide();
   366 		replyrow.hide();
   294 
   367 		$('#com-reply').append( replyrow );
   295 			if ( $.browser.msie )
   368 		$('#replycontent').css('height', '').val('');
   296 				$('#replycontainer, #replycontent').css('height', '120px');
   369 		$('#edithead input').val('');
   297 			else
   370 		$('.error', replyrow).html('').hide();
   298 				$('#replycontainer').resizable('destroy').css('height', '120px');
   371 		$('.waiting', replyrow).hide();
   299 
   372 
   300 			this.cid = '';
   373 		this.cid = '';
   301 		}
   374 	},
   302 	},
   375 
   303 
   376 	open : function(comment_id, post_id, action) {
   304 	open : function(id, p, a) {
   377 		var t = this, editRow, rowData, act, c = $('#comment-' + comment_id), h = c.height(), replyButton;
   305 		var t = this, editRow, rowData, act, h, c = $('#comment-' + id);
   378 
   306 		t.close();
   379 		t.close();
   307 		t.cid = id;
   380 		t.cid = comment_id;
   308 
   381 
   309 		$('td', '#replyrow').attr('colspan', $('table.widefat thead th:visible').length);
       
   310 		editRow = $('#replyrow');
   382 		editRow = $('#replyrow');
   311 		rowData = $('#inline-'+id);
   383 		rowData = $('#inline-'+comment_id);
   312 		act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment';
   384 		action = action || 'replyto';
       
   385 		act = 'edit' == action ? 'edit' : 'replyto';
       
   386 		act = t.act = act + '-comment';
   313 
   387 
   314 		$('#action', editRow).val(act);
   388 		$('#action', editRow).val(act);
   315 		$('#comment_post_ID', editRow).val(p);
   389 		$('#comment_post_ID', editRow).val(post_id);
   316 		$('#comment_ID', editRow).val(id);
   390 		$('#comment_ID', editRow).val(comment_id);
   317 
   391 
   318 		if ( a == 'edit' ) {
   392 		if ( h > 120 )
       
   393 			$('#replycontent', editRow).css('height', (35+h) + 'px');
       
   394 
       
   395 		if ( action == 'edit' ) {
   319 			$('#author', editRow).val( $('div.author', rowData).text() );
   396 			$('#author', editRow).val( $('div.author', rowData).text() );
   320 			$('#author-email', editRow).val( $('div.author-email', rowData).text() );
   397 			$('#author-email', editRow).val( $('div.author-email', rowData).text() );
   321 			$('#author-url', editRow).val( $('div.author-url', rowData).text() );
   398 			$('#author-url', editRow).val( $('div.author-url', rowData).text() );
   322 			$('#status', editRow).val( $('div.comment_status', rowData).text() );
   399 			$('#status', editRow).val( $('div.comment_status', rowData).text() );
   323 			$('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
   400 			$('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
   324 			$('#edithead, #savebtn', editRow).show();
   401 			$('#edithead, #savebtn', editRow).show();
   325 			$('#replyhead, #replybtn', editRow).hide();
   402 			$('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide();
   326 
       
   327 			h = c.height();
       
   328 			if ( h > 220 )
       
   329 				if ( $.browser.msie )
       
   330 					$('#replycontainer, #replycontent', editRow).height(h-105);
       
   331 				else
       
   332 					$('#replycontainer', editRow).height(h-105);
       
   333 
   403 
   334 			c.after( editRow ).fadeOut('fast', function(){
   404 			c.after( editRow ).fadeOut('fast', function(){
   335 				$('#replyrow').fadeIn(300, function(){ $(this).show() });
   405 				$('#replyrow').fadeIn(300, function(){ $(this).show() });
   336 			});
   406 			});
   337 		} else {
   407 		} else if ( action == 'add' ) {
   338 			$('#edithead, #savebtn', editRow).hide();
   408 			$('#addhead, #addbtn', editRow).show();
       
   409 			$('#replyhead, #replybtn, #edithead, #editbtn', editRow).hide();
       
   410 			$('#the-comment-list').prepend(editRow);
       
   411 			$('#replyrow').fadeIn(300);
       
   412  		} else {
       
   413  			replyButton = $('#replybtn', editRow);
       
   414 			$('#edithead, #savebtn, #addhead, #addbtn', editRow).hide();
   339 			$('#replyhead, #replybtn', editRow).show();
   415 			$('#replyhead, #replybtn', editRow).show();
   340 			c.after(editRow);
   416 			c.after(editRow);
       
   417 
       
   418 			if ( c.hasClass('unapproved') ) {
       
   419 				replyButton.text(adminCommentsL10n.replyApprove);
       
   420 			} else {
       
   421 				replyButton.text(adminCommentsL10n.reply);
       
   422 			}
       
   423 
   341 			$('#replyrow').fadeIn(300, function(){ $(this).show() });
   424 			$('#replyrow').fadeIn(300, function(){ $(this).show() });
   342 		}
   425 		}
   343 
       
   344 		if ( ! $.browser.msie )
       
   345 			$('#replycontainer').resizable({
       
   346 				handles : 's',
       
   347 				axis : 'y',
       
   348 				minHeight : 80,
       
   349 				stop : function() {
       
   350 					$('#replycontainer').width('auto');
       
   351 				}
       
   352 			});
       
   353 
   426 
   354 		setTimeout(function() {
   427 		setTimeout(function() {
   355 			var rtop, rbottom, scrollTop, vp, scrollBottom;
   428 			var rtop, rbottom, scrollTop, vp, scrollBottom;
   356 
   429 
   357 			rtop = $('#replyrow').offset().top;
   430 			rtop = $('#replyrow').offset().top;
   375 	},
   448 	},
   376 
   449 
   377 	send : function() {
   450 	send : function() {
   378 		var post = {};
   451 		var post = {};
   379 
   452 
       
   453 		$('#replysubmit .error').hide();
   380 		$('#replysubmit .waiting').show();
   454 		$('#replysubmit .waiting').show();
   381 
   455 
   382 		$('#replyrow input').each(function() {
   456 		$('#replyrow input').not(':button').each(function() {
   383 			post[ $(this).attr('name') ] = $(this).val();
   457 			var t = $(this);
       
   458 			post[ t.attr('name') ] = t.val();
   384 		});
   459 		});
   385 
   460 
   386 		post.content = $('#replycontent').val();
   461 		post.content = $('#replycontent').val();
   387 		post.id = post.comment_post_ID;
   462 		post.id = post.comment_post_ID;
   388 		post.comments_listing = this.comments_listing;
   463 		post.comments_listing = this.comments_listing;
       
   464 		post.p = $('[name="p"]').val();
       
   465 
       
   466 		if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') )
       
   467 			post.approve_parent = 1;
   389 
   468 
   390 		$.ajax({
   469 		$.ajax({
   391 			type : 'POST',
   470 			type : 'POST',
   392 			url : ajaxurl,
   471 			url : ajaxurl,
   393 			data : post,
   472 			data : post,
   397 
   476 
   398 		return false;
   477 		return false;
   399 	},
   478 	},
   400 
   479 
   401 	show : function(xml) {
   480 	show : function(xml) {
   402 		var r, c, id, bg;
   481 		var t = this, r, c, id, bg, pid;
   403 
   482 
   404 		if ( typeof(xml) == 'string' ) {
   483 		if ( typeof(xml) == 'string' ) {
   405 			this.error({'responseText': xml});
   484 			t.error({'responseText': xml});
   406 			return false;
   485 			return false;
   407 		}
   486 		}
   408 
   487 
   409 		r = wpAjax.parseAjaxResponse(xml);
   488 		r = wpAjax.parseAjaxResponse(xml);
   410 		if ( r.errors ) {
   489 		if ( r.errors ) {
   411 			this.error({'responseText': wpAjax.broken});
   490 			t.error({'responseText': wpAjax.broken});
   412 			return false;
   491 			return false;
   413 		}
   492 		}
       
   493 
       
   494 		t.revert();
   414 
   495 
   415 		r = r.responses[0];
   496 		r = r.responses[0];
   416 		c = r.data;
   497 		c = r.data;
   417 		id = '#comment-' + r.id;
   498 		id = '#comment-' + r.id;
   418 		if ( 'edit-comment' == this.act )
   499 
       
   500 		if ( 'edit-comment' == t.act )
   419 			$(id).remove();
   501 			$(id).remove();
       
   502 
       
   503 		if ( r.supplemental.parent_approved ) {
       
   504 			pid = $('#comment-' + r.supplemental.parent_approved);
       
   505 			updatePending( -1 );
       
   506 
       
   507 			if ( this.comments_listing == 'moderated' ) {
       
   508 				pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){
       
   509 					pid.fadeOut();
       
   510 				});
       
   511 				return;
       
   512 			}
       
   513 		}
   420 
   514 
   421 		$(c).hide()
   515 		$(c).hide()
   422 		$('#replyrow').after(c);
   516 		$('#replyrow').after(c);
   423 
   517 		id = $(id);
   424 		this.revert();
   518 		t.addEvents(id);
   425 		this.addEvents($(id));
   519 		bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor');
   426 		bg = $(id).hasClass('unapproved') ? '#ffffe0' : '#fff';
   520 
   427 
   521 		id.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
   428 		$(id)
   522 			.animate( { 'backgroundColor': bg }, 300, function() {
   429 			.animate( { 'backgroundColor':'#CCEEBB' }, 600 )
   523 				if ( pid && pid.length ) {
   430 			.animate( { 'backgroundColor': bg }, 600 );
   524 					pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
   431 
   525 						.animate( { 'backgroundColor': bg }, 300 )
   432 		$.fn.wpList.process($(id))
   526 						.removeClass('unapproved').addClass('approved')
       
   527 						.find('div.comment_status').html('1');
       
   528 				}
       
   529 			});
       
   530 
   433 	},
   531 	},
   434 
   532 
   435 	error : function(r) {
   533 	error : function(r) {
   436 		var er = r.statusText;
   534 		var er = r.statusText;
   437 
   535 
   441 			er = r.responseText.replace( /<.[^<>]*?>/g, '' );
   539 			er = r.responseText.replace( /<.[^<>]*?>/g, '' );
   442 
   540 
   443 		if ( er )
   541 		if ( er )
   444 			$('#replysubmit .error').html(er).show();
   542 			$('#replysubmit .error').html(er).show();
   445 
   543 
       
   544 	},
       
   545 
       
   546 	addcomment: function(post_id) {
       
   547 		var t = this;
       
   548 
       
   549 		$('#add-new-comment').fadeOut(200, function(){
       
   550 			t.open(0, post_id, 'add');
       
   551 			$('table.comments-box').css('display', '');
       
   552 			$('#no-comments').remove();
       
   553 		});
   446 	}
   554 	}
   447 };
   555 };
   448 
   556 
   449 $(document).ready(function(){
   557 $(document).ready(function(){
   450 	var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
   558 	var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
   451 
   559 
   452 	setCommentsList();
   560 	setCommentsList();
   453 	commentReply.init();
   561 	commentReply.init();
   454 	$('span.delete a.delete').click(function(){return false;});
   562 	$(document).delegate('span.delete a.delete', 'click', function(){return false;});
   455 
       
   456 	if ( typeof QTags != 'undefined' )
       
   457 		ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more');
       
   458 
   563 
   459 	if ( typeof $.table_hotkeys != 'undefined' ) {
   564 	if ( typeof $.table_hotkeys != 'undefined' ) {
   460 		make_hotkeys_redirect = function(which) {
   565 		make_hotkeys_redirect = function(which) {
   461 			return function() {
   566 			return function() {
   462 				var first_last, l;
   567 				var first_last, l;
   463 
   568 
   464 				first_last = 'next' == which? 'first' : 'last';
   569 				first_last = 'next' == which? 'first' : 'last';
   465 				l = $('.'+which+'.page-numbers');
   570 				l = $('.tablenav-pages .'+which+'-page:not(.disabled)');
   466 				if (l.length)
   571 				if (l.length)
   467 					window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
   572 					window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
   468 			}
   573 			}
   469 		};
   574 		};
   470 
   575 
   472 			window.location = $('span.edit a', current_row).attr('href');
   577 			window.location = $('span.edit a', current_row).attr('href');
   473 		};
   578 		};
   474 
   579 
   475 		toggle_all = function() {
   580 		toggle_all = function() {
   476 			toggleWithKeyboard = true;
   581 			toggleWithKeyboard = true;
   477 			$('input:checkbox', '#cb').click().attr('checked', '');
   582 			$('input:checkbox', '#cb').click().prop('checked', false);
   478 			toggleWithKeyboard = false;
   583 			toggleWithKeyboard = false;
   479 		};
   584 		};
   480 
   585 
   481 		make_bulk = function(value) {
   586 		make_bulk = function(value) {
   482 			return function() {
   587 			return function() {
   483 				var scope = $('select[name="action"]');
   588 				var scope = $('select[name="action"]');
   484 				$('option[value='+value+']', scope).attr('selected', 'selected');
   589 				$('option[value="' + value + '"]', scope).prop('selected', true);
   485 				$('#comments-form').submit();
   590 				$('#doaction').click();
   486 			}
   591 			}
   487 		};
   592 		};
   488 
   593 
   489 		$.table_hotkeys(
   594 		$.table_hotkeys(
   490 			$('table.widefat'),
   595 			$('table.widefat'),
   491 			['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all],
   596 			['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all],
   492 			['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')],
   597 			['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')],
   493 			['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')],
   598 			['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')],
   494 			['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]],
   599 			['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]],
   495 			{ highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
   600 			{ 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') }
   601 			prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') }
   497 		);
   602 		);