Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] ES6 please, com_contacts #21453

Merged
merged 2 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 0 additions & 43 deletions build/media/com_contact/js/categories-default.js

This file was deleted.

51 changes: 51 additions & 0 deletions build/media_src/com_contact/js/categories-default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
((Joomla) => {
'use strict';

if (!Joomla || typeof Joomla.JText !== 'function') {
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 = (event) => {
const button = event.currentTarget;
const icon = button.querySelector('span');

// Toggle icon class
icon.classList.toggle('icon-plus');
icon.classList.toggle('icon-minus');

// Toggle aria label
const ariaLabel = button.getAttribute('aria-label');
button.setAttribute(
'aria-label',
(
ariaLabel === Joomla.JText._('JGLOBAL_EXPAND_CATEGORIES') ? Joomla.JText._('JGLOBAL_COLLAPSE_CATEGORIES') : Joomla.JText._('JGLOBAL_EXPAND_CATEGORIES')
),
);
};

/**
* Script boot
*/
const onBoot = () => {
const buttons = [].slice.call(document.querySelectorAll(buttonsSelector));
buttons.forEach((button) => {
button.addEventListener('click', handleCategoryToggleButtonClick);
});

// Cleanup
document.removeEventListener('DOMContentLoaded', onBoot);
};

document.addEventListener('DOMContentLoaded', onBoot);
})(Joomla);