refactored PasswordForm constructor to take args parameter instead of explicit parameters

This commit is contained in:
Chris Karlof 2013-01-09 09:37:03 -08:00
Родитель 39d61fa4ba
Коммит 608ef4eb9b
2 изменённых файлов: 24 добавлений и 13 удалений

Просмотреть файл

@ -207,13 +207,20 @@ var PasswordForm = function($, DomMonitor) {
return { el: el, $el: $(el), val: "" };
}
// PasswordForm constructor function
// PasswordForm constructor function. <args> should contain the following:
// id: unqiue id value
// passwordEl: DOM element representing the password element in this form
// passwordEl: (optional) DOM element representing the password element in this form
// usernameEl: (optional) DOM element representing the username element in this form
// containingEl: DOM element representing the "form" element that contains
// the passwordEl (note: need not be an HTML form)
// siteConfig: site configuration hash for special site specific handling
var PasswordForm = function(id, passwordEl, containingEl, siteConfig) {
// Generally, either the passwordEl or usernameEl is provided.
var PasswordForm = function(args) {
var id = args.id,
passwordEl = args.passwordEl,
usernameEl = args.usernameEl,
containingEl = args.containingEl,
siteConfig = args.siteConfig;
this.id = id;
this.passwordField = createFieldObjForEl(passwordEl);
this.$containingEl = $(containingEl);
@ -226,8 +233,12 @@ var PasswordForm = function($, DomMonitor) {
this.focusEvents = "focus.username"+this.id;
this.removedEvents = "isRemoved.pwdEl"+this.id;
// This must be called after passwordField and $containingEl are set
this.usernameField = findUsernameField.call(this);
if (usernameEl) {
this.usernameField = createFieldObjForEl(usernameEl);
} else {
// This must be called after passwordField and $containingEl are set
this.usernameField = findUsernameField.call(this);
}
// We may have detected detected a "fake" username field that after the user focuses on it,
// the site switches focus to the "real" username field. This handler will update
// this.usernameField appropriately.

Просмотреть файл

@ -19,10 +19,10 @@ var PasswordFormInspector = function($, PasswordForm, DomMonitor) {
if (!siteConfig.multiStage) return [];
$un = $(siteConfig.un);
if ($un.length === 0) return [];
return [ new PasswordForm(generateId(),
null,
getFormForElement($un),
siteConfig) ];
return [ new PasswordForm({ id: generateId(),
usernameEl: $un.get(0),
containingEl: getFormForElement($un).get(0),
siteConfig: siteConfig }) ];
}
function getFormForElement($el) {
@ -51,10 +51,10 @@ var PasswordFormInspector = function($, PasswordForm, DomMonitor) {
// If the containing form contains multiple password field, then ignore
// for now. This is probably a change password field.
if (numPasswordInputs > 1) return;
passwordForms.push(new PasswordForm(generateId(),
passwordEl,
$containingForm.get(0),
siteConfig));
passwordForms.push(new PasswordForm({ id: generateId(),
passwordEl: passwordEl,
containingEl: $containingForm.get(0),
siteConfig: siteConfig }));
});
passwordForms = passwordForms.concat(findMultistageForms());
observeForms();