]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/user-profile.js
Wordpress 4.6
[autoinstalls/wordpress.git] / wp-admin / js / user-profile.js
index 5ec77bc867683bdfeb79b05be03e20448db95787..c5f5db36eaefe80d502642217b1baa4946f802b6 100644 (file)
        function generatePassword() {
                if ( typeof zxcvbn !== 'function' ) {
                        setTimeout( generatePassword, 50 );
-               } else {
+                       return;
+               } else if ( ! $pass1.val() ) {
+                       // zxcvbn loaded before user entered password.
                        $pass1.val( $pass1.data( 'pw' ) );
-                       $pass1.trigger( 'pwupdate' ).trigger( 'wp-check-valid-field' );
-                       if ( 1 !== parseInt( $toggleButton.data( 'start-masked' ), 10 ) ) {
-                               $pass1Wrap.addClass( 'show-password' );
-                       } else {
-                               $toggleButton.trigger( 'click' );
-                       }
+                       $pass1.trigger( 'pwupdate' );
+                       showOrHideWeakPasswordCheckbox();
+               }
+               else {
+                       // zxcvbn loaded after the user entered password, check strength.
+                       check_pass_strength();
+                       showOrHideWeakPasswordCheckbox();
                }
+
+               if ( 1 !== parseInt( $toggleButton.data( 'start-masked' ), 10 ) ) {
+                       $pass1Wrap.addClass( 'show-password' );
+               } else {
+                       $toggleButton.trigger( 'click' );
+               }
+
+               // Once zxcvbn loads, passwords strength is known.
+               $( '#pw-weak-text-label' ).html( userProfileL10n.warnWeak );
        }
 
        function bindPass1() {
-               var passStrength = $('#pass-strength-result')[0];
-
                currentPass = $pass1.val();
 
                $pass1Wrap = $pass1.parent();
                                $pass1Text.val( currentPass );
                        }
                        $pass1.add( $pass1Text ).removeClass( 'short bad good strong' );
-
-                       if ( passStrength.className ) {
-                               $pass1.add( $pass1Text ).addClass( passStrength.className );
-                               if ( 'short' === passStrength.className || 'bad' === passStrength.className ) {
-                                       if ( ! $weakCheckbox.prop( 'checked' ) ) {
-                                               $submitButtons.prop( 'disabled', true );
-                                       }
-                                       $weakRow.show();
-                               } else {
-                                       $submitButtons.prop( 'disabled', false );
-                                       $weakRow.hide();
-                               }
-                       }
+                       showOrHideWeakPasswordCheckbox();
                } );
        }
 
                strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass1 );
 
                switch ( strength ) {
+                       case -1:
+                               $( '#pass-strength-result' ).addClass( 'bad' ).html( pwsL10n.unknown );
+                               break;
                        case 2:
                                $('#pass-strength-result').addClass('bad').html( pwsL10n.bad );
                                break;
                }
        }
 
+       function showOrHideWeakPasswordCheckbox() {
+               var passStrength = $('#pass-strength-result')[0];
+
+               if ( passStrength.className ) {
+                       $pass1.add( $pass1Text ).addClass( passStrength.className );
+                       if ( 'short' === passStrength.className || 'bad' === passStrength.className ) {
+                               if ( ! $weakCheckbox.prop( 'checked' ) ) {
+                                       $submitButtons.prop( 'disabled', true );
+                               }
+                               $weakRow.show();
+                       } else {
+                               $submitButtons.prop( 'disabled', false );
+                               $weakRow.hide();
+                       }
+               }
+       }
+
        $(document).ready( function() {
                var $colorpicker, $stylesheet, user_id, current_user_id,
                        select = $( '#display_name' );