Browse Source

homework10 update done

holevchuk.evgeny 1 year ago
parent
commit
952b1faad4
4 changed files with 35 additions and 40 deletions
  1. 3 3
      hw10/loginForm.js
  2. 19 21
      hw10/loginFormConstructor.js
  3. 3 3
      hw10/password.js
  4. 10 13
      hw10/passwordVerify.js

+ 3 - 3
hw10/loginForm.js

@@ -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 () {

+ 19 - 21
hw10/loginFormConstructor.js

@@ -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);

+ 3 - 3
hw10/password.js

@@ -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;
 }
 
 let p = new Password(document.body, true);

+ 10 - 13
hw10/passwordVerify.js

@@ -17,12 +17,6 @@ function Password(
 		parent.appendChild(buttonPassword);
 	}
 
-	const buttonLogin = document.createElement('button');
-	buttonLogin.type = 'button';
-	buttonLogin.classList.add('login-button');
-	buttonLogin.textContent = 'Логин';
-	buttonLogin.disabled = true;
-
 	const divider = document.createElement('br');
 
 	buttonPassword.addEventListener('click', () => {
@@ -35,7 +29,9 @@ function Password(
 
 	this.setOpen = openUpdate => {
 		open = openUpdate;
-		this.onOpenChange(openUpdate);
+		if(typeof this.onOpenChange === 'function') {
+			this.onOpenChange(openUpdate);
+		}
 		buttonPassword.textContent = (openUpdate) ? 'показать' : 'скрыть';
 		inputPassword.type = (openUpdate) ? 'password' : 'text';
 	}
@@ -48,10 +44,6 @@ function Password(
 		}
 	});
 
-	this.onOpenChange = isOpen => isOpen;
-
-	this.addButton = () => parent.appendChild(buttonLogin);
-
 	this.addDivider = () => parent.appendChild(divider);
 }
 
@@ -59,10 +51,15 @@ const password1 = new Password(document.body, true, true, 'first_password');
 password1.addDivider();
 const password2 = new Password(document.body, true, false, 'second_password');
 password2.addDivider();
-password1.addButton();
+
+const buttonLogin = document.createElement('button');
+buttonLogin.type = 'button';
+buttonLogin.textContent = 'Логин';
+buttonLogin.disabled = true;
+document.body.appendChild(buttonLogin);
 
 const isEqual = () => {
-	document.querySelector('.login-button').disabled = (password1.getValue() !== password2.getValue());
+	buttonLogin.disabled = (password1.getValue() !== password2.getValue());
 }
 
 password1.onOpenChange = (open) => {