Make WordPress Core

Changeset 34060


Ignore:
Timestamp:
09/11/2015 09:51:31 PM (11 years ago)
Author:
ocean90
Message:

Passwords: Refresh password fields when content is pasted into fields.

Use feature detection to determine whether password inputs should use the keyup or input event.

Props peterwilsoncc, adamsilverstein.
Fixes #33398.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/user-profile.js

    r33766 r34060  
    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;
     17
     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        } else {
     26                inputEvent = 'keyup';
     27        }
    1928
    2029        function generatePassword() {
     
    4857                        .data( 'pw', $pass1.data( 'pw' ) )
    4958                        .val( $pass1.val() )
    50                         .on( 'keyup', function () {
     59                        .on( inputEvent, function () {
    5160                                if ( $pass1Text.val() === currentPass ) {
    5261                                        return;
     
    6372                }
    6473
    65                 $pass1.on( 'keyup pwupdate', function () {
     74                $pass1.on( inputEvent + ' pwupdate', function () {
    6675                        if ( $pass1.val() === currentPass ) {
    6776                                return;
     
    166175                 * pass2 field to the pass1 field, then running check_pass_strength.
    167176                 */
    168                 $pass2 = $('#pass2').on( 'keyup', function () {
     177                $pass2 = $('#pass2').on( inputEvent, function () {
    169178                        if ( $pass2.val().length > 0 ) {
    170179                                $pass1.val( $pass2.val() );
     
    251260                        select = $( '#display_name' );
    252261
    253                 $('#pass1').val('').on( 'keyup pwupdate', check_pass_strength );
     262                $('#pass1').val('').on( inputEvent + ' pwupdate', check_pass_strength );
    254263                $('#pass-strength-result').show();
    255264                $('.color-palette').click( function() {
Note: See TracChangeset for help on using the changeset viewer.