diff --git a/src/js/_enqueues/admin/user-profile.js b/src/js/_enqueues/admin/user-profile.js
index b73f2ab5c4..d14ff2549a 100644
a
|
b
|
|
5 | 5 | /* global ajaxurl, pwsL10n */ |
6 | 6 | (function($) { |
7 | 7 | var updateLock = false, |
| 8 | isSubmitting = false, |
8 | 9 | __ = wp.i18n.__, |
9 | 10 | $pass1Row, |
10 | 11 | $pass1, |
… |
… |
|
14 | 15 | $toggleButton, |
15 | 16 | $submitButtons, |
16 | 17 | $submitButton, |
17 | | currentPass; |
| 18 | currentPass, |
| 19 | $form, |
| 20 | originalFormContent; |
18 | 21 | |
19 | 22 | function generatePassword() { |
20 | 23 | if ( typeof zxcvbn !== 'function' ) { |
… |
… |
|
377 | 380 | }); |
378 | 381 | |
379 | 382 | bindPasswordForm(); |
| 383 | |
| 384 | $submitButtons.on( 'click', function () { |
| 385 | isSubmitting = true; |
| 386 | }); |
| 387 | |
| 388 | $form = $('#your-profile, #createuser'); |
| 389 | originalFormContent = $form.serialize(); |
380 | 390 | }); |
381 | 391 | |
382 | 392 | $( '#destroy-sessions' ).on( 'click', function( e ) { |
… |
… |
|
400 | 410 | window.generatePassword = generatePassword; |
401 | 411 | |
402 | 412 | /* Warn the user if password was generated but not saved */ |
403 | | $( window ).on( 'beforeunload', function () { |
| 413 | $( window ).on( 'beforeunload', function ( ) { |
404 | 414 | if ( true === updateLock ) { |
405 | 415 | return __( 'Your new password has not been saved.' ); |
406 | 416 | } |
| 417 | if( originalFormContent !== $form.serialize() && ! isSubmitting ) { |
| 418 | return __( 'Changes that you made may not be saved.' ); |
| 419 | } |
407 | 420 | } ); |
408 | 421 | |
409 | 422 | })(jQuery); |