Comments: Keep comments safe in the Edit Post screen.

Warns users that have added a new Comment or began editing an existing without saving their changes, before they press the “update” button which would wipe out their comment changes.

Fixes #32818.

Props polevaultweb.
Built from https://develop.svn.wordpress.org/trunk@37303


git-svn-id: http://core.svn.wordpress.org/trunk@37269 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Rachel Baker 2016-04-22 21:43:28 +00:00
parent be59d289b7
commit 8b0e1859bc
6 changed files with 35 additions and 3 deletions

View File

@ -566,6 +566,7 @@ setCommentsList = function() {
commentReply = {
cid : '',
act : '',
originalContent : '',
init : function() {
var row = $('#replyrow');
@ -649,6 +650,7 @@ commentReply = {
$( '.spinner', replyrow ).removeClass( 'is-active' );
this.cid = '';
this.originalContent = '';
},
open : function(comment_id, post_id, action) {
@ -658,6 +660,10 @@ commentReply = {
h = c.height(),
colspanVal = 0;
if ( ! this.discardCommentChanges() ) {
return false;
}
t.close();
t.cid = comment_id;
@ -666,6 +672,7 @@ commentReply = {
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.
@ -853,6 +860,22 @@ commentReply = {
$('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 );
}
};

File diff suppressed because one or more lines are too long

View File

@ -271,6 +271,14 @@ jQuery(document).ready( function($) {
}
if ( typeof commentReply !== 'undefined' ) {
/*
* Warn the user they have an unsaved comment before submitting
* the post data for update.
*/
if ( ! commentReply.discardCommentChanges() ) {
return false;
}
/*
* Close the comment edit/reply form if open to stop the form
* action from interfering with the post's form action.

File diff suppressed because one or more lines are too long

View File

@ -495,6 +495,7 @@ function wp_default_scripts( &$scripts ) {
'replyApprove' => __( 'Approve and Reply' ),
'reply' => __( 'Reply' ),
'warnQuickEdit' => __( "Are you sure you want to edit this comment?\nThe changes you made will be lost." ),
'warnCommentChanges' => __( "Are you sure you want to do this?\nThe comment changes you made will be lost." ),
'docTitleComments' => __( 'Comments' ),
/* translators: %s: comments count */
'docTitleCommentsCount' => __( 'Comments (%s)' ),

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.6-alpha-37302';
$wp_version = '4.6-alpha-37303';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.