overleaf/services/web/frontend/js/features/form-helpers/password-visibility.js
M Fahru 97abde3992 Merge pull request #17571 from overleaf/mf-website-redesign-login
[web] Website redesign for log in page

GitOrigin-RevId: 2f700ca7cec242598449b1f4fc830801976b9eaf
2024-03-28 09:04:29 +00:00

28 lines
976 B
JavaScript

const visibilityOnQuery = '[data-ol-password-visibility-toggle="visibilityOn"]'
const visibilityOffQuery =
'[data-ol-password-visibility-toggle="visibilityOff"]'
const visibilityOnButton = document.querySelector(visibilityOnQuery)
const visibilityOffButton = document.querySelector(visibilityOffQuery)
if (visibilityOffButton && visibilityOnButton) {
visibilityOnButton.addEventListener('click', function () {
const passwordInput = document.querySelector(
'[data-ol-password-visibility-target]'
)
passwordInput.type = 'text'
visibilityOnButton.hidden = true
visibilityOffButton.hidden = false
visibilityOffButton.focus()
})
visibilityOffButton.addEventListener('click', function () {
const passwordInput = document.querySelector(
'[data-ol-password-visibility-target]'
)
passwordInput.type = 'password'
visibilityOffButton.hidden = true
visibilityOnButton.hidden = false
visibilityOnButton.focus()
})
}