main.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. //................................Password
  2. let task1 = document.createElement('div');
  3. task1.innerText = 'Password'
  4. task1.className = 'box1';
  5. document.body.append(task1);
  6. function Password(parent,open = true) {
  7. this.inputPassword = document.createElement("input");
  8. parent.append(this.inputPassword);
  9. this.inputPassword.placeholder = 'password'
  10. this.buttonShowPassword = document.createElement("button");
  11. parent.append(this.buttonShowPassword);
  12. this.buttonShowPassword.innerText = "password";
  13. this.eye = document.createElement('img');
  14. this.buttonShowPassword.append(this.eye);
  15. if (open) this.eye.src = '2540381-200.png'
  16. else this.eye.src = 'interface_hide-512.webp'
  17. this.inputPassword.type = open ? "" : "password";
  18. this.checked = open;
  19. this.setValue = function (data) {
  20. this.inputPassword.value = data;
  21. };
  22. this.getValue = function () {
  23. return this.inputPassword.value;
  24. };
  25. this.onOpenChange = function () {}
  26. this.setOpen = function (boolean) {
  27. this.inputPassword.type = boolean ? "" : "password";
  28. boolean = this.inputPassword.type;
  29. if (this.inputPassword.type == 'password') this.eye.src = 'interface_hide-512.webp'
  30. else this.eye.src = '2540381-200.png'
  31. this.onOpenChange(boolean);
  32. };
  33. this.getOpen = function () {
  34. return open;
  35. };
  36. if (!this.inputPassword.value) this.buttonShowPassword.disabled = false;
  37. this.onChange = function () {}
  38. this.inputPassword.oninput = (data) => {
  39. data = this.inputPassword.value
  40. this.onChange(data);
  41. if (this.inputPassword.value) this.buttonShowPassword.disabled = false;
  42. else this.buttonShowPassword.disabled = true;
  43. }
  44. this.checked = open;
  45. this.buttonShowPassword.onclick = (open) => {
  46. this.checked = !this.checked;
  47. if (this.inputPassword.type = this.checked) {
  48. this.eye.src = '2540381-200.png'
  49. } else this.eye.src = 'interface_hide-512.webp'
  50. this.inputPassword.type = this.checked ? "" : "password";
  51. open = this.inputPassword.type;
  52. this.onOpenChange(open);
  53. };
  54. }
  55. let taskPassword = new Password(task1)
  56. //................................LoginForm
  57. let task2 = document.createElement('div');
  58. task2.innerText = 'LoginForm '
  59. task2.className = 'box2';
  60. document.body.append(task2);
  61. function LoginForm(parent) {
  62. this.inputLogin = document.createElement("input");
  63. parent.append(this.inputLogin);
  64. this.inputLogin.placeholder = 'login';
  65. let password = new Password(parent)
  66. this.buttonLogin = document.createElement('button');
  67. parent.append(this.buttonLogin);
  68. this.buttonLogin.innerText = 'login';
  69. this.buttonLogin.disabled = true;
  70. password.inputPassword.oninput = this.inputLogin.oninput = () => {
  71. if (password.inputPassword.value && this.inputLogin.value) this.buttonLogin.disabled = false;
  72. else this.buttonLogin.disabled = true;
  73. }
  74. }
  75. let loginForm = new LoginForm(task2, true);
  76. //................................ FormConstructor
  77. let task3 = document.createElement('div');
  78. task3.innerText = 'Form Constructor '
  79. task3.className = 'box3';
  80. document.body.append(task3);
  81. function FormConstructor(parent,open = true) {
  82. this.inputLogin = document.createElement("input");
  83. parent.append(this.inputLogin);
  84. this.inputLogin.placeholder = 'login';
  85. this.setLogin = function (login) {
  86. this.inputLogin.value = login
  87. }
  88. this.getLogin = function(){
  89. return this.inputLogin.value
  90. }
  91. this.inputLogin.oninput = (data) => {
  92. }
  93. this.inputPassword = document.createElement("input");
  94. parent.append(this.inputPassword);
  95. this.inputPassword.placeholder = 'password'
  96. this.buttonShowPassword = document.createElement("button");
  97. parent.append(this.buttonShowPassword);
  98. this.buttonShowPassword.innerText = "password";
  99. this.eye = document.createElement('img');
  100. this.buttonShowPassword.append(this.eye);
  101. if (open) this.eye.src = '2540381-200.png'
  102. else this.eye.src = 'interface_hide-512.webp'
  103. this.inputPassword.type = open ? "" : "password";
  104. this.buttonLogin = document.createElement('button');
  105. parent.append(this.buttonLogin);
  106. this.buttonLogin.innerText = 'login';
  107. this.buttonLogin.disabled = true;
  108. this.checked = open;
  109. this.setLogin = function (data) {
  110. this.inputLogin.value = data;
  111. };
  112. this.getLogin = function () {
  113. return this.inputLogin.value;
  114. };
  115. this.setPassword = function (data) {
  116. this.inputPassword.value = data;
  117. };
  118. this.getPassword = function () {
  119. return this.inputPassword.value;
  120. };
  121. this.onOpenChange = function () {}
  122. this.setOpen = function (boolean) {
  123. this.inputPassword.type = boolean ? "" : "password";
  124. boolean = this.inputPassword.type;
  125. if (this.inputPassword.type == 'password') this.eye.src = 'interface_hide-512.webp'
  126. else this.eye.src = '2540381-200.png'
  127. this.onOpenChange(boolean);
  128. };
  129. this.getOpen = function () {
  130. return open;
  131. };
  132. if (!this.inputPassword.value) this.buttonShowPassword.disabled = false;
  133. this.onChangeLogin = function () {}
  134. this.onChangePassword = function () {}
  135. this.inputLogin.oninput= this.inputPassword.oninput = (data) => {
  136. data = this.inputPassword.value
  137. this.onChangePassword(data);
  138. if (!this.inputLogin.value && !this.inputPassword.value) this.buttonLogin.disabled = true;
  139. else this.buttonLogin.disabled = false;
  140. data = this.inputLogin.value
  141. this.onChangeLogin(data);
  142. if (this.inputPassword.value) this.buttonShowPassword.disabled = false;
  143. else this.buttonShowPassword.disabled = true;
  144. }
  145. this.checked = open;
  146. this.buttonShowPassword.onclick = (open) => {
  147. this.checked = !this.checked;
  148. if (this.inputPassword.type = this.checked) {
  149. this.eye.src = '2540381-200.png'
  150. } else this.eye.src = 'interface_hide-512.webp'
  151. this.inputPassword.type = this.checked ? "" : "password";
  152. open = this.inputPassword.type;
  153. this.onOpenChange(open);
  154. };
  155. }
  156. let formConstructor = new FormConstructor(task3)