Users: Add JS confirmation if user profile has unsaved changes.

Add a confirmation dialog when users navigate away from the user profile screen if they have unsaved changes to prevent data loss.

Props ashokrane, karlijnbk, diedeexterkate, jwgoedert, joedolson, swissspidy, afercia.
Fixes #40493.
Built from https://develop.svn.wordpress.org/trunk@58137


git-svn-id: http://core.svn.wordpress.org/trunk@57602 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2024-05-12 18:45:14 +00:00
parent fd4159ed87
commit 39c3bec9f3
3 changed files with 15 additions and 3 deletions

View File

@ -5,6 +5,7 @@
/* global ajaxurl, pwsL10n, userProfileL10n */
(function($) {
var updateLock = false,
isSubmitting = false,
__ = wp.i18n.__,
$pass1Row,
$pass1,
@ -15,6 +16,8 @@
$submitButtons,
$submitButton,
currentPass,
$form,
originalFormContent,
$passwordWrapper;
function generatePassword() {
@ -454,6 +457,12 @@
bindPasswordForm();
bindPasswordResetLink();
$submitButtons.on( 'click', function() {
isSubmitting = true;
});
$form = $( '#your-profile, #createuser' );
originalFormContent = $form.serialize();
});
$( '#destroy-sessions' ).on( 'click', function( e ) {
@ -481,7 +490,10 @@
if ( true === updateLock ) {
return __( 'Your new password has not been saved.' );
}
} );
if ( originalFormContent !== $form.serialize() && ! isSubmitting ) {
return __( 'Changes that you made may not be saved.' );
}
});
/*
* We need to generate a password as soon as the Reset Password page is loaded,

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.6-alpha-58136';
$wp_version = '6.6-alpha-58137';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.