About page: Cache our zxcvbn calls and limit the variation of the animation.

Merges [25884] to the 3.7 branch.

Diff is mostly whitespace.

props jorbin, azaozz.
fixes #25603.

Built from https://develop.svn.wordpress.org/branches/3.7@25887


git-svn-id: http://core.svn.wordpress.org/branches/3.7@25799 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2013-10-23 19:55:09 +00:00
parent 1ba8a7f373
commit c7e5a7da23
2 changed files with 72 additions and 58 deletions

View File

@ -2,10 +2,19 @@
var password = 'Gosh, WordPress is grand.',
$input = $('#pass'),
shouldAnimate = true,
timesForAnimation = [280, 300, 305, 310, 315, 325, 330, 345, 360, 370, 380, 400, 450, 500, 600],
resultsCache = {},
indicatorString = $('#pass-strength-result').text();
function updateResult(){
var strength = wp.passwordStrength.meter($input.val(), [], $input.val());
var strength;
if ( typeof( resultsCache[ $input.val() ]) === 'undefined') {
strength = wp.passwordStrength.meter($input.val(), [], $input.val());
resultsCache[ $input.val() ] = strength;
} else {
strength = resultsCache[ $input.val() ];
}
$('#pass-strength-result').removeClass('short bad good strong');
switch ( strength ) {
@ -34,13 +43,18 @@
if ($input.val().length < password.length){
$input.val( password.substr(0, $input.val().length + 1) );
updateResult();
// Look like real typing by changing the speed new letters are added each time
setTimeout( animate, ( timesForAnimation[ Math.floor( Math.random() * timesForAnimation.length ) ] ) );
} else {
resetMeter();
// When we reset, let's wait a bit longer than normal to start again
setTimeout(animate, 700);
}
// Look like real typing by changing the speed new letters are added each time
setTimeout(animate, 220 + Math.floor(Math.random() * ( 800 - 220)) );
}
//
function begin(){
// we async load zxcvbn, so we need to make sure it's loaded before starting
if (typeof(zxcvbn) !== 'undefined')

View File

@ -1 +1 @@
!function(a){function b(){var b=wp.passwordStrength.meter(g.val(),[],g.val());switch(a("#pass-strength-result").removeClass("short bad good strong"),b){case 2:a("#pass-strength-result").addClass("bad").html(pwsL10n.bad);break;case 3:a("#pass-strength-result").addClass("good").html(pwsL10n.good);break;case 4:a("#pass-strength-result").addClass("strong").html(pwsL10n.strong);break;default:a("#pass-strength-result").addClass("short").html(pwsL10n["short"])}}function c(){g.val(""),a("#pass-strength-result").text(i),a("#pass-strength-result").removeClass("short bad good strong")}function d(){h!==!1&&(g.val().length<f.length?(g.val(f.substr(0,g.val().length+1)),b()):c(),setTimeout(d,220+Math.floor(580*Math.random())))}function e(){"undefined"!=typeof zxcvbn?d():setTimeout(e,800)}var f="Gosh, WordPress is grand.",g=a("#pass"),h=!0,i=a("#pass-strength-result").text();g.on("focus",function(){h=!1,c()}),g.on("keyup",function(){b()}),e()}(jQuery);
!function(a){function b(){var b;switch("undefined"==typeof j[g.val()]?(b=wp.passwordStrength.meter(g.val(),[],g.val()),j[g.val()]=b):b=j[g.val()],a("#pass-strength-result").removeClass("short bad good strong"),b){case 2:a("#pass-strength-result").addClass("bad").html(pwsL10n.bad);break;case 3:a("#pass-strength-result").addClass("good").html(pwsL10n.good);break;case 4:a("#pass-strength-result").addClass("strong").html(pwsL10n.strong);break;default:a("#pass-strength-result").addClass("short").html(pwsL10n["short"])}}function c(){g.val(""),a("#pass-strength-result").text(k),a("#pass-strength-result").removeClass("short bad good strong")}function d(){h!==!1&&(g.val().length<f.length?(g.val(f.substr(0,g.val().length+1)),b(),setTimeout(d,i[Math.floor(Math.random()*i.length)])):(c(),setTimeout(d,700)))}function e(){"undefined"!=typeof zxcvbn?d():setTimeout(e,800)}var f="Gosh, WordPress is grand.",g=a("#pass"),h=!0,i=[280,300,305,310,315,325,330,345,360,370,380,400,450,500,600],j={},k=a("#pass-strength-result").text();g.on("focus",function(){h=!1,c()}),g.on("keyup",function(){b()}),e()}(jQuery);