main.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //passsword
  2. function Password(parent, open = true) {
  3. let inputPass = document.createElement("input")
  4. let inputCheck = document.createElement("input")
  5. inputCheck.type = "checkbox"
  6. inputCheck.checked = open
  7. this.setValue = (newValue) => inputPass.value = newValue
  8. this.getValue = () => inputPass.value
  9. this.setOpen = (newOpen) => {
  10. inputCheck.checked = newOpen
  11. if (inputCheck.checked == false) {
  12. inputPass.type = "password"
  13. inputCheck.innerText = "false"
  14. } else {
  15. inputPass.type = "text"
  16. inputCheck.innerText = "true"
  17. }
  18. this.onOpenChange(inputCheck.checked)
  19. }
  20. this.getOpen = () => inputCheck.checked
  21. inputPass.oninput = () => this.onChange(inputPass.value)
  22. inputCheck.onchange = () => {
  23. if (inputCheck.checked == false) {
  24. inputPass.type = "password"
  25. inputCheck.innerText = "false"
  26. } else {
  27. inputPass.type = "text"
  28. inputCheck.innerText = "true"
  29. }
  30. this.onOpenChange(inputCheck.checked)
  31. }
  32. parent.append(inputPass)
  33. parent.append(inputCheck)
  34. }
  35. /*
  36. setValue/getValue - задают/читают значения
  37. setOpen/getOpen - задают/читают открытость текста в поле ввода
  38. Колбэки (функции обратного вызова, данные изнутри объекта):
  39. onChange - запускается по событию oninput в поле ввода, передает текст наружу
  40. onOpenChange - запускается по изменению состояния открытости пароля*/
  41. //let p = new Password(document.body, true)
  42. // //p.onChange = data => console.log(data)
  43. // p.onOpenChange = open => console.log(open)
  44. // p.setValue('qwerty')
  45. // console.log(p.getValue())
  46. // p.setOpen(true)
  47. // console.log(p.getOpen())
  48. //LoginForm
  49. function LoginForm(parent, open = true) {
  50. let inputLogin = document.createElement("input")
  51. let button = document.createElement("button")
  52. let form = document.createElement("form")
  53. inputLogin.type = "text"
  54. button.innerText = "log in"
  55. button.disabled = open
  56. //button.setAttribute("disabled", "")
  57. this.setValueLog = (newValue) => inputLogin.value = newValue
  58. this.setButton = (newOpen) => button.disabled = newOpen
  59. this.getButton = () => button.disabled
  60. this.getValueLog = () => inputLogin.value
  61. inputLogin.oninput = () => this.onChange(inputLogin.value)
  62. form.append(inputLogin, button);
  63. //parent.append(inputLogin)
  64. //parent.append(button)
  65. parent.append(form)
  66. }
  67. // let l = new LoginForm(document.body, true)
  68. // //l.setValueLog('qwerty')
  69. // console.log(l.getValueLog())
  70. // function btnState() {
  71. // if (p.getValue() != "" && l.getValueLog() != "") {
  72. // l.setButton(false)
  73. // } else {
  74. // l.setButton(true)
  75. // }
  76. // }
  77. // l.onChange = btnState
  78. // p.onChange = btnState
  79. function LoginFormConstructor(parent, open = true) {
  80. let inputLogin = document.createElement("input")
  81. inputLogin.type = "text"
  82. let inputPass = document.createElement("input")
  83. let button = document.createElement("button")
  84. button.innerText = "register"
  85. button.disabled = open
  86. let form = document.createElement("form")
  87. this.setValueLog = (newValue) => inputLogin.value = newValue
  88. this.getValueLog = () => inputLogin.value
  89. inputLogin.oninput = () => this.onChange(inputLogin.value)
  90. this.setButton = (newOpen) => button.disabled = newOpen
  91. this.getButton = () => button.disabled
  92. let inputCheck = document.createElement("input")
  93. inputCheck.type = "checkbox"
  94. state = (inputCheck.checked) ? (inputPass.type = "text" && inputCheck.checked) : (inputPass.type = "password")
  95. this.setValue = (newValue) => inputPass.value = newValue
  96. this.getValue = () => inputPass.value
  97. this.setOpen = (newOpen) => {
  98. inputCheck.checked = (newOpen == true) ? (inputPass.type = "text" && inputCheck.checked) : (inputPass.type = "password")
  99. // this.onOpenChange(inputCheck.checked)
  100. }
  101. this.getOpen = () => inputCheck.checked
  102. inputPass.oninput = () => this.onChange(inputPass.value)
  103. inputCheck.onchange = () => {
  104. (inputCheck.checked == true) ? (inputPass.type = "text" && inputCheck.checked) : (inputPass.type = "password")
  105. //this.onOpenChange(inputCheck.checked)
  106. }
  107. let btnState = () => (this.getValue() != "" && this.getValueLog() != "") ?
  108. (this.setButton(false)) :
  109. this.setButton(true)
  110. this.onChange = () => btnState()
  111. form.append(inputLogin, inputPass, inputCheck, button);
  112. parent.append(form)
  113. }
  114. //let finishForm = new LoginFormConstructor(document.body, true)
  115. //Password Verify
  116. function PasswordVerify(parent, open = true) {
  117. let input1 = document.createElement("input")
  118. let input2 = document.createElement("input")
  119. input2.type = "text"
  120. let button = document.createElement("button")
  121. button.innerText = "register"
  122. button.disabled = open
  123. let form = document.createElement("form")
  124. this.setValue2 = (newValue) => input2.value = newValue
  125. this.getValue2 = () => input2.value
  126. input2.oninput = () => this.onChange(input2.value)
  127. this.setButton = (newOpen) => button.disabled = newOpen
  128. this.getButton = () => button.disabled
  129. let inputCheck = document.createElement("input")
  130. inputCheck.type = "checkbox"
  131. state = (inputCheck.checked) ? (input1.type = "text" && inputCheck.checked) : (input1.type = "password")
  132. this.setValue1 = (newValue) => input1.value = newValue
  133. this.getValue1 = () => input1.value
  134. this.setOpen = (newOpen) => {
  135. inputCheck.checked = (newOpen == true) ? (input1.type = "text" && inputCheck.checked) : (input1.type = "password")
  136. // this.onOpenChange(inputCheck.checked)
  137. }
  138. this.getOpen = () => inputCheck.checked
  139. input1.oninput = () => this.onChange(input1.value)
  140. inputCheck.onchange = () => {
  141. if (inputCheck.checked == true) {
  142. //1 вариант
  143. // parent.removeChild(input2)
  144. //2
  145. input2.style.display = "none"
  146. input1.type = "text"
  147. } else {
  148. input1.type = "password"
  149. //1 вариант
  150. // parent.appendChild(input2)
  151. //2 вариант
  152. input2.style.display = ""
  153. }
  154. }
  155. let btnState = () => (this.getValue1() == this.getValue2()) ?
  156. (this.setButton(false)) :
  157. this.setButton(true)
  158. this.onChange = () => btnState()
  159. parent.append(input1)
  160. parent.append(input2)
  161. parent.append(inputCheck)
  162. parent.append(button)
  163. }
  164. //let pass = new PasswordVerify(document.body, true)