[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/mod_quickicon/js/ -> quickicon-es5.js (source)

   1  (function () {
   2    'use strict';
   3  
   4    /**
   5     * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
   6     * @license    GNU General Public License version 2 or later; see LICENSE.txt
   7     */
   8  
   9    /**
  10     * Every quickicon with an ajax request url loads data and set them into the counter element
  11     * Also the data name is set as singular or plural.
  12     * A SR-only text is added
  13     * The class pulse gets 'warning', 'success' or 'error', depending on the retrieved data.
  14     */
  15    if (!Joomla) {
  16      throw new Error('Joomla API was not properly initialized');
  17    }
  18  
  19    Array.from(document.querySelectorAll('.quickicon')).forEach(function (quickicon) {
  20      var counter = quickicon.querySelector('.quickicon-amount');
  21  
  22      if (!counter) {
  23        return;
  24      }
  25  
  26      if (counter.dataset.url) {
  27        Joomla.request({
  28          url: counter.dataset.url,
  29          method: 'GET',
  30          onSuccess: function onSuccess(resp) {
  31            var response;
  32  
  33            try {
  34              response = JSON.parse(resp);
  35            } catch (error) {
  36              quickicon.classList.add('error');
  37            }
  38  
  39            if (Object.prototype.hasOwnProperty.call(response, 'data')) {
  40              var name = quickicon.querySelector('.quickicon-name');
  41              var nameSpan = document.createElement('span');
  42              quickicon.classList.add(response.data > 0 ? 'warning' : 'success'); // Set name in singular or plural
  43  
  44              if (response.data.name && name) {
  45                nameSpan.textContent = response.data.name;
  46                name.replaceChild(nameSpan, name.firstChild);
  47              } // Set amount of number into counter span
  48  
  49  
  50              counter.textContent = "\u200E" + response.data.amount; // Insert screenreader text
  51  
  52              var sronly = quickicon.querySelector('.quickicon-sr-desc');
  53  
  54              if (response.data.sronly && sronly) {
  55                sronly.textContent = response.data.sronly;
  56              }
  57            } else {
  58              quickicon.classList.add('error');
  59            }
  60          },
  61          onError: function onError() {
  62            quickicon.classList.add('error');
  63          }
  64        });
  65      }
  66    });
  67  
  68  })();


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