CoreFiles by mySites.guru
quickicon.js71 lines, 2,372 bytes, from Joomla_4.0.0-beta7-Beta-Full_Package.zip
Raw History Compare with 4.0.0-beta6
md5
aeb939a92cbd5a27db49691a265fc960
sha1
2aedebd15cac1d3564789b8ca356cd3ec4f1c7df
sha256
97b7ea05ee3be29505b3df1e80d81d06f0744cc344f26fc58b47683a97da6493
/**
* PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION.
* OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD.
**/

/**
 * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
(function (document, Joomla) {
  'use strict';
  /**
   * Every quickicon with an ajax request url loads data and set them into the counter element
   * Also the data name is set as singular or plural.
   * A SR-only text is added
   * The class pulse gets 'warning', 'success' or 'error', depending on the retrieved data.
   */

  document.addEventListener('DOMContentLoaded', function () {
    document.querySelectorAll('.quickicon').forEach(function (quickicon) {
      var pulse = quickicon.querySelector('.pulse');
      var counter = quickicon.querySelector('.quickicon-amount');

      if (!counter) {
        return;
      }

      if (counter.dataset.url) {
        Joomla.request({
          url: counter.dataset.url,
          method: 'GET',
          onSuccess: function onSuccess(resp) {
            var response = JSON.parse(resp);

            if (Object.prototype.hasOwnProperty.call(response, 'data')) {
              var name = quickicon.querySelector('.quickicon-name');
              var nameSpan = document.createElement('span');

              if (pulse) {
                var className = response.data > 0 ? 'warning' : 'success';
                pulse.classList.add(className);
              } // Set name in singular or plural


              if (response.data.name && name) {
                nameSpan.textContent = response.data.name;
                name.replaceChild(nameSpan, name.firstChild);
              } // Set amount of number into counter span


              counter.textContent = "\u200E".concat(response.data.amount); // Insert screenreader text

              var sronly = quickicon.querySelector('.quickicon-sr-desc');

              if (response.data.sronly && sronly) {
                sronly.textContent = response.data.sronly;
              }
            } else if (pulse) {
              pulse.classList.add('error');
            }
          },
          onError: function onError() {
            if (pulse) {
              pulse.classList.add('error');
            }
          }
        });
      }
    });
  });
})(document, Joomla);

No other release has this exact content. See every version of this file.