CoreFiles by mySites.guru
two-factor-focus.js51 lines, 1,911 bytes, from Joomla_4.3.3-Stable-Full_Package.zip
Raw History Compare with 4.3.2
md5
246fb0360714e5982a2a99e674de1c79
sha1
3e36249f4cedf32ce23743fced7f0e3023594000
sha256
72f5b814b878a22c9bff06246c262aed201ac32609cc78bc6b1303b0da95a798
/**
 * @copyright   (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

(() => {

  document.addEventListener('DOMContentLoaded', () => {
    const elCodeField = document.getElementById('users-mfa-code');
    const elValidateButton = document.getElementById('users-mfa-captive-button-submit');
    const elToolbarButton = document.getElementById('toolbar-user-mfa-submit')?.querySelector('button');

    // Focus the code field. If the code field is hidden, focus the submit button (useful e.g. for WebAuthn)
    if (elCodeField && elCodeField.style.display !== 'none' && !elCodeField.classList.contains('visually-hidden') && elCodeField.type !== 'hidden') {
      elCodeField.focus();
    } else {
      if (elValidateButton) {
        elValidateButton.focus();
      }
      if (elToolbarButton) {
        elToolbarButton.focus();
      }
    }

    // Capture the admin toolbar buttons, make them click the inline buttons
    document.querySelectorAll('.button-user-mfa-submit').forEach(elButton => {
      elButton.addEventListener('click', e => {
        e.preventDefault();
        elValidateButton.click();
      });
    });
    document.querySelectorAll('.button-user-mfa-logout').forEach(elButton => {
      elButton.addEventListener('click', e => {
        e.preventDefault();
        const elLogout = document.getElementById('users-mfa-captive-button-logout');
        if (elLogout) {
          elLogout.click();
        }
      });
    });
    document.querySelectorAll('.button-user-mfa-choose-another').forEach(elButton => {
      elButton.addEventListener('click', e => {
        e.preventDefault();
        const elChooseAnother = document.getElementById('users-mfa-captive-form-choose-another');
        if (elChooseAnother) {
          elChooseAnother.click();
        }
      });
    });
  });
})();

The same content is in 44 releases, Joomla 4.3.2-rc1 to 5.0.0-alpha1. See them all, or every version of this file.