hw14.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. // Person Constructor ================================================================================================
  2. function Person(name,surname){
  3. this.name = name
  4. this.surname = surname
  5. this.getFullName = () => { return `${this.surname} ${this.name} ${this.fatherName ? this.fatherName : ''}` }
  6. }
  7. const a = new Person("Вася", "Пупкин")
  8. const b = new Person("Анна", "Иванова")
  9. const c = new Person("Елизавета", "Петрова")
  10. console.log(a.getFullName())
  11. a.fatherName = 'Иванович'
  12. console.log(b.getFullName())
  13. // Person Prototype ================================================================================================
  14. function createPerson (name,surname) {
  15. return createPerson.prototype = {
  16. name: name,
  17. surname: surname,
  18. getFullName: () => { return `${surname} ${name} ${this.fatherName ? this.fatherName : ''}` }
  19. }
  20. }
  21. const a = createPerson("Вася", "Пупкин")
  22. const b = createPerson("Анна", "Иванова")
  23. const c = createPerson("Елизавета", "Петрова")
  24. console.log(a.getFullName())
  25. a.fatherName = 'Иванович'
  26. console.log(b.getFullName())
  27. // Store ================================================================================================
  28. // Задание находится в домашней работе по Redux
  29. // Password ================================================================================================
  30. function Password (parent,open) {
  31. this.passwordInput = document.createElement('input')
  32. parent.appendChild(this.passwordInput)
  33. this.passwordInput.type = open ? 'text' : 'password'
  34. this.openInput = document.createElement('input')
  35. parent.appendChild(this.openInput)
  36. this.openInput.type = 'checkBox'
  37. this.setValue = newValue => this.passwordInput.value = newValue
  38. this.getValue = () => {
  39. return this.passwordInput.value
  40. }
  41. this.setOpen = newOpen => {
  42. newOpen = this.openInput.checked
  43. this.passwordInput.type = newOpen ? 'text' : 'password'
  44. }
  45. this.getOpen = () => {
  46. return this.openInput.checked
  47. }
  48. this.passwordInput.oninput = () => {
  49. if (typeof this.onChange === 'function') {
  50. this.onChange(this.getValue())
  51. }
  52. }
  53. this.openInput.onchange = () => {
  54. if (typeof this.onOpenChange === 'function') {
  55. this.onOpenChange(this.getOpen())
  56. }
  57. this.getOpen(this.setOpen())
  58. }
  59. console.log(this)
  60. }
  61. const p = new Password (document.body, false)
  62. p.onChange = data => console.log(data)
  63. p.onOpenChange = open => console.log(open)
  64. p.setValue('qwerty')
  65. console.log(p.getValue())
  66. p.setOpen(false)
  67. console.log(p.getOpen())
  68. // LoginForm ================================================================================================
  69. function Password (parent,open) {
  70. this.passwordInput = document.createElement('input')
  71. parent.appendChild(this.passwordInput)
  72. this.passwordInput.type = open ? 'text' : 'password'
  73. this.openInput = document.createElement('input')
  74. parent.appendChild(this.openInput)
  75. this.openInput.type = 'checkBox'
  76. this.setValue = newValue => this.passwordInput.value = newValue
  77. this.getValue = () => {
  78. return this.passwordInput.value
  79. }
  80. this.setOpen = newOpen => {
  81. newOpen = this.openInput.checked
  82. this.passwordInput.type = newOpen ? 'text' : 'password'
  83. }
  84. this.getOpen = () => {
  85. return this.openInput.checked
  86. }
  87. this.passwordInput.oninput = () => {
  88. if (typeof this.onChange === 'function') {
  89. this.onChange(this.getValue())
  90. }
  91. }
  92. this.openInput.onchange = () => {
  93. if (typeof this.onOpenChange === 'function') {
  94. this.onOpenChange(this.getOpen())
  95. }
  96. this.getOpen(this.setOpen())
  97. }
  98. console.log(this)
  99. }
  100. function makeLogin (parent) {
  101. const p = new Password (document.body, false)
  102. Object.assign(parent.style, {display: 'grid', justifyItems: 'center'})
  103. const loginInput = document.createElement('input')
  104. parent.prepend(loginInput)
  105. loginInput.placeholder = 'Login'
  106. const logInButton = document.createElement('button')
  107. parent.appendChild(logInButton)
  108. Object.assign(logInButton.style, {width: '50px', height: '25px', marginTop: '5px'})
  109. logInButton.innerText = 'Login'
  110. logInButton.disabled = loginInput.value === '' && p.passwordInput.value === '' ? true : false
  111. p.onChange = data => {
  112. logInButton.disabled = data === '' ? true : false
  113. }
  114. loginInput.oninput = data => {
  115. data = loginInput.value
  116. logInButton.disabled = data === '' ? true : false
  117. }
  118. }
  119. const l = makeLogin(document.body)
  120. // LoginForm Constructor ================================================================================================
  121. function Form (parent) {
  122. this.mainForm = document.createElement('form')
  123. parent.append(this.mainForm)
  124. Object.assign(this.mainForm.style, {display: 'flex', flexDirection: 'column', alignItems: 'center', width: '150px'})
  125. this.formElementsPlace = document.createElement('div')
  126. this.mainForm.append(this.formElementsPlace)
  127. Object.assign(this.formElementsPlace.style, {display: 'flex', flexDirection: 'column', width: '100%'})
  128. const p = new Password (this.formElementsPlace, false)
  129. const l = new Login (this.formElementsPlace)
  130. this.formButton = document.createElement('button')
  131. this.mainForm.append(this.formButton)
  132. this.formButton.innerText = 'Login'
  133. Object.assign(this.formButton.style, {width: '50px', marginBottom: '5px'})
  134. this.formButton.disabled = p.passwordInput.value === '' && l.loginInput.value === '' ? true : false
  135. p.onChange = data => this.formButton.disabled = data === ''? true : false
  136. l.onChange = data => this.formButton.disabled = data === ''? true : false
  137. }
  138. function Password (parent,open) {
  139. this.passwordInput = document.createElement('input')
  140. parent.appendChild(this.passwordInput)
  141. this.passwordInput.placeholder = 'Password'
  142. this.passwordInput.type = open ? 'text' : 'password'
  143. this.openInput = document.createElement('input')
  144. parent.appendChild(this.openInput)
  145. this.openInput.type = 'checkBox'
  146. this.setValue = newValue => this.passwordInput.value = newValue
  147. this.getValue = () => {
  148. return this.passwordInput.value
  149. }
  150. this.setOpen = newOpen => {
  151. newOpen = this.openInput.checked
  152. this.passwordInput.type = newOpen ? 'text' : 'password'
  153. }
  154. this.getOpen = () => {
  155. return this.openInput.checked
  156. }
  157. this.passwordInput.oninput = () => {
  158. if (typeof this.onChange === 'function') {
  159. this.onChange(this.getValue())
  160. }
  161. }
  162. this.openInput.onchange = () => {
  163. if (typeof this.onOpenChange === 'function') {
  164. this.onOpenChange(this.getOpen())
  165. }
  166. this.getOpen(this.setOpen())
  167. }
  168. console.log(this)
  169. }
  170. function Login (parent) {
  171. this.loginInput = document.createElement('input')
  172. parent.prepend(this.loginInput)
  173. this.loginInput.placeholder = 'Login'
  174. Object.assign(this.loginInput.style, {marginBottom: '5px'})
  175. this.setValue = newValue => this.loginInput.value = newValue
  176. this.getValue = () => {
  177. return this.loginInput.value
  178. }
  179. this.loginInput.oninput = () => {
  180. if (typeof this.onChange === 'function') {
  181. this.onChange(this.getValue())
  182. }
  183. }
  184. console.log(this)
  185. }
  186. const f = new Form (document.body)
  187. // Password Verify ================================================================================================
  188. function Password (parent,open) {
  189. this.passwordInput = document.createElement('input')
  190. parent.appendChild(this.passwordInput)
  191. this.passwordInput.type = open ? 'text' : 'password'
  192. this.openInput = document.createElement('input')
  193. parent.appendChild(this.openInput)
  194. this.openInput.type = 'checkBox'
  195. this.setValue = newValue => this.passwordInput.value = newValue
  196. this.getValue = () => {
  197. return this.passwordInput.value
  198. }
  199. this.setOpen = newOpen => {
  200. newOpen = this.openInput.checked
  201. this.passwordInput.type = newOpen ? 'text' : 'password'
  202. }
  203. this.getOpen = () => {
  204. return this.openInput.checked
  205. }
  206. this.passwordInput.oninput = () => {
  207. if (typeof this.onChange === 'function') {
  208. this.onChange(this.getValue())
  209. }
  210. }
  211. this.openInput.onchange = () => {
  212. if (typeof this.onOpenChange === 'function') {
  213. this.onOpenChange(this.getOpen())
  214. }
  215. this.getOpen(this.setOpen())
  216. }
  217. console.log(this)
  218. }
  219. function verifyPassword (parent, open) {
  220. const p = new Password(parent, open)
  221. const v = new Password(parent)
  222. v.passwordInput.type = 'password'
  223. p.passwordInput.style.marginBottom = '5px'
  224. parent.removeChild(v.openInput)
  225. open ? v.passwordInput.style.display = 'none' : v.passwordInput.style.display = 'block'
  226. p.onOpenChange = open => {
  227. open ? v.passwordInput.style.display = 'none' : v.passwordInput.style.display = 'block'
  228. }
  229. p.onChange = mainData => {
  230. if (mainData == '') p.passwordInput.style.background = 'white' && v.setValue('')
  231. v.onChange = checkData => {
  232. checkData === mainData ? p.passwordInput.style.background = '#98FB98' : p.passwordInput.style.background = '#E9967A'
  233. }
  234. }
  235. }
  236. const verify = verifyPassword(document.body, false)