CoreFiles by mySites.guru
token.js60 lines, 1,516 bytes, from Joomla_4.2.3-Stable-Full_Package.zip
Raw History Compare with 4.2.2
md5
8e2eba79ffede05a7165625f08c5bd07
sha1
0491ecac404fd1d378eb42448afb6ccb4f974903
sha256
f19ffb72b54b8f3547c2d8c5eb9075570a1885e2ccbacbc4af087c22df33a1f4
/**
 * @copyright  (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
((document, Joomla) => {

  const copyToClipboardFallback = input => {
    input.focus();
    input.select();

    try {
      const copy = document.execCommand('copy');

      if (copy) {
        Joomla.renderMessages({
          message: [Joomla.Text._('PLG_USER_TOKEN_COPY_SUCCESS')]
        });
      } else {
        Joomla.renderMessages({
          error: [Joomla.Text._('PLG_USER_TOKEN_COPY_FAIL')]
        });
      }
    } catch (err) {
      Joomla.renderMessages({
        error: [err]
      });
    }
  };

  const copyToClipboard = () => {
    const button = document.getElementById('token-copy');
    button.addEventListener('click', ({
      currentTarget
    }) => {
      const input = currentTarget.previousElementSibling;

      if (!navigator.clipboard) {
        copyToClipboardFallback(input);
        return;
      }

      navigator.clipboard.writeText(input.value).then(() => {
        Joomla.renderMessages({
          message: [Joomla.Text._('PLG_USER_TOKEN_COPY_SUCCESS')]
        });
      }, () => {
        Joomla.renderMessages({
          error: [Joomla.Text._('PLG_USER_TOKEN_COPY_FAIL')]
        });
      });
    });
  };

  const onBoot = () => {
    copyToClipboard();
    document.removeEventListener('DOMContentLoaded', onBoot);
  };

  document.addEventListener('DOMContentLoaded', onBoot);
})(document, Joomla);

The same content is in 67 releases, Joomla 4.0.0-rc2 to 4.2.9. See them all, or every version of this file.