Make WordPress Core

Ticket #40493: 40493.diff

File 40493.diff, 1.3 KB (added by karlijnbk, 4 years ago)
  • src/js/_enqueues/admin/user-profile.js

    diff --git a/src/js/_enqueues/admin/user-profile.js b/src/js/_enqueues/admin/user-profile.js
    index b73f2ab5c4..d14ff2549a 100644
    a b  
    55/* global ajaxurl, pwsL10n */
    66(function($) {
    77        var updateLock = false,
     8                isSubmitting = false,
    89                __ = wp.i18n.__,
    910                $pass1Row,
    1011                $pass1,
     
    1415                $toggleButton,
    1516                $submitButtons,
    1617                $submitButton,
    17                 currentPass;
     18                currentPass,
     19                $form,
     20                originalFormContent;
    1821
    1922        function generatePassword() {
    2023                if ( typeof zxcvbn !== 'function' ) {
     
    377380                });
    378381
    379382                bindPasswordForm();
     383
     384                $submitButtons.on( 'click', function () {
     385                        isSubmitting = true;
     386                });
     387
     388                $form = $('#your-profile, #createuser');
     389                originalFormContent = $form.serialize();
    380390        });
    381391
    382392        $( '#destroy-sessions' ).on( 'click', function( e ) {
     
    400410        window.generatePassword = generatePassword;
    401411
    402412        /* Warn the user if password was generated but not saved */
    403         $( window ).on( 'beforeunload', function () {
     413        $( window ).on( 'beforeunload', function ( ) {
    404414                if ( true === updateLock ) {
    405415                        return __( 'Your new password has not been saved.' );
    406416                }
     417                if( originalFormContent !== $form.serialize() && ! isSubmitting ) {
     418                        return __( 'Changes that you made may not be saved.' );
     419                }
    407420        } );
    408421
    409422})(jQuery);