2 | | var password = 'Gosh, WordPress is grand.', |
3 | | $input = $('#pass'), |
4 | | shouldAnimate = true, |
5 | | indicatorString = $('#pass-strength-result').text(); |
| 2 | var password = 'Gosh, WordPress is grand.', |
| 3 | $input = $('#pass'), |
| 4 | shouldAnimate = true, |
| 5 | timesForAnimation = [280, 300, 305, 310, 315, 325, 330, 345, 360, 370, 380, 400, 450, 500, 600], |
| 6 | resultsCache = {}, |
| 7 | indicatorString = $('#pass-strength-result').text(); |
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 | | function resetMeter(){ |
26 | | $input.val(''); |
27 | | $('#pass-strength-result').text(indicatorString); |
28 | | $('#pass-strength-result').removeClass('short bad good strong'); |
29 | | } |
| 12 | if ( typeof( resultsCache[ $input.val() ]) === 'undefined') { |
| 13 | strength = wp.passwordStrength.meter($input.val(), [], $input.val()); |
| 14 | resultsCache[ $input.val() ] = strength; |
| 15 | } else { |
| 16 | strength = resultsCache[ $input.val() ]; |
| 17 | } |
31 | | function animate(){ |
32 | | if (shouldAnimate === false) |
33 | | return; |
34 | | if ($input.val().length < password.length){ |
35 | | $input.val( password.substr(0, $input.val().length + 1) ); |
36 | | updateResult(); |
37 | | } else { |
38 | | resetMeter(); |
39 | | } |
40 | | // Look like real typing by changing the speed new letters are added each time |
41 | | setTimeout(animate, 220 + Math.floor(Math.random() * ( 800 - 220)) ); |
42 | | } |
43 | | // |
44 | | function begin(){ |
45 | | // we async load zxcvbn, so we need to make sure it's loaded before starting |
46 | | if (typeof(zxcvbn) !== 'undefined') |
47 | | animate(); |
48 | | else |
49 | | setTimeout(begin,800); |
50 | | } |
| 19 | $('#pass-strength-result').removeClass('short bad good strong'); |
| 20 | switch ( strength ) { |
| 21 | case 2: |
| 22 | $('#pass-strength-result').addClass('bad').html( pwsL10n['bad'] ); |
| 23 | break; |
| 24 | case 3: |
| 25 | $('#pass-strength-result').addClass('good').html( pwsL10n['good'] ); |
| 26 | break; |
| 27 | case 4: |
| 28 | $('#pass-strength-result').addClass('strong').html( pwsL10n['strong'] ); |
| 29 | break; |
| 30 | default: |
| 31 | $('#pass-strength-result').addClass('short').html( pwsL10n['short'] ); |
| 32 | } |
| 33 | } |
| 34 | function resetMeter(){ |
| 35 | $input.val(''); |
| 36 | $('#pass-strength-result').text(indicatorString); |
| 37 | $('#pass-strength-result').removeClass('short bad good strong'); |
| 38 | } |