- md5
- 8215179ba782dad71f165dff60f7e071
- sha1
- f5f01ff4d3a492fe52e73ccbf4e8ab36f38e0a3b
- sha256
- e3b5bfd09b689bf3acea648231114c727f521e22e901f4d1781498e3b1d52fd2
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
/**
* @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');
}
document.querySelectorAll('.quickicon').forEach(quickicon => {
const counter = quickicon.querySelector('.quickicon-amount');
if (!counter) {
return;
}
if (counter.dataset.url) {
Joomla.request({
url: counter.dataset.url,
method: 'GET',
onSuccess: resp => {
let response;
try {
response = JSON.parse(resp);
} catch (error) {
quickicon.classList.add('error');
}
if (Object.hasOwn(response, 'data')) {
const name = quickicon.querySelector('.quickicon-name');
const 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
const sronly = quickicon.querySelector('.quickicon-sr-desc');
if (response.data.sronly && sronly) {
sronly.textContent = response.data.sronly;
}
} else {
quickicon.classList.add('error');
}
},
onError: () => {
quickicon.classList.add('error');
}
});
}
});
The same content is in 136 releases, Joomla 5.1.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.