diff --git a/core/modules/user/user.js b/core/modules/user/user.js index f4602c6..4364bf3 100644 --- a/core/modules/user/user.js +++ b/core/modules/user/user.js @@ -35,7 +35,7 @@ $passwordInputParentWrapper .find('input.js-password-confirm') .parent() - .append('
' + translate.confirmTitle + '
') + .append(Drupal.theme('passwordMatchIndicator', translate)) .addClass('confirm-parent'); var $confirmInput = $passwordInputParentWrapper.find('input.js-password-confirm'); @@ -44,8 +44,8 @@ // If the password strength indicator is enabled, add its markup. if (settings.password.showStrengthIndicator) { - var passwordMeter = '
' + translate.strengthTitle + '
'; - $confirmInput.parent().after('
'); + var passwordMeter = Drupal.theme('passwordMeter', translate); + $confirmInput.parent().after(Drupal.theme('passwordSuggestions')); $passwordInputParent.append(passwordMeter); $passwordSuggestions = $passwordInputParentWrapper.find('div.password-suggestions').hide(); } @@ -214,4 +214,50 @@ }; + $.extend(Drupal.theme, /** @lends Drupal.theme */ { + + /** + * Theme function for a password strength meter. + * + * @param {object} translate + * An object with the following keys: + * @param {string} translate.strengthTitle + * The text label prepended to the password strength indicator. + * + * @return {string} + * This function returns a string with the required password strength + * meter HTML. + */ + passwordMeter: function (translate) { + return '
' + translate.strengthTitle + '
'; + }, + + /** + * Theme functions for a password match indicator. + * + * @param {object} translate + * An object with the following keys: + * @param {string} translate.confirmTitle + * The text label prepended to the password match indicator. + * + * @return {string} + * This function returns a string with the HTML markup used to show + * whether the user has entered matching passwords. + */ + passwordMatchIndicator: function (translate) { + return '
' + translate.confirmTitle + '
'; + }, + + /** + * Theme functions for a password strength suggestions list. + * + * @return {string} + * This function returns an HTML div where a list of suggestions are + * inserted to explain ways the user can make their password stronger. + */ + passwordSuggestions: function () { + return '
'; + } + }); + })(jQuery, Drupal, drupalSettings);