Make WordPress Core

Changeset 37303 for trunk


Ignore:
Timestamp:
04/22/2016 09:42:38 PM (10 years ago)
Author:
rachelbaker
Message:

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.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/edit-comments.js

    r37302 r37303  
    567567        cid : '',
    568568        act : '',
     569        originalContent : '',
    569570
    570571        init : function() {
     
    650651
    651652                this.cid = '';
     653                this.originalContent = '';
    652654        },
    653655
     
    659661                        colspanVal = 0;
    660662
     663                if ( ! this.discardCommentChanges() ) {
     664                        return false;
     665                }
     666
    661667                t.close();
    662668                t.cid = comment_id;
     
    667673                act = 'edit' == action ? 'edit' : 'replyto';
    668674                act = t.act = act + '-comment';
     675                t.originalContent = $('textarea.comment', rowData).val();
    669676                colspanVal = $( '> th:visible, > td:visible', c ).length;
    670677
     
    854861                        $('#no-comments').remove();
    855862                });
     863        },
     864
     865        /**
     866         * Alert the user if they have unsaved changes on a comment that will be
     867         * lost if they proceed.
     868         *
     869         * @returns {boolean}
     870         */
     871        discardCommentChanges: function() {
     872                var editRow = $( '#replyrow' );
     873
     874                if  ( this.originalContent === $( '#replycontent', editRow ).val() ) {
     875                        return true;
     876                }
     877
     878                return window.confirm( adminCommentsL10n.warnCommentChanges );
    856879        }
    857880};
  • trunk/src/wp-admin/js/post.js

    r36972 r37303  
    273273                        if ( typeof commentReply !== 'undefined' ) {
    274274                                /*
     275                                 * Warn the user they have an unsaved comment before submitting
     276                                 * the post data for update.
     277                                 */
     278                                if ( ! commentReply.discardCommentChanges() ) {
     279                                        return false;
     280                                }
     281
     282                                /*
    275283                                 * Close the comment edit/reply form if open to stop the form
    276284                                 * action from interfering with the post's form action.
  • trunk/src/wp-includes/script-loader.php

    r37201 r37303  
    496496                        'reply' => __( 'Reply' ),
    497497                        'warnQuickEdit' => __( "Are you sure you want to edit this comment?\nThe changes you made will be lost." ),
     498                        'warnCommentChanges' => __( "Are you sure you want to do this?\nThe comment changes you made will be lost." ),
    498499                        'docTitleComments' => __( 'Comments' ),
    499500                        /* translators: %s: comments count */
Note: See TracChangeset for help on using the changeset viewer.