-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscripts.js
30 lines (25 loc) · 869 Bytes
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const passInput = document.querySelector('[data-pwd-input]')
const toggleBtn = document.querySelector('[data-pwd-toggle]')
let showPassword = false
passInput.addEventListener('input', showToggleButton)
passInput.addEventListener('focus', () => {
if (showPassword && passInput.value.length < 1) togglePasswordVisible()
})
toggleBtn.addEventListener('click', () => {
togglePasswordVisible()
passInput.focus()
})
function showToggleButton() {
if (passInput.value.length > 0) toggleBtn.style.display = 'block'
else toggleBtn.style.display = ''
}
function togglePasswordVisible() {
showPassword = !showPassword
if (showPassword) {
toggleBtn.classList = 'fas fa-eye-slash'
passInput.setAttribute('type', 'text')
} else {
toggleBtn.classList = 'fas fa-eye'
passInput.setAttribute('type', 'password')
}
}