Make WordPress Core

Ticket #32886: 32886.2.diff

File 32886.2.diff, 2.1 KB (added by peterwilsoncc, 10 years ago)
  • src/wp-admin/js/user-profile.js

    diff --git a/src/wp-admin/js/user-profile.js b/src/wp-admin/js/user-profile.js
    index 86c214f..cfc32cd 100644
    a b  
    2222                        } else {
    2323                                pw_field.val( pw_field.data( 'pw' ) );
    2424                                pw_field.trigger( 'propertychange' );
    25                                 pw_field.attr( 'type', 'text' ).focus();
    26                                 pw_field[0].setSelectionRange(100, 100);
     25                                pw_field = toggleField( pw_field, 1 );
     26                                pw_field.focus();
     27                                if ( 'undefined' !== typeof pw_field[0].setSelectionRange ){
     28                                        pw_field[0].setSelectionRange(100, 100);
     29                                }
    2730                        }
    2831                };
    2932
     
    3841
    3942                parentform.on('submit', function(){
    4043                        pw_field2.val( pw_field.val() );
    41                         pw_field.attr('type', 'password');
     44                        pw_field = toggleField( pw_field, 0 );
    4245                });
    4346
    4447
     
    9396                pw_togglebtn.on( 'click', function() {
    9497                        var show = pw_togglebtn.attr( 'data-toggle' );
    9598                        if ( show == 1 ) {
    96                                 pw_field.attr( 'type', 'text' );
     99                                pw_field = toggleField( pw_field, 1 );
    97100                                pw_togglebtn.attr( 'data-toggle', 0 )
    98101                                        .find( '.text' )
    99102                                                .text( 'hide' )
    100103                                ;
    101104                        } else {
    102                                 pw_field.attr( 'type', 'password' );
     105                                pw_field = toggleField( pw_field, 0 );
    103106                                pw_togglebtn.attr( 'data-toggle', 1 )
    104107                                        .find( '.text' )
    105108                                                .text( 'show' )
    106109                                ;
    107110                        }
    108111                        pw_field.focus();
    109                         pw_field[0].setSelectionRange(100, 100);
     112                        if ( 'undefined' !== typeof pw_field[0].setSelectionRange ){
     113                                pw_field[0].setSelectionRange(100, 100);
     114                        }
    110115                });
     116
    111117        });
    112118
     119        function toggleField( pw_field, show ) {
     120                var newField = document.createElement( 'input' );
     121                var type = 'password';
     122                var $newField;
     123
     124                if ( 1 == show ) {
     125                        type = 'text';
     126                }
     127
     128                newField.type = type;
     129                $newField = $( newField );
     130
     131                $newField
     132                .attr({
     133                        'id'   : 'pass1',
     134                        'name' : 'pass1',
     135                        'autocomplete' : 'off'
     136                })
     137                .addClass( pw_field[0].className )
     138                .data( 'pw', pw_field.data( 'pw' ) );
     139                $newField.val( pw_field.val() );
     140
     141                pw_field.replaceWith( $newField );
     142                return $newField;
     143        }
     144
    113145        function check_pass_strength() {
    114146                var pass1 = $('#pass1').val(), pass2 = $('#pass2').val(), strength;
    115147