script.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. function Password(parent, open){
  2. this.textBox = document.createElement("input")
  3. this.textBox.setAttribute("type", "password")
  4. parent.appendChild(this.textBox)
  5. this.checkBox = document.createElement("input")
  6. this.checkBox.setAttribute("type", "checkbox")
  7. parent.appendChild(this.checkBox)
  8. this.isChecked = function(checkBox, textBox) {
  9. if(open === false){
  10. this.textBox.setAttribute("type", "password")
  11. open = true;
  12. } else {
  13. this.textBox.setAttribute("type", "text")
  14. open = false;
  15. }
  16. }
  17. this.getValue = function(arg = this.textBox) {
  18. return arg.value
  19. }
  20. this.setValue = function(inner) {
  21. this.textBox.value = inner;
  22. }
  23. this.getOpen = function() {
  24. let str;
  25. open == true ? str = "closed" : str = "opened";
  26. return str;
  27. }
  28. this.onChange = function(arg) {
  29. let data = this.getValue(arg);
  30. return data;
  31. }
  32. this.onOpenChange = function(arg) {
  33. console.log(arg)
  34. return arg
  35. }
  36. this.checkBox.onchange = () => {
  37. this.isChecked(this.checkBox, this.textBox)
  38. this.onOpenChange(this.getOpen())
  39. };
  40. this.textBox.oninput = () => this.onChange(this.getValue(this.textBox));
  41. this.setOpen = function(arg) {
  42. if(!arg == true){
  43. this.checkBox.checked = "checked"
  44. } else {
  45. this.checkBox.checked = ""
  46. }
  47. this.isChecked()
  48. }
  49. }
  50. function login(parent) {
  51. this.loginBox = document.createElement("input");
  52. this.loginBox.setAttribute("type", "text");
  53. this.loginBox.setAttribute("value", "login")
  54. parent.appendChild(this.loginBox);
  55. }
  56. function send(parent) {
  57. this.sendBottom = document.createElement("button");
  58. this.sendBottom.setAttribute("disabled", true);
  59. this.sendBottom.innerText = "send";
  60. parent.appendChild(this.sendBottom)
  61. }
  62. function loginForm(parent) {
  63. this.login = new login(parent);
  64. this.login.loginBox.oninput = () => this.sendOnChange();
  65. this.password = new Password(parent);
  66. this.password.textBox.oninput = () => { this.sendOnChange()
  67. }
  68. this.sendBottom = new send(parent)
  69. this.sendOnChange = function() {
  70. if(this.login.loginBox.value != "" && this.password.textBox.value != "") {
  71. return this.sendBottom.sendBottom.removeAttribute("disabled");
  72. } return this.sendBottom.sendBottom.setAttribute("disabled", true);
  73. }
  74. this.setValue = function(inner, box = this.password.textBox) {
  75. box.value = inner;
  76. }
  77. this.setValue("qwerty")
  78. this.sendOnChange()
  79. }
  80. // let j = new loginForm(document.body)
  81. // j.setValue("Вооот")
  82. function passwordVerify(parent) {
  83. this.login = new login(parent);
  84. this.login.loginBox.oninput = () => this.sendOnChange();
  85. this.checkPasswordBox = document.createElement("span");
  86. parent.appendChild(this.checkPasswordBox);
  87. this.password = new Password(this.checkPasswordBox);
  88. this.password.checkBox.onchange = () => {
  89. if(this.password.checkBox.checked) {
  90. this.checkPassword.remove()
  91. } else {
  92. this.checkPassword = document.createElement("input");
  93. this.checkPassword.setAttribute("type", "password");
  94. this.checkPasswordBox.appendChild(this.checkPassword);
  95. this.checkPassword.oninput = () => this.sendOnChange();
  96. }
  97. this.sendOnChange()
  98. }
  99. this.password.textBox.oninput = () => this.sendOnChange();
  100. this.checkPassword = document.createElement("input");
  101. this.checkPassword.setAttribute("type", "password");
  102. this.checkPasswordBox.appendChild(this.checkPassword);
  103. this.checkPassword.oninput = () => this.sendOnChange();
  104. this.sendBottom = new send(parent);
  105. this.setValue = function(inner, box = this.password.textBox) {
  106. box.value = inner;
  107. }
  108. this.setValue("qwerty")
  109. this.sendOnChange = function() {
  110. if(this.password.checkBox.checked &&
  111. this.login.loginBox.value != "" &&
  112. this.password.textBox.value != "") {
  113. return this.sendBottom.sendBottom.removeAttribute("disabled");
  114. }
  115. else {
  116. if(this.login.loginBox.value != "" &&
  117. this.password.textBox.value != "" &&
  118. this.password.textBox.value === this.checkPassword.value) {
  119. return this.sendBottom.sendBottom.removeAttribute("disabled");
  120. }
  121. }
  122. return this.sendBottom.sendBottom.setAttribute("disabled", true);
  123. }
  124. }
  125. passwordVerify(document.body)