wp/wp-admin/js/edit-comments.js
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
--- a/wp/wp-admin/js/edit-comments.js	Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-admin/js/edit-comments.js	Mon Oct 14 17:39:30 2019 +0200
@@ -2,7 +2,187 @@
 var setCommentsList, theList, theExtraList, commentReply;
 
 (function($) {
-var getCount, updateCount, updatePending;
+var getCount, updateCount, updateCountText, updatePending, updateApproved,
+	updateHtmlTitle, updateDashboardText, adminTitle = document.title,
+	isDashboard = $('#dashboard_right_now').length,
+	titleDiv, titleRegEx;
+
+	getCount = function(el) {
+		var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
+		if ( isNaN(n) ) {
+			return 0;
+		}
+		return n;
+	};
+
+	updateCount = function(el, n) {
+		var n1 = '';
+		if ( isNaN(n) ) {
+			return;
+		}
+		n = n < 1 ? '0' : n.toString();
+		if ( n.length > 3 ) {
+			while ( n.length > 3 ) {
+				n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
+				n = n.substr(0, n.length - 3);
+			}
+			n = n + n1;
+		}
+		el.html(n);
+	};
+
+	updateApproved = function( diff, commentPostId ) {
+		var postSelector = '.post-com-count-' + commentPostId,
+			noClass = 'comment-count-no-comments',
+			approvedClass = 'comment-count-approved',
+			approved,
+			noComments;
+
+		updateCountText( 'span.approved-count', diff );
+
+		if ( ! commentPostId ) {
+			return;
+		}
+
+		// cache selectors to not get dupes
+		approved = $( 'span.' + approvedClass, postSelector );
+		noComments = $( 'span.' + noClass, postSelector );
+
+		approved.each(function() {
+			var a = $(this), n = getCount(a) + diff;
+			if ( n < 1 )
+				n = 0;
+
+			if ( 0 === n ) {
+				a.removeClass( approvedClass ).addClass( noClass );
+			} else {
+				a.addClass( approvedClass ).removeClass( noClass );
+			}
+			updateCount( a, n );
+		});
+
+		noComments.each(function() {
+			var a = $(this);
+			if ( diff > 0 ) {
+				a.removeClass( noClass ).addClass( approvedClass );
+			} else {
+				a.addClass( noClass ).removeClass( approvedClass );
+			}
+			updateCount( a, diff );
+		});
+	};
+
+	updateCountText = function( selector, diff ) {
+		$( selector ).each(function() {
+			var a = $(this), n = getCount(a) + diff;
+			if ( n < 1 ) {
+				n = 0;
+			}
+			updateCount( a, n );
+		});
+	};
+
+	updateDashboardText = function ( response ) {
+		if ( ! isDashboard || ! response || ! response.i18n_comments_text ) {
+			return;
+		}
+
+		var rightNow = $( '#dashboard_right_now' );
+
+		$( '.comment-count a', rightNow ).text( response.i18n_comments_text );
+		$( '.comment-mod-count a', rightNow ).text( response.i18n_moderation_text )
+			.parent()
+			[ response.in_moderation > 0 ? 'removeClass' : 'addClass' ]( 'hidden' );
+	};
+
+	updateHtmlTitle = function ( diff ) {
+		var newTitle, regExMatch, titleCount, commentFrag;
+
+		titleRegEx = titleRegEx || new RegExp( adminCommentsL10n.docTitleCommentsCount.replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' );
+		// count funcs operate on a $'d element
+		titleDiv = titleDiv || $( '<div />' );
+		newTitle = adminTitle;
+
+		commentFrag = titleRegEx.exec( document.title );
+		if ( commentFrag ) {
+			commentFrag = commentFrag[0];
+			titleDiv.html( commentFrag );
+			titleCount = getCount( titleDiv ) + diff;
+		} else {
+			titleDiv.html( 0 );
+			titleCount = diff;
+		}
+
+		if ( titleCount >= 1 ) {
+			updateCount( titleDiv, titleCount );
+			regExMatch = titleRegEx.exec( document.title );
+			if ( regExMatch ) {
+				newTitle = document.title.replace( regExMatch[0], adminCommentsL10n.docTitleCommentsCount.replace( '%s', titleDiv.text() ) + ' ' );
+			}
+		} else {
+			regExMatch = titleRegEx.exec( newTitle );
+			if ( regExMatch ) {
+				newTitle = newTitle.replace( regExMatch[0], adminCommentsL10n.docTitleComments );
+			}
+		}
+		document.title = newTitle;
+	};
+
+	updatePending = function( diff, commentPostId ) {
+		var postSelector = '.post-com-count-' + commentPostId,
+			noClass = 'comment-count-no-pending',
+			noParentClass = 'post-com-count-no-pending',
+			pendingClass = 'comment-count-pending',
+			pending,
+			noPending;
+
+		if ( ! isDashboard ) {
+			updateHtmlTitle( diff );
+		}
+
+		$( 'span.pending-count' ).each(function() {
+			var a = $(this), n = getCount(a) + diff;
+			if ( n < 1 )
+				n = 0;
+			a.closest('.awaiting-mod')[ 0 === n ? 'addClass' : 'removeClass' ]('count-0');
+			updateCount( a, n );
+		});
+
+		if ( ! commentPostId ) {
+			return;
+		}
+
+		// cache selectors to not get dupes
+		pending = $( 'span.' + pendingClass, postSelector );
+		noPending = $( 'span.' + noClass, postSelector );
+
+		pending.each(function() {
+			var a = $(this), n = getCount(a) + diff;
+			if ( n < 1 )
+				n = 0;
+
+			if ( 0 === n ) {
+				a.parent().addClass( noParentClass );
+				a.removeClass( pendingClass ).addClass( noClass );
+			} else {
+				a.parent().removeClass( noParentClass );
+				a.addClass( pendingClass ).removeClass( noClass );
+			}
+			updateCount( a, n );
+		});
+
+		noPending.each(function() {
+			var a = $(this);
+			if ( diff > 0 ) {
+				a.parent().removeClass( noParentClass );
+				a.removeClass( noClass ).addClass( pendingClass );
+			} else {
+				a.parent().addClass( noParentClass );
+				a.addClass( noClass ).removeClass( pendingClass );
+			}
+			updateCount( a, diff );
+		});
+	};
 
 setCommentsList = function() {
 	var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff,
@@ -12,10 +192,26 @@
 	perPageInput = $('input[name="_per_page"]', '#comments-form');
 	pageInput = $('input[name="_page"]', '#comments-form');
 
+	// Updates the current total (stored in the _total input)
+	updateTotalCount = function( total, time, setConfidentTime ) {
+		if ( time < lastConfidentTime )
+			return;
+
+		if ( setConfidentTime )
+			lastConfidentTime = time;
+
+		totalInput.val( total.toString() );
+	};
+
+	// this fires when viewing "All"
 	dimAfter = function( r, settings ) {
-		var editRow, replyID, replyButton,
+		var editRow, replyID, replyButton, response,
 			c = $( '#' + settings.element );
 
+		if ( true !== settings.parsed ) {
+			response = settings.parsed.responses[0];
+		}
+
 		editRow = $('#replyrow');
 		replyID = $('#comment_ID', editRow).val();
 		replyButton = $('#replybtn', editRow);
@@ -24,16 +220,26 @@
 			if ( settings.data.id == replyID )
 				replyButton.text(adminCommentsL10n.replyApprove);
 
-			c.find('div.comment_status').html('0');
+			c.find( '.row-actions span.view' ).addClass( 'hidden' ).end()
+				.find( 'div.comment_status' ).html( '0' );
+
 		} else {
 			if ( settings.data.id == replyID )
 				replyButton.text(adminCommentsL10n.reply);
 
-			c.find('div.comment_status').html('1');
+			c.find( '.row-actions span.view' ).removeClass( 'hidden' ).end()
+				.find( 'div.comment_status' ).html( '1' );
 		}
 
 		diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
-		updatePending( diff );
+		if ( response ) {
+			updateDashboardText( response.supplemental );
+			updatePending( diff, response.supplemental.postId );
+			updateApproved( -1 * diff, response.supplemental.postId );
+		} else {
+			updatePending( diff );
+			updateApproved( -1 * diff  );
+		}
 	};
 
 	// Send current total, page, per_page and url
@@ -81,111 +287,188 @@
 			a.attr('class', 'vim-z vim-destructive');
 			$('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
 
-			a.click(function(){
+			a.click(function( e ){
+				e.preventDefault();
+				e.stopPropagation(); // ticket #35904
 				list.wpList.del(this);
 				$('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
 					$(this).remove();
 					$('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show(); });
 				});
-				return false;
 			});
 		}
 
 		return settings;
 	};
 
-	// Updates the current total (stored in the _total input)
-	updateTotalCount = function( total, time, setConfidentTime ) {
-		if ( time < lastConfidentTime )
-			return;
-
-		if ( setConfidentTime )
-			lastConfidentTime = time;
-
-		totalInput.val( total.toString() );
-	};
-
-	getCount = function(el) {
-		var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
-		if ( isNaN(n) )
-			return 0;
-		return n;
-	};
-
-	updateCount = function(el, n) {
-		var n1 = '';
-		if ( isNaN(n) )
-			return;
-		n = n < 1 ? '0' : n.toString();
-		if ( n.length > 3 ) {
-			while ( n.length > 3 ) {
-				n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
-				n = n.substr(0, n.length - 3);
-			}
-			n = n + n1;
-		}
-		el.html(n);
-	};
-
-	updatePending = function( diff ) {
-		$('span.pending-count').each(function() {
-			var a = $(this), n = getCount(a) + diff;
-			if ( n < 1 )
-				n = 0;
-			a.closest('.awaiting-mod')[ 0 === n ? 'addClass' : 'removeClass' ]('count-0');
-			updateCount( a, n );
-		});
-	};
-
 	// In admin-ajax.php, we send back the unix time stamp instead of 1 on success
 	delAfter = function( r, settings ) {
-		var total_items_i18n, total, spam, trash, pending,
-			untrash = $(settings.target).parent().is('span.untrash'),
-			unspam = $(settings.target).parent().is('span.unspam'),
-			unapproved = $('#' + settings.element).is('.unapproved');
+		var total_items_i18n, total, animated, animatedCallback,
+			response = true === settings.parsed ? {} : settings.parsed.responses[0],
+			commentStatus = true === settings.parsed ? '' : response.supplemental.status,
+			commentPostId = true === settings.parsed ? '' : response.supplemental.postId,
+			newTotal = true === settings.parsed ? '' : response.supplemental,
+
+			targetParent = $( settings.target ).parent(),
+			commentRow = $('#' + settings.element),
+
+			spamDiff, trashDiff, pendingDiff, approvedDiff,
+
+			approved = commentRow.hasClass( 'approved' ),
+			unapproved = commentRow.hasClass( 'unapproved' ),
+			spammed = commentRow.hasClass( 'spam' ),
+			trashed = commentRow.hasClass( 'trash' ),
+			undoing = false; // ticket #35904
+
+		updateDashboardText( newTotal );
+
+		// the order of these checks is important
+		// .unspam can also have .approve or .unapprove
+		// .untrash can also have .approve or .unapprove
+
+		if ( targetParent.is( 'span.undo' ) ) {
+			// the comment was spammed
+			if ( targetParent.hasClass( 'unspam' ) ) {
+				spamDiff = -1;
+
+				if ( 'trash' === commentStatus ) {
+					trashDiff = 1;
+				} else if ( '1' === commentStatus ) {
+					approvedDiff = 1;
+				} else if ( '0' === commentStatus ) {
+					pendingDiff = 1;
+				}
+
+			// the comment was trashed
+			} else if ( targetParent.hasClass( 'untrash' ) ) {
+				trashDiff = -1;
+
+				if ( 'spam' === commentStatus ) {
+					spamDiff = 1;
+				} else if ( '1' === commentStatus ) {
+					approvedDiff = 1;
+				} else if ( '0' === commentStatus ) {
+					pendingDiff = 1;
+				}
+			}
+
+			undoing = true;
+
+		// user clicked "Spam"
+		} else if ( targetParent.is( 'span.spam' ) ) {
+			// the comment is currently approved
+			if ( approved ) {
+				approvedDiff = -1;
+			// the comment is currently pending
+			} else if ( unapproved ) {
+				pendingDiff = -1;
+			// the comment was in the trash
+			} else if ( trashed ) {
+				trashDiff = -1;
+			}
+			// you can't spam an item on the spam screen
+			spamDiff = 1;
 
-		function getUpdate(s) {
-			if ( $(settings.target).parent().is('span.' + s) )
-				return 1;
-			else if ( $('#' + settings.element).is('.' + s) )
-				return -1;
+		// user clicked "Unspam"
+		} else if ( targetParent.is( 'span.unspam' ) ) {
+			if ( approved ) {
+				pendingDiff = 1;
+			} else if ( unapproved ) {
+				approvedDiff = 1;
+			} else if ( trashed ) {
+				// the comment was previously approved
+				if ( targetParent.hasClass( 'approve' ) ) {
+					approvedDiff = 1;
+				// the comment was previously pending
+				} else if ( targetParent.hasClass( 'unapprove' ) ) {
+					pendingDiff = 1;
+				}
+			} else if ( spammed ) {
+				if ( targetParent.hasClass( 'approve' ) ) {
+					approvedDiff = 1;
+
+				} else if ( targetParent.hasClass( 'unapprove' ) ) {
+					pendingDiff = 1;
+				}
+			}
+			// you can Unspam an item on the spam screen
+			spamDiff = -1;
 
-			return 0;
+		// user clicked "Trash"
+		} else if ( targetParent.is( 'span.trash' ) ) {
+			if ( approved ) {
+				approvedDiff = -1;
+			} else if ( unapproved ) {
+				pendingDiff = -1;
+			// the comment was in the spam queue
+			} else if ( spammed ) {
+				spamDiff = -1;
+			}
+			// you can't trash an item on the trash screen
+			trashDiff = 1;
+
+		// user clicked "Restore"
+		} else if ( targetParent.is( 'span.untrash' ) ) {
+			if ( approved ) {
+				pendingDiff = 1;
+			} else if ( unapproved ) {
+				approvedDiff = 1;
+			} else if ( trashed ) {
+				if ( targetParent.hasClass( 'approve' ) ) {
+					approvedDiff = 1;
+				} else if ( targetParent.hasClass( 'unapprove' ) ) {
+					pendingDiff = 1;
+				}
+			}
+			// you can't go from trash to spam
+			// you can untrash on the trash screen
+			trashDiff = -1;
+
+		// User clicked "Approve"
+		} else if ( targetParent.is( 'span.approve:not(.unspam):not(.untrash)' ) ) {
+			approvedDiff = 1;
+			pendingDiff = -1;
+
+		// User clicked "Unapprove"
+		} else if ( targetParent.is( 'span.unapprove:not(.unspam):not(.untrash)' ) ) {
+			approvedDiff = -1;
+			pendingDiff = 1;
+
+		// User clicked "Delete Permanently"
+		} else if ( targetParent.is( 'span.delete' ) ) {
+			if ( spammed ) {
+				spamDiff = -1;
+			} else if ( trashed ) {
+				trashDiff = -1;
+			}
 		}
 
-		if ( untrash )
-			trash = -1;
-		else
-			trash = getUpdate('trash');
+		if ( pendingDiff ) {
+			updatePending( pendingDiff, commentPostId );
+			updateCountText( 'span.all-count', pendingDiff );
+		}
 
-		if ( unspam )
-			spam = -1;
-		else
-			spam = getUpdate('spam');
-
-		if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) {
-			// a comment was 'deleted' from another list (e.g. approved, spam, trash) and moved to pending,
-			// or a trash/spam of a pending comment was undone
-			pending = 1;
-		} else if ( unapproved ) {
-			// a pending comment was trashed/spammed/approved
-			pending = -1;
+		if ( approvedDiff ) {
+			updateApproved( approvedDiff, commentPostId );
+			updateCountText( 'span.all-count', approvedDiff );
 		}
 
-		if ( pending )
-			updatePending(pending);
+		if ( spamDiff ) {
+			updateCountText( 'span.spam-count', spamDiff );
+		}
+
+		if ( trashDiff ) {
+			updateCountText( 'span.trash-count', trashDiff );
+		}
 
-		$('span.spam-count').each( function() {
-			var a = $(this), n = getCount(a) + spam;
-			updateCount(a, n);
-		});
+		if (
+			( ( 'trash' === settings.data.comment_status ) && !getCount( $( 'span.trash-count' ) ) ) ||
+			( ( 'spam' === settings.data.comment_status ) && !getCount( $( 'span.spam-count' ) ) )
+		) {
+			$( '#delete_all' ).hide();
+		}
 
-		$('span.trash-count').each( function() {
-			var a = $(this), n = getCount(a) + trash;
-			updateCount(a, n);
-		});
-
-		if ( ! $('#dashboard_right_now').length ) {
+		if ( ! isDashboard ) {
 			total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
 			if ( $(settings.target).parent().is('span.undo') )
 				total++;
@@ -195,26 +478,43 @@
 			if ( total < 0 )
 				total = 0;
 
-			if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
-				total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
-				if ( total_items_i18n ) {
-					$('.displaying-num').text( total_items_i18n );
-					$('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
-					$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
+			if ( 'object' === typeof r ) {
+				if ( response.supplemental.total_items_i18n && lastConfidentTime < response.supplemental.time ) {
+					total_items_i18n = response.supplemental.total_items_i18n || '';
+					if ( total_items_i18n ) {
+						$('.displaying-num').text( total_items_i18n );
+						$('.total-pages').text( response.supplemental.total_pages_i18n );
+						$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', response.supplemental.total_pages == $('.current-page').val());
+					}
+					updateTotalCount( total, response.supplemental.time, true );
+				} else if ( response.supplemental.time ) {
+					updateTotalCount( total, response.supplemental.time, false );
 				}
-				updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
 			} else {
 				updateTotalCount( total, r, false );
 			}
 		}
 
-		if ( ! theExtraList || theExtraList.size() === 0 || theExtraList.children().size() === 0 || untrash || unspam ) {
+		if ( ! theExtraList || theExtraList.length === 0 || theExtraList.children().length === 0 || undoing ) {
 			return;
 		}
 
-		theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
+		theList.get(0).wpList.add( theExtraList.children( ':eq(0):not(.no-items)' ).remove().clone() );
 
 		refillTheExtraList();
+
+		animated = $( ':animated', '#the-comment-list' );
+		animatedCallback = function () {
+			if ( ! $( '#the-comment-list tr:visible' ).length ) {
+				theList.get(0).wpList.add( theExtraList.find( '.no-items' ).clone() );
+			}
+		};
+
+		if ( animated.length ) {
+			animated.promise().done( animatedCallback );
+		} else {
+			animatedCallback();
+		}
 	};
 
 	refillTheExtraList = function(ev) {
@@ -273,13 +573,14 @@
 commentReply = {
 	cid : '',
 	act : '',
+	originalContent : '',
 
 	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){
+		$( 'input#author-name, input#author-email, input#author-url', row ).keypress( function( e ) {
 			if ( e.which == 13 ) {
 				commentReply.send();
 				e.preventDefault();
@@ -313,8 +614,9 @@
 	},
 
 	toggle : function(el) {
-		if ( $(el).css('display') != 'none' )
-			$(el).find('a.vim-q').click();
+		if ( 'none' !== $( el ).css( 'display' ) && ( $( '#replyrow' ).parent().is('#com-reply') || window.confirm( adminCommentsL10n.warnQuickEdit ) ) ) {
+			$( el ).find( 'a.vim-q' ).click();
+		}
 	},
 
 	revert : function() {
@@ -351,17 +653,25 @@
 		$('#com-reply').append( replyrow );
 		$('#replycontent').css('height', '').val('');
 		$('#edithead input').val('');
-		$('.error', replyrow).empty().hide();
+		$( '.notice-error', replyrow )
+			.addClass( 'hidden' )
+			.find( '.error' ).empty();
 		$( '.spinner', replyrow ).removeClass( 'is-active' );
 
 		this.cid = '';
+		this.originalContent = '';
 	},
 
 	open : function(comment_id, post_id, action) {
 		var editRow, rowData, act, replyButton, editHeight,
 			t = this,
 			c = $('#comment-' + comment_id),
-			h = c.height();
+			h = c.height(),
+			colspanVal = 0;
+
+		if ( ! this.discardCommentChanges() ) {
+			return false;
+		}
 
 		t.close();
 		t.cid = comment_id;
@@ -371,18 +681,25 @@
 		action = action || 'replyto';
 		act = 'edit' == action ? 'edit' : 'replyto';
 		act = t.act = act + '-comment';
+		t.originalContent = $('textarea.comment', rowData).val();
+		colspanVal = $( '> th:visible, > td:visible', c ).length;
+
+		// Make sure it's actually a table and there's a `colspan` value to apply.
+		if ( editRow.hasClass( 'inline-edit-row' ) && 0 !== colspanVal ) {
+			$( 'td', editRow ).attr( 'colspan', colspanVal );
+		}
 
 		$('#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-name', 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();
+			$( '#edithead, #editlegend, #savebtn', editRow ).show();
 			$('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide();
 
 			if ( h > 120 ) {
@@ -397,12 +714,12 @@
 			});
 		} else if ( action == 'add' ) {
 			$('#addhead, #addbtn', editRow).show();
-			$('#replyhead, #replybtn, #edithead, #editbtn', editRow).hide();
+			$( '#replyhead, #replybtn, #edithead, #editlegend, #savebtn', editRow ) .hide();
 			$('#the-comment-list').prepend(editRow);
 			$('#replyrow').fadeIn(300);
 		} else {
 			replyButton = $('#replybtn', editRow);
-			$('#edithead, #savebtn, #addhead, #addbtn', editRow).hide();
+			$( '#edithead, #editlegend, #savebtn, #addhead, #addbtn', editRow ).hide();
 			$('#replyhead, #replybtn', editRow).show();
 			c.after(editRow);
 
@@ -439,9 +756,10 @@
 	},
 
 	send : function() {
-		var post = {};
+		var post = {},
+			$errorNotice = $( '#replysubmit .error-notice' );
 
-		$('#replysubmit .error').hide();
+		$errorNotice.addClass( 'hidden' );
 		$( '#replysubmit .spinner' ).addClass( 'is-active' );
 
 		$('#replyrow input').not(':button').each(function() {
@@ -492,7 +810,7 @@
 
 		if ( r.supplemental.parent_approved ) {
 			pid = $('#comment-' + r.supplemental.parent_approved);
-			updatePending( -1 );
+			updatePending( -1, r.supplemental.parent_post_id );
 
 			if ( this.comments_listing == 'moderated' ) {
 				pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){
@@ -502,6 +820,15 @@
 			}
 		}
 
+		if ( r.supplemental.i18n_comments_text ) {
+			if ( isDashboard ) {
+				updateDashboardText( r.supplemental );
+			} else {
+				updateApproved( 1, r.supplemental.parent_post_id );
+				updateCountText( 'span.all-count', 1 );
+			}
+		}
+
 		c = $.trim(r.data); // Trim leading whitespaces
 		$(c).hide();
 		$('#replyrow').after(c);
@@ -523,16 +850,19 @@
 	},
 
 	error : function(r) {
-		var er = r.statusText;
+		var er = r.statusText,
+			$errorNotice = $( '#replysubmit .notice-error' ),
+			$error = $errorNotice.find( '.error' );
 
 		$( '#replysubmit .spinner' ).removeClass( 'is-active' );
 
 		if ( r.responseText )
 			er = r.responseText.replace( /<.[^<>]*?>/g, '' );
 
-		if ( er )
-			$('#replysubmit .error').html(er).show();
-
+		if ( er ) {
+			$errorNotice.removeClass( 'hidden' );
+			$error.html( er );
+		}
 	},
 
 	addcomment: function(post_id) {
@@ -543,6 +873,22 @@
 			$('table.comments-box').css('display', '');
 			$('#no-comments').remove();
 		});
+	},
+
+	/**
+	 * Alert the user if they have unsaved changes on a comment that will be
+	 * lost if they proceed.
+	 *
+	 * @returns {boolean}
+	 */
+	discardCommentChanges: function() {
+		var editRow = $( '#replyrow' );
+
+		if  ( this.originalContent === $( '#replycontent', editRow ).val() ) {
+			return true;
+		}
+
+		return window.confirm( adminCommentsL10n.warnCommentChanges );
 	}
 };
 
@@ -551,7 +897,10 @@
 
 	setCommentsList();
 	commentReply.init();
-	$(document).delegate('span.delete a.delete', 'click', function(){return false;});
+
+	$(document).on( 'click', 'span.delete a.delete', function( e ) {
+		e.preventDefault();
+	});
 
 	if ( typeof $.table_hotkeys != 'undefined' ) {
 		make_hotkeys_redirect = function(which) {