1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- function Password(parent, open) {
- let value = ''
- let pass = document.createElement('input')
- pass.placeholder = 'enter password'
- let showPassBox = document.createElement('div')
- let check = document.createElement('input')
- check.type = 'checkbox'
- check.name = 'password'
- let label = document.createElement('label')
- label.for = 'password'
- label.innerText = 'Show password'
- showPassBox.append(check, label)
- parent.append(pass, showPassBox)
- check.onchange = () => {
- this.setOpen(check.checked)
- }
- pass.oninput = () => {
- if (typeof this.onChange === "function") {
- this.onChange(this.getValue());
- }
- };
- this.getValue = function () {
- return pass.value
- }
- this.setValue = function(value) {
- pass.value = value
- }
- this.getOpen = function () {
- return open
- }
- this.setOpen = function(newOpen) {
- open = newOpen
- pass.type = open ? 'text' : 'password'
- check.checked = open
- if(typeof this.onOpenChange === 'function') {
- this.onOpenChange(open)
- }
- }
- this.setOpen(open)
- this.onChange = () => {
- button.disabled = !(p.getValue() === p2.getValue())
- }
- }
- // let p = new Password(document.body, false)
- //
- // p.onChange = data => console.log(data)
- // p.onOpenChange = open => console.log(open)
- //
- // p.setValue('qwerty')
- // console.log(p.getValue())
- // p.setOpen(false)
- // console.log(p.getOpen())
- function Login(parent) {
- let input = document.createElement('input')
- input.placeholder = 'enter login'
- let button = document.createElement('button')
- button.innerText = 'log in'
- parent.appendChild(input)
- let password = new Password(parent, false)
- password.placeholder = 'enter password'
- button.disabled = true
- parent.appendChild(button)
- parent.onchange = function () {
- console.log(password.getValue())
- button.disabled = !(input.value !== '' && password.getValue() !== '')
- }
- }
- let newLogin = new Login(loginForm)
- console.log(newLogin)
- let p = new Password(document.body, true)
- let p2 = new Password(document.body, true)
- let button = document.createElement('button')
- button.innerText = 'log in'
- button.disabled = true
- document.body.append(button)
|