Prechádzať zdrojové kódy

накидал чето но не особо уверен,нужно думать

kurkabein 2 rokov pred
rodič
commit
d153ce4f72
2 zmenil súbory, kde vykonal 100 pridanie a 0 odobranie
  1. 13 0
      password_OOP/index.html
  2. 87 0
      password_OOP/main.js

+ 13 - 0
password_OOP/index.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <div id="form1"></div>
+    <script src="main.js"></script>
+</body>
+</html>

+ 87 - 0
password_OOP/main.js

@@ -0,0 +1,87 @@
+function Password(parent, open, onChange,onOpenChange){
+    let pswdInput = document.createElement('input');
+    let showPswd = document.createElement('button');
+    /* pswdInput.type = 'password'; */
+    showPswd.innerText = 'show pswd';
+    parent.append(pswdInput);
+    parent.append(showPswd);
+
+    if(open == true){
+        pswdInput.type = 'text'
+    } else {
+        pswdInput.type = 'password'
+    }
+    /* this.open = open; \
+    this.getOpen = function(){
+        return this.open;
+    }*/
+    this.setValue = value =>pswdInput.value = value;
+    this.getValue = () => pswdInput.value;
+    this.setOpen = (newOpen) =>{
+        if(open !== newOpen){
+             pswdInput.type = 'password'
+             
+        } else {
+            pswdInput.type = 'text';
+        }
+    };
+    this.getOpen = () =>{
+        if(pswdInput.type =='password'){
+            console.log('closed');
+        }else {
+            console.log('open');
+        }
+    }
+    this.onChange = onChange;
+    this.onOpenChange = onOpenChange;
+    /* pswdInput.oninput = this.onChange(this.getValue()); */  
+    /* this.onOpenChange = opened =>{
+        pswdInput.oninput = () => oninput(opened);
+    } */
+    /* this.onChange = data =>{
+        pswdInput.onchange = () =>onchange(data);
+    } */
+    showPswd.addEventListener('click', function changeVision(e){
+        if(pswdInput.getAttribute("type")=="password"){
+            pswdInput.type = 'text';
+        } else{
+            pswdInput.type = 'password';
+        }
+    
+    });
+    /* if(typeof this.onOpenChange == 'function'){
+        this.onOpenChange(this.getValue());
+    } */
+    /* pswdInput.oninput = () => {
+        if(typeof this.onChange == 'function'){
+            this.onChange(this.getValue());
+        }
+    } */
+    /* pswdInput.oninput = () => this.onOpenChange(this.getValue()); */
+    /* pswdInput.oninput = () =>this.onChange(this.getValue()); */
+}
+
+function Form (parent){
+    /* let pswdCheck = new Password(parent,true,()=>{}, ()=>{}); */
+    let login = document.createElement('input');
+    parent.append(login);
+    let pswd = new Password(parent,true);
+    pswd.setValue('qwerty');
+    this.setLoginValue = value => login.value = value;
+    this.getloginValue = () => login.value;
+}
+
+let p = new Password(document.body, false, ()=>{});
+
+p.onChange = data => console.log(data)
+p.onOpenChange = open => console.log(open)
+
+p.setValue('qwerty')
+console.log(p.getValue())
+
+p.setOpen(true)
+console.log(p.getOpen())
+
+/* let form = new Form(form1);
+form.setLoginValue('Nik');
+console.log(form.getloginValue()); */