main.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. function Password(parent, open = false) {
  2. let wrap = document.createElement('div')
  3. let input = document.createElement('input')
  4. let checkBox = document.createElement('input')
  5. input.type = open ? 'text' : 'password'
  6. checkBox.type = 'checkbox'
  7. checkBox.checked = open
  8. wrap.append(input)
  9. wrap.append(checkBox)
  10. parent.append(wrap)
  11. this.getValue = () => input.value
  12. this.getOpen = () => checkBox.checked
  13. this.setValue = newValue => input.value = newValue
  14. this.setOpen = () => checkBox.checked ? input.type = 'text' : input.type = 'password'
  15. input.oninput = () => this.onChange()
  16. checkBox.oninput = () => {
  17. this.setOpen()
  18. if (typeof this.onOpenChange === 'function') {
  19. this.onOpenChange(checkBox.checked)
  20. }
  21. }
  22. }
  23. // let p = new Password(document.body, true)
  24. // p.onChange = () => console.log(p.getValue())
  25. // p.onOpenChange = (open) => console.log(open)
  26. // p.setValue('qwerty')
  27. // console.log(p.getValue())
  28. // let button = document.createElement('button')
  29. // let input = document.createElement('input')
  30. // input.type = 'text'
  31. // button.disabled = true
  32. // button.innerText = 'LogIn'
  33. // document.body.append(input)
  34. // document.body.append(button)
  35. // let checkDisabled = () => input.value !== '' && p.getValue() !== '' ? button.disabled = false : button.disabled = true
  36. // p.onChange = () => checkDisabled()
  37. // input.oninput = () => checkDisabled()
  38. function LoginForm(parent, disabled) {
  39. const input = document.createElement('input')
  40. const btn = document.createElement('button')
  41. input.type = 'text'
  42. btn.disabled = disabled
  43. btn.innerText = 'LogIn'
  44. this.getValue = () => input.value
  45. this.setValue = (newValue) => input.value = newValue
  46. input.oninput = () => this.onChange()
  47. this.getOpen = () => btn.disabled
  48. this.setOpen = (newChek) => btn.disabled = newChek
  49. parent.append(input)
  50. parent.append(btn)
  51. }
  52. let lf = new LoginForm(form, true)
  53. let psw = new Password(form, true)
  54. let checkDisabled = () => lf.getValue() !== '' && psw.getValue() !== '' ? lf.setOpen(false) : lf.setOpen(true)
  55. lf.onChange = () => checkDisabled()
  56. psw.onChange = () => checkDisabled()
  57. //Password Verifyd
  58. function pswInputChange() {
  59. const pswInputDouble = document.createElement('input')
  60. psw.onOpenChange = (chek) => {
  61. if (!chek) {
  62. pswInputDouble.type = psw.setOpen()
  63. pswInputDouble.value = psw.getValue()
  64. pswInputDouble.checked = psw.getOpen()
  65. form.append(pswInputDouble)
  66. } else {
  67. pswInputDouble.remove()
  68. }
  69. }
  70. }
  71. pswInputChange()