wp/wp-admin/js/edit-comments.js
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     1 /* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */
     1 /* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */
     2 var setCommentsList, theList, theExtraList, commentReply;
     2 var setCommentsList, theList, theExtraList, commentReply;
     3 
     3 
     4 (function($) {
     4 (function($) {
     5 var getCount, updateCount, updatePending;
     5 var getCount, updateCount, updateCountText, updatePending, updateApproved,
       
     6 	updateHtmlTitle, updateDashboardText, adminTitle = document.title,
       
     7 	isDashboard = $('#dashboard_right_now').length,
       
     8 	titleDiv, titleRegEx;
       
     9 
       
    10 	getCount = function(el) {
       
    11 		var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
       
    12 		if ( isNaN(n) ) {
       
    13 			return 0;
       
    14 		}
       
    15 		return n;
       
    16 	};
       
    17 
       
    18 	updateCount = function(el, n) {
       
    19 		var n1 = '';
       
    20 		if ( isNaN(n) ) {
       
    21 			return;
       
    22 		}
       
    23 		n = n < 1 ? '0' : n.toString();
       
    24 		if ( n.length > 3 ) {
       
    25 			while ( n.length > 3 ) {
       
    26 				n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
       
    27 				n = n.substr(0, n.length - 3);
       
    28 			}
       
    29 			n = n + n1;
       
    30 		}
       
    31 		el.html(n);
       
    32 	};
       
    33 
       
    34 	updateApproved = function( diff, commentPostId ) {
       
    35 		var postSelector = '.post-com-count-' + commentPostId,
       
    36 			noClass = 'comment-count-no-comments',
       
    37 			approvedClass = 'comment-count-approved',
       
    38 			approved,
       
    39 			noComments;
       
    40 
       
    41 		updateCountText( 'span.approved-count', diff );
       
    42 
       
    43 		if ( ! commentPostId ) {
       
    44 			return;
       
    45 		}
       
    46 
       
    47 		// cache selectors to not get dupes
       
    48 		approved = $( 'span.' + approvedClass, postSelector );
       
    49 		noComments = $( 'span.' + noClass, postSelector );
       
    50 
       
    51 		approved.each(function() {
       
    52 			var a = $(this), n = getCount(a) + diff;
       
    53 			if ( n < 1 )
       
    54 				n = 0;
       
    55 
       
    56 			if ( 0 === n ) {
       
    57 				a.removeClass( approvedClass ).addClass( noClass );
       
    58 			} else {
       
    59 				a.addClass( approvedClass ).removeClass( noClass );
       
    60 			}
       
    61 			updateCount( a, n );
       
    62 		});
       
    63 
       
    64 		noComments.each(function() {
       
    65 			var a = $(this);
       
    66 			if ( diff > 0 ) {
       
    67 				a.removeClass( noClass ).addClass( approvedClass );
       
    68 			} else {
       
    69 				a.addClass( noClass ).removeClass( approvedClass );
       
    70 			}
       
    71 			updateCount( a, diff );
       
    72 		});
       
    73 	};
       
    74 
       
    75 	updateCountText = function( selector, diff ) {
       
    76 		$( selector ).each(function() {
       
    77 			var a = $(this), n = getCount(a) + diff;
       
    78 			if ( n < 1 ) {
       
    79 				n = 0;
       
    80 			}
       
    81 			updateCount( a, n );
       
    82 		});
       
    83 	};
       
    84 
       
    85 	updateDashboardText = function ( response ) {
       
    86 		if ( ! isDashboard || ! response || ! response.i18n_comments_text ) {
       
    87 			return;
       
    88 		}
       
    89 
       
    90 		var rightNow = $( '#dashboard_right_now' );
       
    91 
       
    92 		$( '.comment-count a', rightNow ).text( response.i18n_comments_text );
       
    93 		$( '.comment-mod-count a', rightNow ).text( response.i18n_moderation_text )
       
    94 			.parent()
       
    95 			[ response.in_moderation > 0 ? 'removeClass' : 'addClass' ]( 'hidden' );
       
    96 	};
       
    97 
       
    98 	updateHtmlTitle = function ( diff ) {
       
    99 		var newTitle, regExMatch, titleCount, commentFrag;
       
   100 
       
   101 		titleRegEx = titleRegEx || new RegExp( adminCommentsL10n.docTitleCommentsCount.replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' );
       
   102 		// count funcs operate on a $'d element
       
   103 		titleDiv = titleDiv || $( '<div />' );
       
   104 		newTitle = adminTitle;
       
   105 
       
   106 		commentFrag = titleRegEx.exec( document.title );
       
   107 		if ( commentFrag ) {
       
   108 			commentFrag = commentFrag[0];
       
   109 			titleDiv.html( commentFrag );
       
   110 			titleCount = getCount( titleDiv ) + diff;
       
   111 		} else {
       
   112 			titleDiv.html( 0 );
       
   113 			titleCount = diff;
       
   114 		}
       
   115 
       
   116 		if ( titleCount >= 1 ) {
       
   117 			updateCount( titleDiv, titleCount );
       
   118 			regExMatch = titleRegEx.exec( document.title );
       
   119 			if ( regExMatch ) {
       
   120 				newTitle = document.title.replace( regExMatch[0], adminCommentsL10n.docTitleCommentsCount.replace( '%s', titleDiv.text() ) + ' ' );
       
   121 			}
       
   122 		} else {
       
   123 			regExMatch = titleRegEx.exec( newTitle );
       
   124 			if ( regExMatch ) {
       
   125 				newTitle = newTitle.replace( regExMatch[0], adminCommentsL10n.docTitleComments );
       
   126 			}
       
   127 		}
       
   128 		document.title = newTitle;
       
   129 	};
       
   130 
       
   131 	updatePending = function( diff, commentPostId ) {
       
   132 		var postSelector = '.post-com-count-' + commentPostId,
       
   133 			noClass = 'comment-count-no-pending',
       
   134 			noParentClass = 'post-com-count-no-pending',
       
   135 			pendingClass = 'comment-count-pending',
       
   136 			pending,
       
   137 			noPending;
       
   138 
       
   139 		if ( ! isDashboard ) {
       
   140 			updateHtmlTitle( diff );
       
   141 		}
       
   142 
       
   143 		$( 'span.pending-count' ).each(function() {
       
   144 			var a = $(this), n = getCount(a) + diff;
       
   145 			if ( n < 1 )
       
   146 				n = 0;
       
   147 			a.closest('.awaiting-mod')[ 0 === n ? 'addClass' : 'removeClass' ]('count-0');
       
   148 			updateCount( a, n );
       
   149 		});
       
   150 
       
   151 		if ( ! commentPostId ) {
       
   152 			return;
       
   153 		}
       
   154 
       
   155 		// cache selectors to not get dupes
       
   156 		pending = $( 'span.' + pendingClass, postSelector );
       
   157 		noPending = $( 'span.' + noClass, postSelector );
       
   158 
       
   159 		pending.each(function() {
       
   160 			var a = $(this), n = getCount(a) + diff;
       
   161 			if ( n < 1 )
       
   162 				n = 0;
       
   163 
       
   164 			if ( 0 === n ) {
       
   165 				a.parent().addClass( noParentClass );
       
   166 				a.removeClass( pendingClass ).addClass( noClass );
       
   167 			} else {
       
   168 				a.parent().removeClass( noParentClass );
       
   169 				a.addClass( pendingClass ).removeClass( noClass );
       
   170 			}
       
   171 			updateCount( a, n );
       
   172 		});
       
   173 
       
   174 		noPending.each(function() {
       
   175 			var a = $(this);
       
   176 			if ( diff > 0 ) {
       
   177 				a.parent().removeClass( noParentClass );
       
   178 				a.removeClass( noClass ).addClass( pendingClass );
       
   179 			} else {
       
   180 				a.parent().addClass( noParentClass );
       
   181 				a.addClass( noClass ).removeClass( pendingClass );
       
   182 			}
       
   183 			updateCount( a, diff );
       
   184 		});
       
   185 	};
     6 
   186 
     7 setCommentsList = function() {
   187 setCommentsList = function() {
     8 	var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff,
   188 	var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff,
     9 		lastConfidentTime = 0;
   189 		lastConfidentTime = 0;
    10 
   190 
    11 	totalInput = $('input[name="_total"]', '#comments-form');
   191 	totalInput = $('input[name="_total"]', '#comments-form');
    12 	perPageInput = $('input[name="_per_page"]', '#comments-form');
   192 	perPageInput = $('input[name="_per_page"]', '#comments-form');
    13 	pageInput = $('input[name="_page"]', '#comments-form');
   193 	pageInput = $('input[name="_page"]', '#comments-form');
    14 
   194 
       
   195 	// Updates the current total (stored in the _total input)
       
   196 	updateTotalCount = function( total, time, setConfidentTime ) {
       
   197 		if ( time < lastConfidentTime )
       
   198 			return;
       
   199 
       
   200 		if ( setConfidentTime )
       
   201 			lastConfidentTime = time;
       
   202 
       
   203 		totalInput.val( total.toString() );
       
   204 	};
       
   205 
       
   206 	// this fires when viewing "All"
    15 	dimAfter = function( r, settings ) {
   207 	dimAfter = function( r, settings ) {
    16 		var editRow, replyID, replyButton,
   208 		var editRow, replyID, replyButton, response,
    17 			c = $( '#' + settings.element );
   209 			c = $( '#' + settings.element );
       
   210 
       
   211 		if ( true !== settings.parsed ) {
       
   212 			response = settings.parsed.responses[0];
       
   213 		}
    18 
   214 
    19 		editRow = $('#replyrow');
   215 		editRow = $('#replyrow');
    20 		replyID = $('#comment_ID', editRow).val();
   216 		replyID = $('#comment_ID', editRow).val();
    21 		replyButton = $('#replybtn', editRow);
   217 		replyButton = $('#replybtn', editRow);
    22 
   218 
    23 		if ( c.is('.unapproved') ) {
   219 		if ( c.is('.unapproved') ) {
    24 			if ( settings.data.id == replyID )
   220 			if ( settings.data.id == replyID )
    25 				replyButton.text(adminCommentsL10n.replyApprove);
   221 				replyButton.text(adminCommentsL10n.replyApprove);
    26 
   222 
    27 			c.find('div.comment_status').html('0');
   223 			c.find( '.row-actions span.view' ).addClass( 'hidden' ).end()
       
   224 				.find( 'div.comment_status' ).html( '0' );
       
   225 
    28 		} else {
   226 		} else {
    29 			if ( settings.data.id == replyID )
   227 			if ( settings.data.id == replyID )
    30 				replyButton.text(adminCommentsL10n.reply);
   228 				replyButton.text(adminCommentsL10n.reply);
    31 
   229 
    32 			c.find('div.comment_status').html('1');
   230 			c.find( '.row-actions span.view' ).removeClass( 'hidden' ).end()
       
   231 				.find( 'div.comment_status' ).html( '1' );
    33 		}
   232 		}
    34 
   233 
    35 		diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
   234 		diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
    36 		updatePending( diff );
   235 		if ( response ) {
       
   236 			updateDashboardText( response.supplemental );
       
   237 			updatePending( diff, response.supplemental.postId );
       
   238 			updateApproved( -1 * diff, response.supplemental.postId );
       
   239 		} else {
       
   240 			updatePending( diff );
       
   241 			updateApproved( -1 * diff  );
       
   242 		}
    37 	};
   243 	};
    38 
   244 
    39 	// Send current total, page, per_page and url
   245 	// Send current total, page, per_page and url
    40 	delBefore = function( settings, list ) {
   246 	delBefore = function( settings, list ) {
    41 		var note, id, el, n, h, a, author,
   247 		var note, id, el, n, h, a, author,
    79 			a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
   285 			a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
    80 			a.attr('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1');
   286 			a.attr('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1');
    81 			a.attr('class', 'vim-z vim-destructive');
   287 			a.attr('class', 'vim-z vim-destructive');
    82 			$('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
   288 			$('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
    83 
   289 
    84 			a.click(function(){
   290 			a.click(function( e ){
       
   291 				e.preventDefault();
       
   292 				e.stopPropagation(); // ticket #35904
    85 				list.wpList.del(this);
   293 				list.wpList.del(this);
    86 				$('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
   294 				$('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
    87 					$(this).remove();
   295 					$(this).remove();
    88 					$('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show(); });
   296 					$('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show(); });
    89 				});
   297 				});
    90 				return false;
       
    91 			});
   298 			});
    92 		}
   299 		}
    93 
   300 
    94 		return settings;
   301 		return settings;
    95 	};
       
    96 
       
    97 	// Updates the current total (stored in the _total input)
       
    98 	updateTotalCount = function( total, time, setConfidentTime ) {
       
    99 		if ( time < lastConfidentTime )
       
   100 			return;
       
   101 
       
   102 		if ( setConfidentTime )
       
   103 			lastConfidentTime = time;
       
   104 
       
   105 		totalInput.val( total.toString() );
       
   106 	};
       
   107 
       
   108 	getCount = function(el) {
       
   109 		var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
       
   110 		if ( isNaN(n) )
       
   111 			return 0;
       
   112 		return n;
       
   113 	};
       
   114 
       
   115 	updateCount = function(el, n) {
       
   116 		var n1 = '';
       
   117 		if ( isNaN(n) )
       
   118 			return;
       
   119 		n = n < 1 ? '0' : n.toString();
       
   120 		if ( n.length > 3 ) {
       
   121 			while ( n.length > 3 ) {
       
   122 				n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
       
   123 				n = n.substr(0, n.length - 3);
       
   124 			}
       
   125 			n = n + n1;
       
   126 		}
       
   127 		el.html(n);
       
   128 	};
       
   129 
       
   130 	updatePending = function( diff ) {
       
   131 		$('span.pending-count').each(function() {
       
   132 			var a = $(this), n = getCount(a) + diff;
       
   133 			if ( n < 1 )
       
   134 				n = 0;
       
   135 			a.closest('.awaiting-mod')[ 0 === n ? 'addClass' : 'removeClass' ]('count-0');
       
   136 			updateCount( a, n );
       
   137 		});
       
   138 	};
   302 	};
   139 
   303 
   140 	// In admin-ajax.php, we send back the unix time stamp instead of 1 on success
   304 	// In admin-ajax.php, we send back the unix time stamp instead of 1 on success
   141 	delAfter = function( r, settings ) {
   305 	delAfter = function( r, settings ) {
   142 		var total_items_i18n, total, spam, trash, pending,
   306 		var total_items_i18n, total, animated, animatedCallback,
   143 			untrash = $(settings.target).parent().is('span.untrash'),
   307 			response = true === settings.parsed ? {} : settings.parsed.responses[0],
   144 			unspam = $(settings.target).parent().is('span.unspam'),
   308 			commentStatus = true === settings.parsed ? '' : response.supplemental.status,
   145 			unapproved = $('#' + settings.element).is('.unapproved');
   309 			commentPostId = true === settings.parsed ? '' : response.supplemental.postId,
   146 
   310 			newTotal = true === settings.parsed ? '' : response.supplemental,
   147 		function getUpdate(s) {
   311 
   148 			if ( $(settings.target).parent().is('span.' + s) )
   312 			targetParent = $( settings.target ).parent(),
   149 				return 1;
   313 			commentRow = $('#' + settings.element),
   150 			else if ( $('#' + settings.element).is('.' + s) )
   314 
   151 				return -1;
   315 			spamDiff, trashDiff, pendingDiff, approvedDiff,
   152 
   316 
   153 			return 0;
   317 			approved = commentRow.hasClass( 'approved' ),
   154 		}
   318 			unapproved = commentRow.hasClass( 'unapproved' ),
   155 
   319 			spammed = commentRow.hasClass( 'spam' ),
   156 		if ( untrash )
   320 			trashed = commentRow.hasClass( 'trash' ),
   157 			trash = -1;
   321 			undoing = false; // ticket #35904
   158 		else
   322 
   159 			trash = getUpdate('trash');
   323 		updateDashboardText( newTotal );
   160 
   324 
   161 		if ( unspam )
   325 		// the order of these checks is important
   162 			spam = -1;
   326 		// .unspam can also have .approve or .unapprove
   163 		else
   327 		// .untrash can also have .approve or .unapprove
   164 			spam = getUpdate('spam');
   328 
   165 
   329 		if ( targetParent.is( 'span.undo' ) ) {
   166 		if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) {
   330 			// the comment was spammed
   167 			// a comment was 'deleted' from another list (e.g. approved, spam, trash) and moved to pending,
   331 			if ( targetParent.hasClass( 'unspam' ) ) {
   168 			// or a trash/spam of a pending comment was undone
   332 				spamDiff = -1;
   169 			pending = 1;
   333 
   170 		} else if ( unapproved ) {
   334 				if ( 'trash' === commentStatus ) {
   171 			// a pending comment was trashed/spammed/approved
   335 					trashDiff = 1;
   172 			pending = -1;
   336 				} else if ( '1' === commentStatus ) {
   173 		}
   337 					approvedDiff = 1;
   174 
   338 				} else if ( '0' === commentStatus ) {
   175 		if ( pending )
   339 					pendingDiff = 1;
   176 			updatePending(pending);
   340 				}
   177 
   341 
   178 		$('span.spam-count').each( function() {
   342 			// the comment was trashed
   179 			var a = $(this), n = getCount(a) + spam;
   343 			} else if ( targetParent.hasClass( 'untrash' ) ) {
   180 			updateCount(a, n);
   344 				trashDiff = -1;
   181 		});
   345 
   182 
   346 				if ( 'spam' === commentStatus ) {
   183 		$('span.trash-count').each( function() {
   347 					spamDiff = 1;
   184 			var a = $(this), n = getCount(a) + trash;
   348 				} else if ( '1' === commentStatus ) {
   185 			updateCount(a, n);
   349 					approvedDiff = 1;
   186 		});
   350 				} else if ( '0' === commentStatus ) {
   187 
   351 					pendingDiff = 1;
   188 		if ( ! $('#dashboard_right_now').length ) {
   352 				}
       
   353 			}
       
   354 
       
   355 			undoing = true;
       
   356 
       
   357 		// user clicked "Spam"
       
   358 		} else if ( targetParent.is( 'span.spam' ) ) {
       
   359 			// the comment is currently approved
       
   360 			if ( approved ) {
       
   361 				approvedDiff = -1;
       
   362 			// the comment is currently pending
       
   363 			} else if ( unapproved ) {
       
   364 				pendingDiff = -1;
       
   365 			// the comment was in the trash
       
   366 			} else if ( trashed ) {
       
   367 				trashDiff = -1;
       
   368 			}
       
   369 			// you can't spam an item on the spam screen
       
   370 			spamDiff = 1;
       
   371 
       
   372 		// user clicked "Unspam"
       
   373 		} else if ( targetParent.is( 'span.unspam' ) ) {
       
   374 			if ( approved ) {
       
   375 				pendingDiff = 1;
       
   376 			} else if ( unapproved ) {
       
   377 				approvedDiff = 1;
       
   378 			} else if ( trashed ) {
       
   379 				// the comment was previously approved
       
   380 				if ( targetParent.hasClass( 'approve' ) ) {
       
   381 					approvedDiff = 1;
       
   382 				// the comment was previously pending
       
   383 				} else if ( targetParent.hasClass( 'unapprove' ) ) {
       
   384 					pendingDiff = 1;
       
   385 				}
       
   386 			} else if ( spammed ) {
       
   387 				if ( targetParent.hasClass( 'approve' ) ) {
       
   388 					approvedDiff = 1;
       
   389 
       
   390 				} else if ( targetParent.hasClass( 'unapprove' ) ) {
       
   391 					pendingDiff = 1;
       
   392 				}
       
   393 			}
       
   394 			// you can Unspam an item on the spam screen
       
   395 			spamDiff = -1;
       
   396 
       
   397 		// user clicked "Trash"
       
   398 		} else if ( targetParent.is( 'span.trash' ) ) {
       
   399 			if ( approved ) {
       
   400 				approvedDiff = -1;
       
   401 			} else if ( unapproved ) {
       
   402 				pendingDiff = -1;
       
   403 			// the comment was in the spam queue
       
   404 			} else if ( spammed ) {
       
   405 				spamDiff = -1;
       
   406 			}
       
   407 			// you can't trash an item on the trash screen
       
   408 			trashDiff = 1;
       
   409 
       
   410 		// user clicked "Restore"
       
   411 		} else if ( targetParent.is( 'span.untrash' ) ) {
       
   412 			if ( approved ) {
       
   413 				pendingDiff = 1;
       
   414 			} else if ( unapproved ) {
       
   415 				approvedDiff = 1;
       
   416 			} else if ( trashed ) {
       
   417 				if ( targetParent.hasClass( 'approve' ) ) {
       
   418 					approvedDiff = 1;
       
   419 				} else if ( targetParent.hasClass( 'unapprove' ) ) {
       
   420 					pendingDiff = 1;
       
   421 				}
       
   422 			}
       
   423 			// you can't go from trash to spam
       
   424 			// you can untrash on the trash screen
       
   425 			trashDiff = -1;
       
   426 
       
   427 		// User clicked "Approve"
       
   428 		} else if ( targetParent.is( 'span.approve:not(.unspam):not(.untrash)' ) ) {
       
   429 			approvedDiff = 1;
       
   430 			pendingDiff = -1;
       
   431 
       
   432 		// User clicked "Unapprove"
       
   433 		} else if ( targetParent.is( 'span.unapprove:not(.unspam):not(.untrash)' ) ) {
       
   434 			approvedDiff = -1;
       
   435 			pendingDiff = 1;
       
   436 
       
   437 		// User clicked "Delete Permanently"
       
   438 		} else if ( targetParent.is( 'span.delete' ) ) {
       
   439 			if ( spammed ) {
       
   440 				spamDiff = -1;
       
   441 			} else if ( trashed ) {
       
   442 				trashDiff = -1;
       
   443 			}
       
   444 		}
       
   445 
       
   446 		if ( pendingDiff ) {
       
   447 			updatePending( pendingDiff, commentPostId );
       
   448 			updateCountText( 'span.all-count', pendingDiff );
       
   449 		}
       
   450 
       
   451 		if ( approvedDiff ) {
       
   452 			updateApproved( approvedDiff, commentPostId );
       
   453 			updateCountText( 'span.all-count', approvedDiff );
       
   454 		}
       
   455 
       
   456 		if ( spamDiff ) {
       
   457 			updateCountText( 'span.spam-count', spamDiff );
       
   458 		}
       
   459 
       
   460 		if ( trashDiff ) {
       
   461 			updateCountText( 'span.trash-count', trashDiff );
       
   462 		}
       
   463 
       
   464 		if (
       
   465 			( ( 'trash' === settings.data.comment_status ) && !getCount( $( 'span.trash-count' ) ) ) ||
       
   466 			( ( 'spam' === settings.data.comment_status ) && !getCount( $( 'span.spam-count' ) ) )
       
   467 		) {
       
   468 			$( '#delete_all' ).hide();
       
   469 		}
       
   470 
       
   471 		if ( ! isDashboard ) {
   189 			total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
   472 			total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
   190 			if ( $(settings.target).parent().is('span.undo') )
   473 			if ( $(settings.target).parent().is('span.undo') )
   191 				total++;
   474 				total++;
   192 			else
   475 			else
   193 				total--;
   476 				total--;
   194 
   477 
   195 			if ( total < 0 )
   478 			if ( total < 0 )
   196 				total = 0;
   479 				total = 0;
   197 
   480 
   198 			if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
   481 			if ( 'object' === typeof r ) {
   199 				total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
   482 				if ( response.supplemental.total_items_i18n && lastConfidentTime < response.supplemental.time ) {
   200 				if ( total_items_i18n ) {
   483 					total_items_i18n = response.supplemental.total_items_i18n || '';
   201 					$('.displaying-num').text( total_items_i18n );
   484 					if ( total_items_i18n ) {
   202 					$('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
   485 						$('.displaying-num').text( total_items_i18n );
   203 					$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
   486 						$('.total-pages').text( response.supplemental.total_pages_i18n );
       
   487 						$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', response.supplemental.total_pages == $('.current-page').val());
       
   488 					}
       
   489 					updateTotalCount( total, response.supplemental.time, true );
       
   490 				} else if ( response.supplemental.time ) {
       
   491 					updateTotalCount( total, response.supplemental.time, false );
   204 				}
   492 				}
   205 				updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
       
   206 			} else {
   493 			} else {
   207 				updateTotalCount( total, r, false );
   494 				updateTotalCount( total, r, false );
   208 			}
   495 			}
   209 		}
   496 		}
   210 
   497 
   211 		if ( ! theExtraList || theExtraList.size() === 0 || theExtraList.children().size() === 0 || untrash || unspam ) {
   498 		if ( ! theExtraList || theExtraList.length === 0 || theExtraList.children().length === 0 || undoing ) {
   212 			return;
   499 			return;
   213 		}
   500 		}
   214 
   501 
   215 		theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
   502 		theList.get(0).wpList.add( theExtraList.children( ':eq(0):not(.no-items)' ).remove().clone() );
   216 
   503 
   217 		refillTheExtraList();
   504 		refillTheExtraList();
       
   505 
       
   506 		animated = $( ':animated', '#the-comment-list' );
       
   507 		animatedCallback = function () {
       
   508 			if ( ! $( '#the-comment-list tr:visible' ).length ) {
       
   509 				theList.get(0).wpList.add( theExtraList.find( '.no-items' ).clone() );
       
   510 			}
       
   511 		};
       
   512 
       
   513 		if ( animated.length ) {
       
   514 			animated.promise().done( animatedCallback );
       
   515 		} else {
       
   516 			animatedCallback();
       
   517 		}
   218 	};
   518 	};
   219 
   519 
   220 	refillTheExtraList = function(ev) {
   520 	refillTheExtraList = function(ev) {
   221 		var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val();
   521 		var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val();
   222 
   522 
   271 };
   571 };
   272 
   572 
   273 commentReply = {
   573 commentReply = {
   274 	cid : '',
   574 	cid : '',
   275 	act : '',
   575 	act : '',
       
   576 	originalContent : '',
   276 
   577 
   277 	init : function() {
   578 	init : function() {
   278 		var row = $('#replyrow');
   579 		var row = $('#replyrow');
   279 
   580 
   280 		$('a.cancel', row).click(function() { return commentReply.revert(); });
   581 		$('a.cancel', row).click(function() { return commentReply.revert(); });
   281 		$('a.save', row).click(function() { return commentReply.send(); });
   582 		$('a.save', row).click(function() { return commentReply.send(); });
   282 		$('input#author, input#author-email, input#author-url', row).keypress(function(e){
   583 		$( 'input#author-name, input#author-email, input#author-url', row ).keypress( function( e ) {
   283 			if ( e.which == 13 ) {
   584 			if ( e.which == 13 ) {
   284 				commentReply.send();
   585 				commentReply.send();
   285 				e.preventDefault();
   586 				e.preventDefault();
   286 				return false;
   587 				return false;
   287 			}
   588 			}
   311 			});
   612 			});
   312 		});
   613 		});
   313 	},
   614 	},
   314 
   615 
   315 	toggle : function(el) {
   616 	toggle : function(el) {
   316 		if ( $(el).css('display') != 'none' )
   617 		if ( 'none' !== $( el ).css( 'display' ) && ( $( '#replyrow' ).parent().is('#com-reply') || window.confirm( adminCommentsL10n.warnQuickEdit ) ) ) {
   317 			$(el).find('a.vim-q').click();
   618 			$( el ).find( 'a.vim-q' ).click();
       
   619 		}
   318 	},
   620 	},
   319 
   621 
   320 	revert : function() {
   622 	revert : function() {
   321 
   623 
   322 		if ( $('#the-comment-list #replyrow').length < 1 )
   624 		if ( $('#the-comment-list #replyrow').length < 1 )
   349 
   651 
   350 		replyrow.hide();
   652 		replyrow.hide();
   351 		$('#com-reply').append( replyrow );
   653 		$('#com-reply').append( replyrow );
   352 		$('#replycontent').css('height', '').val('');
   654 		$('#replycontent').css('height', '').val('');
   353 		$('#edithead input').val('');
   655 		$('#edithead input').val('');
   354 		$('.error', replyrow).empty().hide();
   656 		$( '.notice-error', replyrow )
       
   657 			.addClass( 'hidden' )
       
   658 			.find( '.error' ).empty();
   355 		$( '.spinner', replyrow ).removeClass( 'is-active' );
   659 		$( '.spinner', replyrow ).removeClass( 'is-active' );
   356 
   660 
   357 		this.cid = '';
   661 		this.cid = '';
       
   662 		this.originalContent = '';
   358 	},
   663 	},
   359 
   664 
   360 	open : function(comment_id, post_id, action) {
   665 	open : function(comment_id, post_id, action) {
   361 		var editRow, rowData, act, replyButton, editHeight,
   666 		var editRow, rowData, act, replyButton, editHeight,
   362 			t = this,
   667 			t = this,
   363 			c = $('#comment-' + comment_id),
   668 			c = $('#comment-' + comment_id),
   364 			h = c.height();
   669 			h = c.height(),
       
   670 			colspanVal = 0;
       
   671 
       
   672 		if ( ! this.discardCommentChanges() ) {
       
   673 			return false;
       
   674 		}
   365 
   675 
   366 		t.close();
   676 		t.close();
   367 		t.cid = comment_id;
   677 		t.cid = comment_id;
   368 
   678 
   369 		editRow = $('#replyrow');
   679 		editRow = $('#replyrow');
   370 		rowData = $('#inline-'+comment_id);
   680 		rowData = $('#inline-'+comment_id);
   371 		action = action || 'replyto';
   681 		action = action || 'replyto';
   372 		act = 'edit' == action ? 'edit' : 'replyto';
   682 		act = 'edit' == action ? 'edit' : 'replyto';
   373 		act = t.act = act + '-comment';
   683 		act = t.act = act + '-comment';
       
   684 		t.originalContent = $('textarea.comment', rowData).val();
       
   685 		colspanVal = $( '> th:visible, > td:visible', c ).length;
       
   686 
       
   687 		// Make sure it's actually a table and there's a `colspan` value to apply.
       
   688 		if ( editRow.hasClass( 'inline-edit-row' ) && 0 !== colspanVal ) {
       
   689 			$( 'td', editRow ).attr( 'colspan', colspanVal );
       
   690 		}
   374 
   691 
   375 		$('#action', editRow).val(act);
   692 		$('#action', editRow).val(act);
   376 		$('#comment_post_ID', editRow).val(post_id);
   693 		$('#comment_post_ID', editRow).val(post_id);
   377 		$('#comment_ID', editRow).val(comment_id);
   694 		$('#comment_ID', editRow).val(comment_id);
   378 
   695 
   379 		if ( action == 'edit' ) {
   696 		if ( action == 'edit' ) {
   380 			$('#author', editRow).val( $('div.author', rowData).text() );
   697 			$( '#author-name', editRow ).val( $( 'div.author', rowData ).text() );
   381 			$('#author-email', editRow).val( $('div.author-email', rowData).text() );
   698 			$('#author-email', editRow).val( $('div.author-email', rowData).text() );
   382 			$('#author-url', editRow).val( $('div.author-url', rowData).text() );
   699 			$('#author-url', editRow).val( $('div.author-url', rowData).text() );
   383 			$('#status', editRow).val( $('div.comment_status', rowData).text() );
   700 			$('#status', editRow).val( $('div.comment_status', rowData).text() );
   384 			$('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
   701 			$('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
   385 			$('#edithead, #savebtn', editRow).show();
   702 			$( '#edithead, #editlegend, #savebtn', editRow ).show();
   386 			$('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide();
   703 			$('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide();
   387 
   704 
   388 			if ( h > 120 ) {
   705 			if ( h > 120 ) {
   389 				// Limit the maximum height when editing very long comments to make it more manageable.
   706 				// Limit the maximum height when editing very long comments to make it more manageable.
   390 				// The textarea is resizable in most browsers, so the user can adjust it if needed.
   707 				// The textarea is resizable in most browsers, so the user can adjust it if needed.
   395 			c.after( editRow ).fadeOut('fast', function(){
   712 			c.after( editRow ).fadeOut('fast', function(){
   396 				$('#replyrow').fadeIn(300, function(){ $(this).show(); });
   713 				$('#replyrow').fadeIn(300, function(){ $(this).show(); });
   397 			});
   714 			});
   398 		} else if ( action == 'add' ) {
   715 		} else if ( action == 'add' ) {
   399 			$('#addhead, #addbtn', editRow).show();
   716 			$('#addhead, #addbtn', editRow).show();
   400 			$('#replyhead, #replybtn, #edithead, #editbtn', editRow).hide();
   717 			$( '#replyhead, #replybtn, #edithead, #editlegend, #savebtn', editRow ) .hide();
   401 			$('#the-comment-list').prepend(editRow);
   718 			$('#the-comment-list').prepend(editRow);
   402 			$('#replyrow').fadeIn(300);
   719 			$('#replyrow').fadeIn(300);
   403 		} else {
   720 		} else {
   404 			replyButton = $('#replybtn', editRow);
   721 			replyButton = $('#replybtn', editRow);
   405 			$('#edithead, #savebtn, #addhead, #addbtn', editRow).hide();
   722 			$( '#edithead, #editlegend, #savebtn, #addhead, #addbtn', editRow ).hide();
   406 			$('#replyhead, #replybtn', editRow).show();
   723 			$('#replyhead, #replybtn', editRow).show();
   407 			c.after(editRow);
   724 			c.after(editRow);
   408 
   725 
   409 			if ( c.hasClass('unapproved') ) {
   726 			if ( c.hasClass('unapproved') ) {
   410 				replyButton.text(adminCommentsL10n.replyApprove);
   727 				replyButton.text(adminCommentsL10n.replyApprove);
   437 
   754 
   438 		return false;
   755 		return false;
   439 	},
   756 	},
   440 
   757 
   441 	send : function() {
   758 	send : function() {
   442 		var post = {};
   759 		var post = {},
   443 
   760 			$errorNotice = $( '#replysubmit .error-notice' );
   444 		$('#replysubmit .error').hide();
   761 
       
   762 		$errorNotice.addClass( 'hidden' );
   445 		$( '#replysubmit .spinner' ).addClass( 'is-active' );
   763 		$( '#replysubmit .spinner' ).addClass( 'is-active' );
   446 
   764 
   447 		$('#replyrow input').not(':button').each(function() {
   765 		$('#replyrow input').not(':button').each(function() {
   448 			var t = $(this);
   766 			var t = $(this);
   449 			post[ t.attr('name') ] = t.val();
   767 			post[ t.attr('name') ] = t.val();
   490 		if ( 'edit-comment' == t.act )
   808 		if ( 'edit-comment' == t.act )
   491 			$(id).remove();
   809 			$(id).remove();
   492 
   810 
   493 		if ( r.supplemental.parent_approved ) {
   811 		if ( r.supplemental.parent_approved ) {
   494 			pid = $('#comment-' + r.supplemental.parent_approved);
   812 			pid = $('#comment-' + r.supplemental.parent_approved);
   495 			updatePending( -1 );
   813 			updatePending( -1, r.supplemental.parent_post_id );
   496 
   814 
   497 			if ( this.comments_listing == 'moderated' ) {
   815 			if ( this.comments_listing == 'moderated' ) {
   498 				pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){
   816 				pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){
   499 					pid.fadeOut();
   817 					pid.fadeOut();
   500 				});
   818 				});
   501 				return;
   819 				return;
       
   820 			}
       
   821 		}
       
   822 
       
   823 		if ( r.supplemental.i18n_comments_text ) {
       
   824 			if ( isDashboard ) {
       
   825 				updateDashboardText( r.supplemental );
       
   826 			} else {
       
   827 				updateApproved( 1, r.supplemental.parent_post_id );
       
   828 				updateCountText( 'span.all-count', 1 );
   502 			}
   829 			}
   503 		}
   830 		}
   504 
   831 
   505 		c = $.trim(r.data); // Trim leading whitespaces
   832 		c = $.trim(r.data); // Trim leading whitespaces
   506 		$(c).hide();
   833 		$(c).hide();
   521 			});
   848 			});
   522 
   849 
   523 	},
   850 	},
   524 
   851 
   525 	error : function(r) {
   852 	error : function(r) {
   526 		var er = r.statusText;
   853 		var er = r.statusText,
       
   854 			$errorNotice = $( '#replysubmit .notice-error' ),
       
   855 			$error = $errorNotice.find( '.error' );
   527 
   856 
   528 		$( '#replysubmit .spinner' ).removeClass( 'is-active' );
   857 		$( '#replysubmit .spinner' ).removeClass( 'is-active' );
   529 
   858 
   530 		if ( r.responseText )
   859 		if ( r.responseText )
   531 			er = r.responseText.replace( /<.[^<>]*?>/g, '' );
   860 			er = r.responseText.replace( /<.[^<>]*?>/g, '' );
   532 
   861 
   533 		if ( er )
   862 		if ( er ) {
   534 			$('#replysubmit .error').html(er).show();
   863 			$errorNotice.removeClass( 'hidden' );
   535 
   864 			$error.html( er );
       
   865 		}
   536 	},
   866 	},
   537 
   867 
   538 	addcomment: function(post_id) {
   868 	addcomment: function(post_id) {
   539 		var t = this;
   869 		var t = this;
   540 
   870 
   541 		$('#add-new-comment').fadeOut(200, function(){
   871 		$('#add-new-comment').fadeOut(200, function(){
   542 			t.open(0, post_id, 'add');
   872 			t.open(0, post_id, 'add');
   543 			$('table.comments-box').css('display', '');
   873 			$('table.comments-box').css('display', '');
   544 			$('#no-comments').remove();
   874 			$('#no-comments').remove();
   545 		});
   875 		});
       
   876 	},
       
   877 
       
   878 	/**
       
   879 	 * Alert the user if they have unsaved changes on a comment that will be
       
   880 	 * lost if they proceed.
       
   881 	 *
       
   882 	 * @returns {boolean}
       
   883 	 */
       
   884 	discardCommentChanges: function() {
       
   885 		var editRow = $( '#replyrow' );
       
   886 
       
   887 		if  ( this.originalContent === $( '#replycontent', editRow ).val() ) {
       
   888 			return true;
       
   889 		}
       
   890 
       
   891 		return window.confirm( adminCommentsL10n.warnCommentChanges );
   546 	}
   892 	}
   547 };
   893 };
   548 
   894 
   549 $(document).ready(function(){
   895 $(document).ready(function(){
   550 	var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
   896 	var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
   551 
   897 
   552 	setCommentsList();
   898 	setCommentsList();
   553 	commentReply.init();
   899 	commentReply.init();
   554 	$(document).delegate('span.delete a.delete', 'click', function(){return false;});
   900 
       
   901 	$(document).on( 'click', 'span.delete a.delete', function( e ) {
       
   902 		e.preventDefault();
       
   903 	});
   555 
   904 
   556 	if ( typeof $.table_hotkeys != 'undefined' ) {
   905 	if ( typeof $.table_hotkeys != 'undefined' ) {
   557 		make_hotkeys_redirect = function(which) {
   906 		make_hotkeys_redirect = function(which) {
   558 			return function() {
   907 			return function() {
   559 				var first_last, l;
   908 				var first_last, l;