Created
April 3, 2013 23:56
-
-
Save thsutton/5306555 to your computer and use it in GitHub Desktop.
Patch Drupal's user module JS to add classes to the password field indicators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/htdocs/modules/user/user.js b/htdocs/modules/user/user.js | |
| index d182066..e5e5abc 100644 | |
| --- a/htdocs/modules/user/user.js | |
| +++ b/htdocs/modules/user/user.js | |
| @@ -52,6 +52,11 @@ Drupal.behaviors.password = { | |
| // Update the strength indication text. | |
| $(innerWrapper).find('.password-strength-text').html(result.indicatorText); | |
| + $(innerWrapper).find('div.password-strength') | |
| + .removeClass('password-strength-error') | |
| + .removeClass('password-strength-warn') | |
| + .removeClass('password-strength-ok') | |
| + .addClass('password-strength-' + result.level); | |
| passwordCheckMatch(); | |
| }; | |
| @@ -73,6 +78,9 @@ Drupal.behaviors.password = { | |
| var confirmClass = success ? 'ok' : 'error'; | |
| confirmChild.html(translate['confirm' + (success ? 'Success' : 'Failure')]).addClass(confirmClass); | |
| this.confirmClass = confirmClass; | |
| + confirmResult.removeClass('password-confirm-ok') | |
| + .removeClass('password-confirm-error') | |
| + .addClass('password-confirm-' + confirmClass); | |
| } | |
| else { | |
| confirmResult.css({ visibility: 'hidden' }); | |
| @@ -157,18 +165,22 @@ Drupal.evaluatePasswordStrength = function (password, translate) { | |
| // Based on the strength, work out what text should be shown by the password strength meter. | |
| if (strength < 60) { | |
| + level = 'weak'; | |
| indicatorText = translate.weak; | |
| } else if (strength < 70) { | |
| + level = 'fair'; | |
| indicatorText = translate.fair; | |
| } else if (strength < 80) { | |
| + level = 'good'; | |
| indicatorText = translate.good; | |
| } else if (strength <= 100) { | |
| + level = 'strong'; | |
| indicatorText = translate.strong; | |
| } | |
| // Assemble the final message. | |
| msg = translate.hasWeaknesses + '<ul><li>' + msg.join('</li><li>') + '</li></ul>'; | |
| - return { strength: strength, message: msg, indicatorText: indicatorText }; | |
| + return { strength: strength, level: level, message: msg, indicatorText: indicatorText }; | |
| }; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment