first commit
This commit is contained in:
40
media/com_categories/js/shared-categories-accordion.js
Normal file
40
media/com_categories/js/shared-categories-accordion.js
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
if (!Joomla || !Joomla.Text) {
|
||||
throw new Error('core.js was not properly initialised');
|
||||
}
|
||||
|
||||
// Selectors used by this script
|
||||
const buttonsSelector = '[id^=category-btn-]';
|
||||
|
||||
/**
|
||||
* Handle the category toggle button click event
|
||||
* @param event
|
||||
*/
|
||||
const handleCategoryToggleButtonClick = ({
|
||||
currentTarget
|
||||
}) => {
|
||||
const button = currentTarget;
|
||||
const icon = button.querySelector('span');
|
||||
|
||||
// Toggle icon class
|
||||
icon.classList.toggle('icon-plus');
|
||||
icon.classList.toggle('icon-minus');
|
||||
|
||||
// Toggle aria label, aria-expanded
|
||||
const ariaLabel = button.getAttribute('aria-label');
|
||||
const ariaExpanded = button.getAttribute('aria-expanded');
|
||||
button.setAttribute('aria-label', ariaLabel === Joomla.Text._('JGLOBAL_EXPAND_CATEGORIES') ? Joomla.Text._('JGLOBAL_COLLAPSE_CATEGORIES') : Joomla.Text._('JGLOBAL_EXPAND_CATEGORIES'));
|
||||
button.setAttribute('aria-expanded', ariaExpanded === 'false' ? 'true' : 'false');
|
||||
const {
|
||||
categoryId
|
||||
} = button.dataset;
|
||||
const target = document.getElementById(`category-${categoryId}`);
|
||||
target.toggleAttribute('hidden');
|
||||
};
|
||||
Array.from(document.querySelectorAll(buttonsSelector)).forEach(button => {
|
||||
button.addEventListener('click', handleCategoryToggleButtonClick);
|
||||
});
|
||||
1
media/com_categories/js/shared-categories-accordion.min.js
vendored
Normal file
1
media/com_categories/js/shared-categories-accordion.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
if(!Joomla||!Joomla.Text)throw new Error("core.js was not properly initialised");const buttonsSelector="[id^=category-btn-]",handleCategoryToggleButtonClick=({currentTarget:t})=>{const e=t,o=e.querySelector("span");o.classList.toggle("icon-plus"),o.classList.toggle("icon-minus");const a=e.getAttribute("aria-label"),r=e.getAttribute("aria-expanded");e.setAttribute("aria-label",a===Joomla.Text._("JGLOBAL_EXPAND_CATEGORIES")?Joomla.Text._("JGLOBAL_COLLAPSE_CATEGORIES"):Joomla.Text._("JGLOBAL_EXPAND_CATEGORIES")),e.setAttribute("aria-expanded","false"===r?"true":"false");const{categoryId:l}=e.dataset;document.getElementById(`category-${l}`).toggleAttribute("hidden")};Array.from(document.querySelectorAll(buttonsSelector)).forEach((t=>{t.addEventListener("click",handleCategoryToggleButtonClick)}));
|
||||
BIN
media/com_categories/js/shared-categories-accordion.min.js.gz
Normal file
BIN
media/com_categories/js/shared-categories-accordion.min.js.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user