CoreFiles by mySites.guru
quickicon-es5.js63 lines, 2,148 bytes, from Joomla_4.4.13-Stable-Full_Package.zip
Raw History Compare with 4.4.12
md5
d442afb7121d1d9266982a4ebe91595f
sha1
b07f84b7824c8096fedee61529d11e6176de2958
sha256
a4ad8a20aa721037c2f0bb54ad3198f55ea53d7f0459d266006baceee3851aec
(function () {
  'use strict';

  /**
   * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   */
  /**
   * 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.
   */
  if (!Joomla) {
    throw new Error('Joomla API was not properly initialized');
  }
  Array.from(document.querySelectorAll('.quickicon')).forEach(function (quickicon) {
    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;
          try {
            response = JSON.parse(resp);
          } catch (error) {
            quickicon.classList.add('error');
          }
          if (Object.prototype.hasOwnProperty.call(response, 'data')) {
            var name = quickicon.querySelector('.quickicon-name');
            var nameSpan = document.createElement('span');
            quickicon.classList.add(response.data > 0 ? 'warning' : 'success');

            // 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" + response.data.amount;

            // Insert screenreader text
            var sronly = quickicon.querySelector('.quickicon-sr-desc');
            if (response.data.sronly && sronly) {
              sronly.textContent = response.data.sronly;
            }
          } else {
            quickicon.classList.add('error');
          }
        },
        onError: function onError() {
          quickicon.classList.add('error');
        }
      });
    }
  });

})();

The same content is in 57 releases, Joomla 4.3.0-alpha1 to 5.0.0-alpha1. See them all, or every version of this file.