Make WordPress Core

Ticket #32886: 32886.3.diff

File 32886.3.diff, 3.3 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 99eae64..72130f7 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
    45                 pw_field.on('input propertychange', function(){
     48                parentform.on('input keyup propertychange', '#pass1', function(){
    4649                        setTimeout( function(){
    4750                                var cssClass = pw_strength.attr('class');
    4851                                pw_field.removeClass( 'short bad good strong' );
     
    7982                 * This fixes the issue by copying any changes from the hidden
    8083                 * pass2 field to the pass1 field.
    8184                 */
    82                 pw_field2.on( 'input propertychange', function() {
     85                pw_field2.on( 'input keyup propertychange', function() {
    8386                        pw_field.val( pw_field2.val() );
    8487                        pw_field.trigger( 'propertychange' );
    8588                } );
     
    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
     
    141173
    142174        $(document).ready( function() {
    143175                var $colorpicker, $stylesheet, user_id, current_user_id,
    144                         select = $( '#display_name' );
     176                        select = $( '#display_name' ),
     177                        pw_form = $('#pass1').closest('form');
    145178
    146                 $('#pass1').val('').on( 'input propertychange', check_pass_strength );
    147                 $('#pass2').val('').on( 'input propertychange', check_pass_strength );
     179                $('#pass1').val('');
     180                $('#pass2').val('');
     181                pw_form.on( 'input  keyup propertychange', '#pass1, #pass2', check_pass_strength );
    148182                $('#pass-strength-result').show();
    149183                $('.color-palette').click( function() {
    150184                        $(this).siblings('input[name="admin_color"]').prop('checked', true);