Make WordPress Core

Ticket #33398: 33398.2.diff

File 33398.2.diff, 2.0 KB (added by adamsilverstein, 9 years ago)
  • src/wp-admin/js/user-profile.js

    (this hunk was shorter than expected) 
    66                $pass1Wrap,
    77                $pass1,
    88                $pass1Text,
    9 
    109                $pass2,
    11 
    1210                $weakRow,
    1311                $weakCheckbox,
    14 
    1512                $toggleButton,
    1613                $submitButtons,
    1714                $submitButton,
    18                 currentPass;
     15                currentPass,
     16                inputEvent;
    1917
     18        /**
     19         * Use feature detection to determine whether password inputs should use
     20         * the `keyup` or `input` event. Input is preferred but lacks support
     21         * in legacy browsers.
     22         */
     23        if ( 'oninput' in document.createElement('input') ) {
     24                inputEvent = 'input';
     25        }
     26        else {
     27                inputEvent = 'keyup';
     28        }
     29
    2030        function generatePassword() {
    2131                if ( typeof zxcvbn !== 'function' ) {
    2232                        setTimeout( generatePassword, 50 );
     
    4759                        .addClass( $pass1[0].className )
    4860                        .data( 'pw', $pass1.data( 'pw' ) )
    4961                        .val( $pass1.val() )
    50                         .on( 'keyup', function () {
     62                        .on( inputEvent, function () {
    5163                                if ( $pass1Text.val() === currentPass ) {
    5264                                        return;
    5365                                }
     
    6274                        generatePassword();
    6375                }
    6476
    65                 $pass1.on( 'keyup pwupdate', function () {
     77                $pass1.on( inputEvent + ' pwupdate', function () {
    6678                        if ( $pass1.val() === currentPass ) {
    6779                                return;
    6880                        }
     
    165177                 * This fixes the issue by copying any changes from the hidden
    166178                 * pass2 field to the pass1 field, then running check_pass_strength.
    167179                 */
    168                 $pass2 = $('#pass2').on( 'keyup', function () {
     180                $pass2 = $('#pass2').on( inputEvent, function () {
    169181                        if ( $pass2.val().length > 0 ) {
    170182                                $pass1.val( $pass2.val() );
    171183                                $pass2.val('');
     
    250262                var $colorpicker, $stylesheet, user_id, current_user_id,
    251263                        select = $( '#display_name' );
    252264
    253                 $('#pass1').val('').on( 'keyup pwupdate', check_pass_strength );
     265                $('#pass1').val('').on( inputEvent + ' pwupdate', check_pass_strength );
    254266                $('#pass-strength-result').show();
    255267                $('.color-palette').click( function() {
    256268                        $(this).siblings('input[name="admin_color"]').prop('checked', true);