Make WordPress Core

Ticket #42749: 42749-2.patch

File 42749-2.patch, 3.2 KB (added by alexstine, 6 years ago)

Patch #2. Remove focus on password field.

  • wp-admin/js/user-profile.js

     
    161161                // hide this
    162162                $('.user-pass2-wrap').hide();
    163163
    164                 $submitButton = $( '#submit, #wp-submit' ).on( 'click', function () {
     164                $submitButton = $( '#submit' ).on( 'click', function () {
    165165                        updateLock = false;
    166166                });
    167167
     
    205205
    206206                bindToggleButton();
    207207
    208                 if ( $generateButton.length ) {
    209                         $passwordWrapper.hide();
    210                 }
     208                $generateButton.on( 'click', function() {
     209                        if($generateButton.hasClass( 'open' ) ) {
     210                                $generateButton.removeClass( 'open' );
     211                                // Clear any entered password.
     212                                $pass1Text.val( '' );
    211213
    212                 $generateButton.show();
    213                 $generateButton.on( 'click', function () {
    214                         updateLock = true;
     214                                // Generate a new password.
     215                                wp.ajax.post( 'generate-password' )
     216                                        .done( function( data ) {
     217                                                $pass1.data( 'pw', data );
     218                                        } );
    215219
    216                         $generateButton.hide();
    217                         $passwordWrapper.show();
     220                                $passwordWrapper.hide();
     221                                $generateButton.attr( 'aria-expanded', false );
    218222
    219                         // Enable the inputs when showing.
    220                         $pass1.attr( 'disabled', false );
    221                         $pass2.attr( 'disabled', false );
    222                         $pass1Text.attr( 'disabled', false );
     223                                $weakRow.hide( 0, function () {
     224                                        $weakCheckbox.removeProp( 'checked' );
     225                                } );
    223226
    224                         if ( $pass1Text.val().length === 0 ) {
    225                                 generatePassword();
     227                                // Disable the inputs when hiding to prevent autofill and submission.
     228                                $pass1.prop( 'disabled', true );
     229                                $pass2.prop( 'disabled', true );
     230                                $pass1Text.prop( 'disabled', true );
     231
     232                                resetToggle();
     233
     234                                if ( $pass1Row.closest( 'form' ).is( '#your-profile' ) ) {
     235                                        // Clear password field to prevent update
     236                                        $pass1.val( '' ).trigger( 'pwupdate' );
     237                                        $submitButtons.prop( 'disabled', false );
     238                                }
     239                        } else {
     240                                $generateButton.addClass( 'open' );
     241                                $generateButton.attr( 'aria-expanded', true );
     242                                $passwordWrapper.show();
     243
     244                                // Enable the inputs when showing.
     245                                $pass1.attr( 'disabled', false );
     246                                $pass2.attr( 'disabled', false );
     247                                $pass1Text.attr( 'disabled', false );
     248
     249                                if ( $pass1Text.val().length === 0 ) {
     250                                        generatePassword();
     251                                }
    226252                        }
    227 
    228253                        _.defer( function() {
    229                                 $pass1Text.focus();
    230254                                if ( ! _.isUndefined( $pass1Text[0].setSelectionRange ) ) {
    231255                                        $pass1Text[0].setSelectionRange( 0, 100 );
    232256                                }
     
    237261                $cancelButton.on( 'click', function () {
    238262                        updateLock = false;
    239263
     264                        $generateButton.removeClass( 'open' );
     265
    240266                        // Clear any entered password.
    241267                        $pass1Text.val( '' );
    242268
     
    246272                                        $pass1.data( 'pw', data );
    247273                                } );
    248274
    249                         $generateButton.show();
     275                        $generateButton.attr( 'aria-expanded', false ).focus();
    250276                        $passwordWrapper.hide();
    251277
    252278                        $weakRow.hide( 0, function () {
     
    314340
    315341                if ( passStrength.className ) {
    316342                        $pass1.add( $pass1Text ).addClass( passStrength.className );
    317                         if ( $( passStrength ).is( '.short, .bad' ) ) {
     343                        if ( 'short' === passStrength.className || 'bad' === passStrength.className ) {
    318344                                if ( ! $weakCheckbox.prop( 'checked' ) ) {
    319345                                        $submitButtons.prop( 'disabled', true );
    320346                                }