Skip to content

Commit

Permalink
check if toggleButton exists (#44555)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeutz authored Nov 29, 2024
1 parent e3ed020 commit d87bb98
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions build/media_source/system/js/fields/passwordview.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,45 @@
.forEach((input) => {
const toggleButton = input.parentNode.querySelector('.input-password-toggle');

const hasClickListener = toggleButton.getAttribute('clickListener') === 'true';

if (toggleButton && !hasClickListener) {
toggleButton.setAttribute('clickListener', 'true');
toggleButton.addEventListener('click', () => {
const icon = toggleButton.firstElementChild;
const srText = toggleButton.lastElementChild;

if (input.type === 'password') {
// Update the icon class
icon.classList.remove('icon-eye');
icon.classList.add('icon-eye-slash');

// Update the input type
input.type = 'text';

// Focus the input field
input.focus();

// Update the text for screenreaders
srText.innerText = Joomla.Text._('JHIDEPASSWORD');
} else if (input.type === 'text') {
// Update the icon class
icon.classList.add('icon-eye');
icon.classList.remove('icon-eye-slash');

// Update the input type
input.type = 'password';

// Focus the input field
input.focus();

// Update the text for screenreaders
srText.innerText = Joomla.Text._('JSHOWPASSWORD');
}
});
if (toggleButton) {
const hasClickListener = toggleButton.getAttribute('clickListener') === 'true';

if (!hasClickListener) {
toggleButton.setAttribute('clickListener', 'true');
toggleButton.addEventListener('click', () => {
const icon = toggleButton.firstElementChild;
const srText = toggleButton.lastElementChild;

if (input.type === 'password') {
// Update the icon class
icon.classList.remove('icon-eye');
icon.classList.add('icon-eye-slash');

// Update the input type
input.type = 'text';

// Focus the input field
input.focus();

// Update the text for screenreaders
srText.innerText = Joomla.Text._('JHIDEPASSWORD');
} else if (input.type === 'text') {
// Update the icon class
icon.classList.add('icon-eye');
icon.classList.remove('icon-eye-slash');

// Update the input type
input.type = 'password';

// Focus the input field
input.focus();

// Update the text for screenreaders
srText.innerText = Joomla.Text._('JSHOWPASSWORD');
}
});
}
}

const modifyButton = input.parentNode.querySelector('.input-password-modify');

if (modifyButton) {
Expand Down

0 comments on commit d87bb98

Please sign in to comment.