1(function ($) { 2 3 Drupal.behaviors.captcha = { 4 attach: function (context) { 5 6 // Turn off autocompletion for the CAPTCHA response field. 7 // We do it here with JavaScript (instead of directly in the markup) 8 // because this autocomplete attribute is not standard and 9 // it would break (X)HTML compliance. 10 $("#edit-captcha-response").attr("autocomplete", "off"); 11 12 } 13 }; 14 15 Drupal.behaviors.captchaAdmin = { 16 attach: function (context) { 17 // Add onclick handler to checkbox for adding a CAPTCHA description 18 // so that the textfields for the CAPTCHA description are hidden 19 // when no description should be added. 20 // @todo: div.form-item-captcha-description depends on theming, maybe 21 // it's better to add our own wrapper with id (instead of a class). 22 $("#edit-captcha-add-captcha-description").click(function() { 23 if ($("#edit-captcha-add-captcha-description").is(":checked")) { 24 // Show the CAPTCHA description textfield(s). 25 $("div.form-item-captcha-description").show('slow'); 26 } 27 else { 28 // Hide the CAPTCHA description textfield(s). 29 $("div.form-item-captcha-description").hide('slow'); 30 } 31 }); 32 // Hide the CAPTCHA description textfields if option is disabled on page load. 33 if (!$("#edit-captcha-add-captcha-description").is(":checked")) { 34 $("div.form-item-captcha-description").hide(); 35 } 36 } 37 38 }; 39 40})(jQuery); 41; 42(function ($) { 43 44/** 45 * Attach handlers to evaluate the strength of any password fields and to check 46 * that its confirmation is correct. 47 */ 48Drupal.behaviors.password = { 49 attach: function (context, settings) { 50 var translate = settings.password; 51 $('input.password-field', context).once('password', function () { 52 var passwordInput = $(this); 53 var innerWrapper = $(this).parent(); 54 var outerWrapper = $(this).parent().parent(); 55 56 // Add identifying class to password element parent. 57 innerWrapper.addClass('password-parent'); 58 59 // Add the password confirmation layer. 60 $('input.password-confirm', outerWrapper).parent().prepend('<div class="password-confirm">' + translate['confirmTitle'] + ' <span></span></div>').addClass('confirm-parent'); 61 var confirmInput = $('input.password-confirm', outerWrapper); 62 var confirmResult = $('div.password-confirm', outerWrapper); 63 var confirmChild = $('span', confirmResult); 64 65 // Add the description box. 66 var passwordMeter = '<div class="password-strength"><div class="password-strength-text" aria-live="assertive"></div><div class="password-strength-title">' + translate['strengthTitle'] + '</div><div class="password-indicator"><div class="indicator"></div></div></div>'; 67 $(confirmInput).parent().after('<div class="password-suggestions description"></div>'); 68 $(innerWrapper).prepend(passwordMeter); 69 var passwordDescription = $('div.password-suggestions', outerWrapper).hide(); 70 71 // Check the password strength. 72 var passwordCheck = function () { 73 74 // Evaluate the password strength. 75 var result = Drupal.evaluatePasswordStrength(passwordInput.val(), settings.password); 76 77 // Update the suggestions for how to improve the password. 78 if (passwordDescription.html() != result.message) { 79 passwordDescription.html(result.message); 80 } 81 82 // Only show the description box if there is a weakness in the password. 83 if (result.strength == 100) { 84 passwordDescription.hide(); 85 } 86 else { 87 passwordDescription.show(); 88 } 89 90 // Adjust the length of the strength indicator. 91 $(innerWrapper).find('.indicator').css('width', result.strength + '%'); 92 93 // Update the strength indication text. 94 $(innerWrapper).find('.password-strength-text').html(result.indicatorText); 95 96 passwordCheckMatch(); 97 }; 98 99 // Check that password and confirmation inputs match. 100 var passwordCheckMatch = function () { 101 102 if (confirmInput.val()) { 103 var success = passwordInput.val() === confirmInput.val(); 104 105 // Show the confirm result. 106 confirmResult.css({ visibility: 'visible' }); 107 108 // Remove the previous styling if any exists. 109 if (this.confirmClass) { 110 confirmChild.removeClass(this.confirmClass); 111 } 112 113 // Fill in the success message and set the class accordingly. 114 var confirmClass = success ? 'ok' : 'error'; 115 confirmChild.html(translate['confirm' + (success ? 'Success' : 'Failure')]).addClass(confirmClass); 116 this.confirmClass = confirmClass; 117 } 118 else { 119 confirmResult.css({ visibility: 'hidden' }); 120 } 121 }; 122 123 // Monitor keyup and blur events. 124 // Blur must be used because a mouse paste does not trigger keyup.
125 passwordInput.keyup(passwordCheck).focus(passwordCheck).blur(passwordCheck); 126 confirmInput.keyup(passwordCheckMatch).blur(passwordCheckMatch); 127 }); 128 } 129}; 130 131/** 132 * Evaluate the strength of a user's password. 133 * 134 * Returns the estimated strength and the relevant output message. 135 */ 136Drupal.evaluatePasswordStrength = function (password, translate) { 137 password = $.trim(password); 138 139 var weaknesses = 0, strength = 100, msg = []; 140 141 var hasLowercase = /[a-z]+/.test(password); 142 var hasUppercase = /[A-Z]+/.test(password); 143 var hasNumbers = /[0-9]+/.test(password); 144 var hasPunctuation = /[^a-zA-Z0-9]+/.test(password); 145 146 // If there is a username edit box on the page, compare password to that, otherwise 147 // use value from the database. 148 var usernameBox = $('input.username'); 149 var username = (usernameBox.length > 0) ? usernameBox.val() : translate.username; 150 151 // Lose 5 points for every character less than 6, plus a 30 point penalty. 152 if (password.length < 6) { 153 msg.push(translate.tooShort); 154 strength -= ((6 - password.length) * 5) + 30; 155 } 156 157 // Count weaknesses. 158 if (!hasLowercase) { 159 msg.push(translate.addLowerCase); 160 weaknesses++; 161 } 162 if (!hasUppercase) { 163 msg.push(translate.addUpperCase); 164 weaknesses++; 165 } 166 if (!hasNumbers) { 167 msg.push(translate.addNumbers); 168 weaknesses++; 169 } 170 if (!hasPunctuation) { 171 msg.push(translate.addPunctuation); 172 weaknesses++; 173 } 174 175 // Apply penalty for each weakness (balanced against length penalty). 176 switch (weaknesses) { 177 case 1: 178 strength -= 12.5; 179 break; 180 181 case 2: 182 strength -= 25; 183 break; 184 185 case 3: 186 strength -= 40; 187 break; 188 189 case 4: 190 strength -= 40; 191 break; 192 } 193 194 // Check if password is the same as the username. 195 if (password !== '' && password.toLowerCase() === username.toLowerCase()) { 196 msg.push(translate.sameAsUsername); 197 // Passwords the same as username are always very weak. 198 strength = 5; 199 } 200 201 // Based on the strength, work out what text should be shown by the password strength meter. 202 if (strength < 60) { 203 indicatorText = translate.weak; 204 } else if (strength < 70) { 205 indicatorText = translate.fair; 206 } else if (strength < 80) { 207 indicatorText = translate.good; 208 } else if (strength <= 100) { 209 indicatorText = translate.strong; 210 } 211 212 // Assemble the final message. 213 msg = translate.hasWeaknesses + '<ul><li>' + msg.join('</li><li>') + '</li></ul>'; 214 return { strength: strength, message: msg, indicatorText: indicatorText }; 215 216}; 217 218/** 219 * Field instance settings screen: force the 'Display on registration form' 220 * checkbox checked whenever 'Required' is checked. 221 */ 222Drupal.behaviors.fieldUserRegistration = { 223 attach: function (context, settings) { 224 var $checkbox = $('form#field-ui-field-edit-form input#edit-instance-settings-user-register-form'); 225 226 if ($checkbox.length) { 227 $('input#edit-instance-required', context).once('user-register-form-checkbox', function () { 228 $(this).bind('change', function (e) { 229 if ($(this).attr('checked')) { 230 $checkbox.attr('checked', true); 231 } 232 }); 233 }); 234 235 } 236 } 237}; 238 239})(jQuery); 240;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.