[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/plg_user_token/js/ -> token.js (source)

   1  /**
   2   * @copyright  (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
   3   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   4   */
   5  ((document, Joomla) => {
   6  
   7    const copyToClipboardFallback = input => {
   8      input.focus();
   9      input.select();
  10  
  11      try {
  12        const copy = document.execCommand('copy');
  13  
  14        if (copy) {
  15          Joomla.renderMessages({
  16            message: [Joomla.Text._('PLG_USER_TOKEN_COPY_SUCCESS')]
  17          });
  18        } else {
  19          Joomla.renderMessages({
  20            error: [Joomla.Text._('PLG_USER_TOKEN_COPY_FAIL')]
  21          });
  22        }
  23      } catch (err) {
  24        Joomla.renderMessages({
  25          error: [err]
  26        });
  27      }
  28    };
  29  
  30    const copyToClipboard = () => {
  31      const button = document.getElementById('token-copy');
  32      button.addEventListener('click', ({
  33        currentTarget
  34      }) => {
  35        const input = currentTarget.previousElementSibling;
  36  
  37        if (!navigator.clipboard) {
  38          copyToClipboardFallback(input);
  39          return;
  40        }
  41  
  42        navigator.clipboard.writeText(input.value).then(() => {
  43          Joomla.renderMessages({
  44            message: [Joomla.Text._('PLG_USER_TOKEN_COPY_SUCCESS')]
  45          });
  46        }, () => {
  47          Joomla.renderMessages({
  48            error: [Joomla.Text._('PLG_USER_TOKEN_COPY_FAIL')]
  49          });
  50        });
  51      });
  52    };
  53  
  54    const onBoot = () => {
  55      copyToClipboard();
  56      document.removeEventListener('DOMContentLoaded', onBoot);
  57    };
  58  
  59    document.addEventListener('DOMContentLoaded', onBoot);
  60  })(document, Joomla);


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer