Browse Source

10.2 oop done

pocu46 4 years ago
parent
commit
b3a60b7654
3 changed files with 128 additions and 11 deletions
  1. 1 0
      10.2 oop/index.html
  2. 108 10
      10.2 oop/script.js
  3. 19 1
      10.2 oop/style.css

+ 1 - 0
10.2 oop/index.html

@@ -11,6 +11,7 @@
 <body>
         <div class="task1" id="task1">Task 1</div>
         <div class="task2" id="task2">Task 2</div>
+        <div class="task3" id="task3">Task 3</div>
 
     <script src="./script.js"></script>
 </body>

+ 108 - 10
10.2 oop/script.js

@@ -41,7 +41,7 @@ function Password2(parent, open = false) {
     let password = document.createElement("input");
     parent.append(password);
     password.setAttribute("type", open ? "text" : "password");
-    password.setAttribute("placeholder",  "Password");
+    password.setAttribute("placeholder", "Password");
 
     let showPassword = document.createElement("input");
     parent.append(showPassword);
@@ -50,7 +50,7 @@ function Password2(parent, open = false) {
     let login = document.createElement("input");
     parent.append(login);
     login.setAttribute("type", "text");
-    login.setAttribute("placeholder",  "Login");
+    login.setAttribute("placeholder", "Login");
 
     let loginButton = document.createElement("button");
     parent.append(loginButton);
@@ -63,8 +63,16 @@ function Password2(parent, open = false) {
         password.setAttribute("type", showPassword.checked ? "text" : "password");
     }
 
-    password.oninput = () => {
-        this.onChange(password.value);
+    password.oninput = login.oninput = () => {
+        this.onChange({
+            password: password.value,
+            login: login.value
+        });
+        if (password.value && login.value) {
+            loginButton.disabled = false;
+        } else {
+            loginButton.disabled = true;
+        }
     }
 
     this.onChange = () => {};
@@ -73,13 +81,103 @@ function Password2(parent, open = false) {
         password.value = someVal;
     }
 
-    this.getPassword = function () {
-        return password.value;
+    // this.getPassword = function () {
+    //     return password.value;
+    // }
+
+    this.getter = function () {
+        return {
+            password: password.value,
+            login: login.value,
+            check: showPassword.checked
+        };
     }
 
-    // if(password.value && login.value) {
-    //     loginButton.disabled = falce;
-    // }
+    this.setLogin = function (someVal) {
+        login.value = someVal;
+    }
+
+    this.setCheckbox = function (someVal) {
+        showPassword.checked = someVal;
+    }
+}
+
+let form2 = new Password2(task2, false);
+form2.onChange = (x) => console.log(x);
+
+//-------------------------------------------------------Password Verify--------------------------------------------------------------------
+
+function Password3(parent, open = false) {
+    let login = document.createElement("input");
+    parent.append(login);
+    login.setAttribute("type", "text");
+    login.setAttribute("placeholder", "Login");
+
+    let password = document.createElement("input");
+    parent.append(password);
+    password.setAttribute("type", open ? "text" : "password");
+    password.setAttribute("placeholder", "Password");
+
+    let confirmPassword = document.createElement("input");
+    parent.append(confirmPassword);
+    confirmPassword.setAttribute("type", "password");
+    confirmPassword.setAttribute("placeholder", "Confirm Password");
+
+    let showPassword = document.createElement("input");
+    parent.append(showPassword);
+    showPassword.setAttribute("type", "checkbox");
+
+    let loginButton = document.createElement("button");
+    parent.append(loginButton);
+    loginButton.innerText = "__OK__";
+    loginButton.disabled = true;
+
+    showPassword.checked = open;
+
+    showPassword.onclick = () => {
+        password.setAttribute("type", showPassword.checked ? "text" : "password");
+        if (showPassword.checked) {
+            confirmPassword.style.display = "none";
+        }
+        else {
+            confirmPassword.style.display = "block";
+        }
+    }
+
+    password.oninput = login.oninput = confirmPassword.oninput = () => {
+        this.onChange({
+            password: password.value,
+            login: login.value,
+            confirmPassword: confirmPassword.value
+        });
+        if (password.value && login.value && confirmPassword.value) {
+            loginButton.disabled = false;
+        } else {
+            loginButton.disabled = true;
+        }
+    }
+
+    this.onChange = () => {};
+
+    this.setPassword = function (someVal) {
+        password.value = someVal;
+    }
+
+    this.getter = function () {
+        return {
+            password: password.value,
+            login: login.value,
+            check: showPassword.checked
+        };
+    }
+
+    this.setLogin = function (someVal) {
+        login.value = someVal;
+    }
+
+    this.setCheckbox = function (someVal) {
+        showPassword.checked = someVal;
+    }
 }
 
-let form2 = new Password2(task2, true);
+let form3 = new Password3(task3, false);

+ 19 - 1
10.2 oop/style.css

@@ -3,10 +3,28 @@
     padding: 0;
 }
 
+body {
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    flex-direction: column;
+    margin: 15px 0;
+}
+
 div {
     display: flex;
     justify-content: center;
     align-items: center;
     text-align: center;
-    margin-bottom: 15px;
+    margin: 15px;
+    border-radius: 3%;
+}
+
+.task3 {
+    display: flex;
+    flex-direction: column;
+    justify-content: center;
+    align-items: center;
+    border: 2px solid #000;
+    width: 250px;
 }