diff --git a/account/templates/account/forms/widgets/c_password.html b/account/templates/account/forms/widgets/c_password.html index a5271db..bb50287 100644 --- a/account/templates/account/forms/widgets/c_password.html +++ b/account/templates/account/forms/widgets/c_password.html @@ -2,9 +2,18 @@
- +
- + eye
\ No newline at end of file diff --git a/note/static/account/css/forms/widgets/c_password.css b/note/static/account/css/forms/widgets/c_password.css index 52490a3..5506e84 100644 --- a/note/static/account/css/forms/widgets/c_password.css +++ b/note/static/account/css/forms/widgets/c_password.css @@ -1,3 +1,3 @@ -.toogle-eye { +.toggle-eye { cursor: pointer; } \ No newline at end of file diff --git a/note/static/account/js/forms/widgets/cPassword.js b/note/static/account/js/forms/widgets/cPassword.js index a7b8577..badcec3 100644 --- a/note/static/account/js/forms/widgets/cPassword.js +++ b/note/static/account/js/forms/widgets/cPassword.js @@ -1,15 +1,20 @@ -const passwords = [...document.getElementsByClassName('js-toogle-password')]; -const eyes = [...document.getElementsByClassName('toogle-eye')]; -let state = false; +const passwordEyes = [...document.getElementsByClassName('toggle-eye')]; +passwordEyes.forEach((eye) => { + eye.addEventListener('click', () => { + if ('inputId' in eye.dataset && 'state' in eye.dataset) { + const input = document.getElementById(eye.dataset.inputId); + const state = eye.dataset.state; -function tooglePasswordView (ps = passwords) { - ps.forEach((p) => { - if (p.type) { - state? p.type = 'password': p.type = 'text'; - }; - }); - state = !state; -}; + if (input && input.hasAttribute('type') && state) { + input.type = state === '1'? 'password': 'text'; + eye.dataset.state = state === '1'? '0': '1'; -eyes.forEach((eye) => eye.addEventListener('click', () => tooglePasswordView(passwords))); \ No newline at end of file + if ('eye' in eye.dataset && 'closedEye' in eye.dataset && eye.hasAttribute('src')) { + eye.src = state === '1'? eye.dataset.eye: eye.dataset.closedEye; + eye.title = state === '1'? 'click to see password': 'click to hide password' + } + } + } + }) +}) \ No newline at end of file diff --git a/note/static/svg/eye_closed.svg b/note/static/svg/eye_closed.svg new file mode 100644 index 0000000..077e293 --- /dev/null +++ b/note/static/svg/eye_closed.svg @@ -0,0 +1 @@ + \ No newline at end of file