main.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. function Password(parent, open) {
  2. let value = ''
  3. let pass = document.createElement('input')
  4. let check = document.createElement('input')
  5. check.type = 'checkbox'
  6. parent.append(pass, check)
  7. check.onchange = () => {
  8. this.setOpen(check.checked)
  9. }
  10. //добавить pass oninput, который из pass забирает value, запускает setValue
  11. this.getValue = function () {
  12. return value
  13. }
  14. this.setValue = function (value) {
  15. // передает value в onchange если он есть
  16. }
  17. this.getOpen = function () {
  18. return open
  19. }
  20. this.setOpen = function (newOpen) {
  21. open = newOpen
  22. pass.type = open ? 'text' : 'password'
  23. check.checked = open
  24. if (typeof this.onOpenChange === 'function') {
  25. this.onOpenChange(open)
  26. }
  27. }
  28. this.setOpen(open)
  29. check.oninput = () => {
  30. if (this.getOpen() === true) {
  31. this.setOpen(true);
  32. } else {
  33. this.setOpen(false);
  34. }
  35. if (typeof this.onOpenChange === "function") {
  36. this.onOpenChange(this.getOpen());
  37. }
  38. };
  39. }