|
@@ -19,7 +19,9 @@ function Password(parent, open) {
|
|
|
|
|
|
this.setOpen = openUpdate => {
|
|
|
open = openUpdate;
|
|
|
- this.onOpenChange(openUpdate);
|
|
|
+ if(typeof this.onOpenChange === 'function') {
|
|
|
+ this.onOpenChange(openUpdate);
|
|
|
+ }
|
|
|
button.textContent = (openUpdate) ? 'показать' : 'скрыть';
|
|
|
input.type = (openUpdate) ? 'password' : 'text';
|
|
|
}
|
|
@@ -31,8 +33,6 @@ function Password(parent, open) {
|
|
|
this.onChange(event.target.value);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
- this.onOpenChange = isOpen => isOpen;
|
|
|
}
|
|
|
|
|
|
function LoginForm (parent) {
|
|
@@ -41,12 +41,10 @@ function LoginForm (parent) {
|
|
|
|
|
|
const input = document.createElement('input');
|
|
|
input.type = 'text';
|
|
|
- input.classList.add('form-text');
|
|
|
parent.appendChild(input);
|
|
|
|
|
|
const button = document.createElement('button');
|
|
|
button.type = 'button';
|
|
|
- button.classList.add('login-button');
|
|
|
button.textContent = 'Логин';
|
|
|
button.disabled = true;
|
|
|
|
|
@@ -56,29 +54,29 @@ function LoginForm (parent) {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- this.getValue = () => input.value;
|
|
|
+ button.addEventListener('click', event => {
|
|
|
+ if (typeof this.onLogin === 'function') {
|
|
|
+ this.onLogin(event);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- this.addButton = () => parent.appendChild(button);
|
|
|
-}
|
|
|
+ this.getLogin = () => input.value;
|
|
|
|
|
|
-const loginForm = new LoginForm(document.body);
|
|
|
+ this.createDivider();
|
|
|
+ const password = new Password(document.body, true);
|
|
|
|
|
|
-loginForm.createDivider();
|
|
|
+ const getPassword = () => password.getValue();
|
|
|
|
|
|
-const password = new Password(document.body, true);
|
|
|
+ this.createDivider();
|
|
|
+ parent.appendChild(button);
|
|
|
|
|
|
-loginForm.createDivider();
|
|
|
+ const isDisabled = () => button.disabled = (!(getPassword() !== '' && this.getLogin() !== ''));
|
|
|
|
|
|
-loginForm.addButton();
|
|
|
+ password.onChange = () => isDisabled();
|
|
|
|
|
|
-const isDisabled = () => {
|
|
|
- document.querySelector('.login-button').disabled = (password.getValue() !== '' && loginForm.getValue() !== '') ? false : true;
|
|
|
+ this.onChange = () => isDisabled();
|
|
|
}
|
|
|
|
|
|
-password.onChange = () => {
|
|
|
- isDisabled();
|
|
|
-}
|
|
|
+const loginForm = new LoginForm(document.body);
|
|
|
|
|
|
-loginForm.onChange = () => {
|
|
|
- isDisabled();
|
|
|
-}
|
|
|
+loginForm.onLogin = data => console.log(data);
|