|
@@ -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()); */
|