index.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. //Password
  12. // function Password(parent, open){
  13. // //const value = ''
  14. // const pass = document.createElement('input')
  15. // const check = document.createElement('input')
  16. // check.type = 'checkbox'
  17. // parent.append(pass , check)
  18. // check.onchange = () => {
  19. // this.setOpen(check.checked)
  20. // }
  21. // pass.oninput = () => {
  22. // this.value = pass.value;
  23. // if(typeof this.onchange === 'function'){
  24. // this.onchange(this.value)
  25. // }
  26. // }
  27. // this.getValue = function () {
  28. // return this.value
  29. // }
  30. // this.setValue = function(value){
  31. // this.value = value;
  32. // pass.value = this.value
  33. // }
  34. // this.setOpen = function (newOpen) {
  35. // open = newOpen
  36. // pass.type = open ? 'text' : 'password'
  37. // check.checked = open
  38. // if(typeof this.onOpenChange === 'function') {
  39. // this.onOpenChange(open)
  40. // }
  41. // }
  42. // this.getOpen = function () {
  43. // return open
  44. // }
  45. // this.setOpen(open)
  46. // }
  47. // let p = new Password(document.body, false)
  48. // p.onChange = data => console.log(data)
  49. // p.onOpenChange = open => console.log(open)
  50. // p.setValue('qwerty')
  51. // console.log(p.getValue())
  52. // // p.setOpen(false)
  53. // console.log(p.getOpen())
  54. //LoginForm
  55. // function LoginForm(parent, open){
  56. // const formBody = document.createElement('div')
  57. // const pass = document.createElement('input')
  58. // const login = document.createElement('input')
  59. // const check = document.createElement('input')
  60. // const btn = document.createElement('button')
  61. // check.type = 'checkbox'
  62. // login.type = 'text'
  63. // btn.innerHTML = 'submit'
  64. // parent.append(formBody)
  65. // formBody.append(login , pass , check , btn)
  66. // check.onchange = () => {
  67. // this.setOpen(check.checked)
  68. // }
  69. // pass.oninput = () => {
  70. // this.value = pass.value;
  71. // btn.disabled = checkInputs();
  72. // if(typeof this.onchange === 'function'){
  73. // this.onchange(this.value)
  74. // }
  75. // }
  76. // this.setLoginValue = (value) => {
  77. // this.loginValue = value
  78. // login.value = this.loginValue
  79. // }
  80. // this.getLoginValue = () => {
  81. // return this.loginValue
  82. // }
  83. // const checkInputs = () => {
  84. // if(login.value.length === 0 || this.value.length === 0 ) {
  85. // return true;
  86. // }
  87. // return false;
  88. // }
  89. // this.getValue = function () {
  90. // return this.value
  91. // }
  92. // this.setValue = function(value){
  93. // this.value = value;
  94. // pass.value = this.value
  95. // }
  96. // this.setOpen = function (newOpen) {
  97. // open = newOpen
  98. // pass.type = open ? 'text' : 'password'
  99. // check.checked = open
  100. // if(typeof this.onOpenChange === 'function') {
  101. // this.onOpenChange(open)
  102. // }
  103. // }
  104. // this.getOpen = function () {
  105. // return open
  106. // }
  107. // this.setOpen(open)
  108. // btn.disabled = checkInputs();
  109. // }
  110. // let lf = new LoginForm(document.body, false)
  111. // lf.onChange = data => console.log(data)
  112. // lf.onOpenChange = open => console.log(open)
  113. // lf.setValue('qwerty')
  114. // console.log(lf.getValue())
  115. // lf.setLoginValue('qwerty')
  116. // console.log(lf.getLoginValue())
  117. // // lf.setOpen(false)
  118. // console.log(lf.getOpen())
  119. //Password Verify
  120. function PasswordCheck(parent, open){
  121. const formBody = document.createElement('div')
  122. const pass1 = document.createElement('input')
  123. const pass2 = document.createElement('input')
  124. const check = document.createElement('input')
  125. const btn = document.createElement('button')
  126. check.type = 'checkbox'
  127. btn.innerHTML = 'пароли совпадают'
  128. parent.append(formBody)
  129. formBody.append(pass2 , pass1 , check , btn)
  130. check.onchange = () => {
  131. this.setOpen(check.checked)
  132. }
  133. pass1.oninput = () => {
  134. this.value = pass1.value;
  135. btn.disabled = !validator();
  136. if(typeof this.onchange === 'function'){
  137. this.onchange(this.value)
  138. }
  139. }
  140. pass2.type = 'password'
  141. pass2.style.display = !open ? 'inline' : 'none';
  142. pass2.oninput = () => {
  143. this.value2 = pass2.value
  144. btn.disabled = !validator();
  145. }
  146. const validator = () => {
  147. if (open === true) {
  148. return false;
  149. }
  150. if (this.value === this.value2 && pass1.value !== "" && this.value2) {
  151. console.log('correct password')
  152. return true;
  153. }
  154. return false;
  155. };
  156. this.setValue = function(value){
  157. this.value = value;
  158. pass1.value = this.value
  159. btn.disabled = !validator();
  160. }
  161. this.setPass2Value = (value) => {
  162. this.pass2 = value
  163. pass2.value = this.pass2
  164. btn.disabled = !validator();
  165. }
  166. this.getValue = () => {
  167. return this.value
  168. }
  169. this.getPass2Value = () => {
  170. return this.pass2
  171. }
  172. this.setOpen = function (newOpen) {
  173. open = newOpen
  174. pass1.type = open ? 'text' : 'password'
  175. pass2.style.display = !open ? "inline" : "none";
  176. btn.disabled = !validator();
  177. check.checked = open
  178. if(typeof this.onOpenChange === 'function') {
  179. this.onOpenChange(open)
  180. }
  181. }
  182. this.getOpen = function () {
  183. return open
  184. }
  185. this.setOpen(open)
  186. btn.disabled = validator();
  187. }
  188. let pc = new PasswordCheck(document.body, false)
  189. pc.onOpenChange = open => console.log(open);
  190. pc.setValue('')
  191. // console.log(pc.getValue())
  192. pc.setPass2Value('')
  193. // console.log(pc.getPass2Value())
  194. // pc.setOpen(false)
  195. // console.log(pc.getOpen())
  196. // ??????????
  197. </script>
  198. </body>
  199. </html>