[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/plg_quickicon_privacycheck/js/ -> privacycheck.js (source)

   1  /**
   2   * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
   3   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   4   */
   5  (document => {
   6  
   7    const checkPrivacy = () => {
   8      const variables = Joomla.getOptions('js-privacy-check');
   9      const ajaxUrl = variables.plg_quickicon_privacycheck_ajax_url;
  10      const url = variables.plg_quickicon_privacycheck_url;
  11      const text = variables.plg_quickicon_privacycheck_text;
  12      const quickicon = document.getElementById('plg_quickicon_privacycheck');
  13      const link = quickicon.querySelector('span.j-links-link');
  14      /**
  15       * DO NOT use fetch() for QuickIcon requests. They must be queued.
  16       *
  17       * @see https://github.com/joomla/joomla-cms/issues/38001
  18       */
  19  
  20      Joomla.enqueueRequest({
  21        url: ajaxUrl,
  22        method: 'GET',
  23        promise: true
  24      }).then(xhr => {
  25        const response = xhr.responseText;
  26        const request = JSON.parse(response);
  27  
  28        if (request.data.number_urgent_requests) {
  29          // Quickicon on dashboard shows message
  30          const countBadge = document.createElement('span');
  31          countBadge.classList.add('badge', 'text-dark', 'bg-light');
  32          countBadge.textContent = request.data.number_urgent_requests;
  33          link.textContent = `$text.REQUESTFOUND} `;
  34          link.appendChild(countBadge); // Quickicon becomes red
  35  
  36          quickicon.classList.add('danger'); // Span in alert
  37  
  38          const countSpan = document.createElement('span');
  39          countSpan.classList.add('label', 'label-important');
  40          countSpan.textContent = `$text.REQUESTFOUND_MESSAGE.replace('%s', request.data.number_urgent_requests)} `; // Button in alert to 'view requests'
  41  
  42          const requestButton = document.createElement('button');
  43          requestButton.classList.add('btn', 'btn-primary', 'btn-sm');
  44          requestButton.setAttribute('onclick', `document.location='$url}'`);
  45          requestButton.textContent = text.REQUESTFOUND_BUTTON;
  46          const div = document.createElement('div');
  47          div.classList.add('alert', 'alert-error', 'alert-joomlaupdate');
  48          div.appendChild(countSpan);
  49          div.appendChild(requestButton); // Add elements to container for alert messages
  50  
  51          const container = document.querySelector('#system-message-container');
  52          container.insertBefore(div, container.firstChild);
  53        } else {
  54          quickicon.classList.add('success');
  55          link.textContent = text.NOREQUEST;
  56        }
  57      }).catch(() => {
  58        quickicon.classList.add('danger');
  59        link.textContent = text.ERROR;
  60      });
  61    }; // Give some times to the layout and other scripts to settle their stuff
  62  
  63  
  64    window.addEventListener('load', () => {
  65      setTimeout(checkPrivacy, 360);
  66    });
  67  })(document);


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