CoreFiles by mySites.guru
token.es6.js66 lines, 1,675 bytes, from Joomla_4.0.0-beta7-Beta-Full_Package.zip
Raw History Compare with 4.0.0-beta6
md5
f923fcb8f51b4e6c4b643a65c7364752
sha1
95a68bf481b86dbb90abd6be037ffe5b8e740638
sha256
4776f84bf39c358e354f5a248d2d8a3cf183ae6ec219dd398fc28c4c65783262
/**
* PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION.
* OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD.
**/

/**
 * @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) => {
  'use strict';

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

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

      if (copy) {
        Joomla.renderMessages({
          message: [Joomla.JText._('PLG_USER_TOKEN_COPY_SUCCESS')]
        });
      } else {
        Joomla.renderMessages({
          error: [Joomla.JText._('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.parentNode.previousElementSibling;

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

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

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

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

The same content is in 2 releases, Joomla 4.0.0-beta6 to 4.0.0-beta7. See them all, or every version of this file.