CoreFiles by mySites.guru
token.js54 lines, 1,510 bytes, from Joomla_4.3.2-Stable-Full_Package.zip
Raw History Compare with 4.3.1
md5
52582402de59421eccd5a69a6132c681
sha1
fb6ea64ed55a4a1a4c5df4194d8e56aee02ec22f
sha256
0cee13e761aaab2f5cb92c9320d90f05b83fb2f27064b9e39a47188aadb6801d
/**
 * @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 214 releases, Joomla 4.3.0-alpha1 to 6.3.0-alpha1. See them all, or every version of this file.