claro-8.x-1.x-dev/js/user.js
js/user.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | /** * DO NOT EDIT THIS FILE. * See the following change record for more information, * @preserve **/ ( function ($, Drupal) { Drupal.behaviors.password = { attach: function attach(context, settings) { var $passwordInput = $(context).find( 'input.js-password-field' ).once( 'password' ); if ($passwordInput.length) { var translate = settings.password; var $passwordInputParent = $passwordInput.parent(); var $passwordWidget = $passwordInput.closest( '.js-form-type-password-confirm' ); var $passwordConfirmInput = $passwordWidget.find( 'input.js-password-confirm' ); var $passwordInputHelp = $(Drupal.theme.passwordInputHelp(translate.strengthTitle)); var $passwordConfirmHelp = $(Drupal.theme.passwordConfirmHelp(translate.confirmTitle)); var $passwordInputStrengthBar = $passwordInputHelp.find( '.js-password-strength-bar' ); var $passwordInputStrengthMessageWrapper = $passwordInputHelp.find( '.js-password-strength-text' ); var $passwordConfirmMatch = $passwordConfirmHelp.find( '.js-password-match-text' ); var $passwordSuggestionsTips = $(Drupal.theme.passwordSuggestionsTips( '' , '' )).hide(); if (settings.password.showStrengthIndicator) { $passwordConfirmInput.after($passwordConfirmHelp).parent().after($passwordSuggestionsTips); $passwordInputParent.append($passwordInputHelp); } var passwordCheckMatch = function passwordCheckMatch(confirmInputVal) { if (confirmInputVal) { var success = $passwordInput.val() === confirmInputVal; var confirmClass = success ? 'ok' : 'error' ; var confirmMatchMessage = success ? translate.confirmSuccess : translate.confirmFailure; if (!$passwordConfirmMatch.hasClass(confirmClass) || !$passwordConfirmMatch.html() === confirmMatchMessage) { $passwordConfirmMatch.html(confirmMatchMessage).removeClass( 'ok error' ).addClass(confirmClass); } } }; var passwordCheck = function passwordCheck() { if (settings.password.showStrengthIndicator) { var result = Drupal.evaluatePasswordStrength($passwordInput.val(), settings.password); var $newSuggestions = $(Drupal.theme.passwordSuggestionsTips(translate.hasWeaknesses, result.tips)); if ($newSuggestions.html() !== $passwordSuggestionsTips.html()) { $passwordSuggestionsTips.replaceWith($newSuggestions); $passwordSuggestionsTips = $newSuggestions; $passwordSuggestionsTips.toggle(result.strength !== 100); } $passwordInputStrengthBar.css( 'width' , result.strength + '%' ).removeClass( 'is-weak is-fair is-good is-strong' ).addClass(result.indicatorClass); if (!$passwordInputStrengthMessageWrapper.hasClass(result.indicatorClass) || !$passwordInputStrengthMessageWrapper.html() === result.indicatorText) { $passwordInputStrengthMessageWrapper.html(result.indicatorText).removeClass( 'is-weak is-fair is-good is-strong' ).addClass(result.indicatorClass); } } $passwordWidget.removeClass( 'is-initial' ).removeClass( 'is-password-empty is-password-filled' ).removeClass( 'is-confirm-empty is-confirm-filled' ); $passwordWidget.addClass($passwordInput.val() ? 'is-password-filled' : 'is-password-empty' ); passwordCheckMatch($passwordConfirmInput.val()); $passwordWidget.addClass($passwordConfirmInput.val() ? 'is-confirm-filled' : 'is-confirm-empty' ); }; $passwordWidget.addClass($passwordInput.val() ? 'is-password-filled' : 'is-password-empty' ).addClass($passwordConfirmInput.val() ? 'is-confirm-filled' : 'is-confirm-empty' ); $passwordInput.on( 'input' , passwordCheck); $passwordConfirmInput.on( 'input' , passwordCheck); } } }; Drupal.evaluatePasswordStrength = function (password, translate) { password = password.trim(); var indicatorText = void 0; var indicatorClass = void 0; var weaknesses = 0; var strength = 100; var tips = []; var hasLowercase = /[a-z]/.test(password); var hasUppercase = /[A-Z]/.test(password); var hasNumbers = /[0-9]/.test(password); var hasPunctuation = /[^a-zA-Z0-9]/.test(password); var $usernameBox = $( 'input.username' ); var username = $usernameBox.length > 0 ? $usernameBox.val() : translate.username; if (password.length < 12) { tips.push(translate.tooShort); strength -= (12 - password.length) * 5 + 30; } if (!hasLowercase) { tips.push(translate.addLowerCase); weaknesses += 1; } if (!hasUppercase) { tips.push(translate.addUpperCase); weaknesses += 1; } if (!hasNumbers) { tips.push(translate.addNumbers); weaknesses += 1; } if (!hasPunctuation) { tips.push(translate.addPunctuation); weaknesses += 1; } switch (weaknesses) { case 1: strength -= 12.5; break ; case 2: strength -= 25; break ; case 3: strength -= 40; break ; case 4: strength -= 40; break ; default : break ; } if (password !== '' && password.toLowerCase() === username.toLowerCase()) { tips.push(translate.sameAsUsername); strength = 5; } if (strength < 60) { indicatorText = translate.weak; indicatorClass = 'is-weak' ; } else if (strength < 70) { indicatorText = translate.fair; indicatorClass = 'is-fair' ; } else if (strength < 80) { indicatorText = translate.good; indicatorClass = 'is-good' ; } else if (strength <= 100) { indicatorText = translate.strong; indicatorClass = 'is-strong' ; } return { strength: strength, tips: tips, indicatorText: indicatorText, indicatorClass: indicatorClass }; }; Drupal.theme.passwordInputHelp = function (message) { return '<div class="password-strength">\n <div class="password-strength__track">\n <div class="password-strength__bar js-password-strength-bar"></div>\n </div>\n <div aria-live="polite" aria-atomic="true" class="password-strength__title">\n ' + message + ' <span class="password-strength__text js-password-strength-text"></span>\n </div>\n </div>' ; }; Drupal.theme.passwordConfirmHelp = function (message) { return '<div aria-live="polite" aria-atomic="true" class="password-match-message">' + message + ' <span class="password-match-message__text js-password-match-text"></span></div>' ; }; Drupal.theme.passwordSuggestionsTips = function (title, tips) { return '<div class="password-suggestions">' + (tips.length ? title + '<ul class="password-suggestions__tips"><li class="password-suggestions__tip">' + tips.join( '</li><li class="password-suggestions__tip">' ) + '</li></ul>' : '' ) + '</div>' ; }; })(jQuery, Drupal); |