| | 1 | (function($){ |
| | 2 | var password = 'Gosh, WordPress is grand.', |
| | 3 | $input = $('#pass'), |
| | 4 | shouldAnimate = true, |
| | 5 | indicatorString = $('#pass-strength-result').text(); |
| | 6 | |
| | 7 | function updateResult(){ |
| | 8 | var strength = wp.passwordStrength.meter($input.val(), [], $input.val()); |
| | 9 | |
| | 10 | $('#pass-strength-result').removeClass('short bad good strong'); |
| | 11 | switch ( strength ) { |
| | 12 | case 2: |
| | 13 | $('#pass-strength-result').addClass('bad').html( pwsL10n['bad'] ); |
| | 14 | break; |
| | 15 | case 3: |
| | 16 | $('#pass-strength-result').addClass('good').html( pwsL10n['good'] ); |
| | 17 | break; |
| | 18 | case 4: |
| | 19 | $('#pass-strength-result').addClass('strong').html( pwsL10n['strong'] ); |
| | 20 | break; |
| | 21 | default: |
| | 22 | $('#pass-strength-result').addClass('short').html( pwsL10n['short'] ); |
| | 23 | } |
| | 24 | } |
| | 25 | |
| | 26 | function animate(){ |
| | 27 | if (shouldAnimate === false) |
| | 28 | return; |
| | 29 | if ($input.val().length < password.length){ |
| | 30 | $input.val( password.substr(0, $input.val().length + 1) ); |
| | 31 | updateResult(); |
| | 32 | } else { |
| | 33 | $input.val(''); |
| | 34 | $('#pass-strength-result').removeClass('short bad good strong'); |
| | 35 | } |
| | 36 | // Look like real typing by changing the speed new letters are added each time |
| | 37 | setTimeout(animate, 220 + Math.floor(Math.random() * ( 800 - 220)) ); |
| | 38 | } |
| | 39 | |
| | 40 | |
| | 41 | // Turn off the animation on focus |
| | 42 | $input.on('focus', function(){ |
| | 43 | shouldAnimate = false; |
| | 44 | $('#pass-strength-result').removeClass('short bad good strong'); |
| | 45 | $('#pass-strength-result').text(indicatorString); |
| | 46 | $input.val('') |
| | 47 | }); |
| | 48 | |
| | 49 | // Act like a normal password strength meter |
| | 50 | $input.on('keyup', function(){ |
| | 51 | updateResult(); |
| | 52 | }); |
| | 53 | |
| | 54 | // Start the animation |
| | 55 | setTimeout(animate, 1200); |
| | 56 | |
| | 57 | })(jQuery) |