diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-admin/js/user-profile.js --- a/wp/wp-admin/js/user-profile.js Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-admin/js/user-profile.js Fri Sep 05 18:40:08 2025 +0200 @@ -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() { @@ -52,7 +55,9 @@ $( '#pw-weak-text-label' ).text( __( 'Confirm use of weak password' ) ); // Focus the password field. - $( $pass1 ).trigger( 'focus' ); + if ( 'mailserver_pass' !== $pass1.prop('id' ) ) { + $( $pass1 ).trigger( 'focus' ); + } } function bindPass1() { @@ -146,7 +151,9 @@ * @param {string} message The message to insert. */ function addInlineNotice( $this, success, message ) { - var resultDiv = $( '
' ); + var resultDiv = $( '
', { + role: 'alert' + } ); // Set up the notice div. resultDiv.addClass( 'notice inline' ); @@ -171,7 +178,7 @@ var $generateButton, $cancelButton; - $pass1Row = $( '.user-pass1-wrap, .user-pass-wrap, .reset-pass-submit' ); + $pass1Row = $( '.user-pass1-wrap, .user-pass-wrap, .mailserver-pass-wrap, .reset-pass-submit' ); // Hide the confirm password field when JavaScript support is enabled. $('.user-pass2-wrap').hide(); @@ -188,7 +195,7 @@ $submitButtons.prop( 'disabled', ! $weakCheckbox.prop( 'checked' ) ); } ); - $pass1 = $('#pass1'); + $pass1 = $('#pass1, #mailserver_pass'); if ( $pass1.length ) { bindPass1(); } else { @@ -309,28 +316,32 @@ $('#pass-strength-result').addClass('short').html( pwsL10n.mismatch ); break; default: - $('#pass-strength-result').addClass('short').html( pwsL10n['short'] ); + $('#pass-strength-result').addClass('short').html( pwsL10n.short ); } } function showOrHideWeakPasswordCheckbox() { - var passStrength = $('#pass-strength-result')[0]; + var passStrengthResult = $('#pass-strength-result'); + + if ( passStrengthResult.length ) { + var passStrength = passStrengthResult[0]; - if ( passStrength.className ) { - $pass1.addClass( passStrength.className ); - if ( $( passStrength ).is( '.short, .bad' ) ) { - if ( ! $weakCheckbox.prop( 'checked' ) ) { - $submitButtons.prop( 'disabled', true ); + if ( passStrength.className ) { + $pass1.addClass( passStrength.className ); + if ( $( passStrength ).is( '.short, .bad' ) ) { + if ( ! $weakCheckbox.prop( 'checked' ) ) { + $submitButtons.prop( 'disabled', true ); + } + $weakRow.show(); + } else { + if ( $( passStrength ).is( '.empty' ) ) { + $submitButtons.prop( 'disabled', true ); + $weakCheckbox.prop( 'checked', false ); + } else { + $submitButtons.prop( 'disabled', false ); + } + $weakRow.hide(); } - $weakRow.show(); - } else { - if ( $( passStrength ).is( '.empty' ) ) { - $submitButtons.prop( 'disabled', true ); - $weakCheckbox.prop( 'checked', false ); - } else { - $submitButtons.prop( 'disabled', false ); - } - $weakRow.hide(); } } } @@ -448,6 +459,12 @@ bindPasswordForm(); bindPasswordResetLink(); + $submitButtons.on( 'click', function() { + isSubmitting = true; + }); + + $form = $( '#your-profile, #createuser' ); + originalFormContent = $form.serialize(); }); $( '#destroy-sessions' ).on( 'click', function( e ) { @@ -459,10 +476,10 @@ }).done( function( response ) { $this.prop( 'disabled', true ); $this.siblings( '.notice' ).remove(); - $this.before( '

' + response.message + '

' ); + $this.before( '' ); }).fail( function( response ) { $this.siblings( '.notice' ).remove(); - $this.before( '

' + response.message + '

' ); + $this.before( '' ); }); e.preventDefault(); @@ -475,7 +492,10 @@ if ( true === updateLock ) { return __( 'Your new password has not been saved.' ); } - } ); + if ( originalFormContent !== $form.serialize() && ! isSubmitting ) { + return __( 'The changes you made will be lost if you navigate away from this page.' ); + } + }); /* * We need to generate a password as soon as the Reset Password page is loaded,