Skip to content

Commit

Permalink
Minor cleanup for components' JS
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Lodder committed Feb 9, 2024
1 parent ef8bc6a commit 2cd81cc
Show file tree
Hide file tree
Showing 33 changed files with 96 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Joomla.submitbutton = (task) => {
if (task === 'actionlogs.exportSelectedLogs') {
// Get id of selected action logs item and pass it to export form hidden input
const cids = [];
const elements = [].slice.call(document.querySelectorAll("input[name='cid[]']:checked"));
const elements = document.querySelectorAll("input[name='cid[]']:checked");

if (elements.length) {
elements.forEach((element) => {
Expand Down
4 changes: 2 additions & 2 deletions build/media_source/com_admin/js/admin-help.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

const helpIndex = document.getElementById('help-index');
if (helpIndex) {
[].slice.call(helpIndex.querySelectorAll('a'))
.map((element) => element.addEventListener('click', () => { window.scroll(0, 0); }));
helpIndex.querySelectorAll('a')).forEach((element) => element.addEventListener('click', () => window.scroll(0, 0)));
}
19 changes: 5 additions & 14 deletions build/media_source/com_associations/js/associations-edit.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ Joomla = window.Joomla || {};
'use strict';

Joomla.hideAssociation = (formControl, languageCode) => {
const controlGroup = [].slice.call(document.querySelectorAll('#associations .control-group'));

controlGroup.forEach((element) => {
document.querySelectorAll('#associations .control-group').forEach((element) => {
// Current selected language. Hide it
const el = element.querySelector('.control-label label');

Expand All @@ -25,7 +23,6 @@ Joomla = window.Joomla || {};
};

Joomla.showAssociationMessage = () => {
const controlGroup = [].slice.call(document.querySelectorAll('#associations .control-group'));
const associations = document.getElementById('associations');

if (associations) {
Expand All @@ -35,7 +32,7 @@ Joomla = window.Joomla || {};
associations.insertAdjacentElement('afterbegin', html);
}

controlGroup.forEach((element) => {
document.querySelectorAll('#associations .control-group').forEach((element) => {
element.classList.add('hidden');
});
};
Expand Down Expand Up @@ -67,7 +64,7 @@ Joomla = window.Joomla || {};

if (result.success) {
if (result.data.length !== 0) {
[].slice.call(Object.keys(result.data)).forEach((lang) => {
Object.keys(result.data).forEach((lang) => {
functionName = callbackFunctionPrefix + lang.replace('-', '_');
window[functionName](result.data[lang].id, result.data[lang].title, result.data[lang].catid, null, null, lang);
});
Expand Down Expand Up @@ -164,9 +161,7 @@ Joomla = window.Joomla || {};
/** For each language, remove the associations, ie,
* empty the associations fields and reset the buttons to Select/Create
*/
const controlGroup = [].slice.call(document.querySelectorAll('#associations .control-group'));

controlGroup.forEach((element) => {
document.querySelectorAll('#associations .control-group').forEach((element) => {
const attribute = element.querySelector('.control-label label').getAttribute('for');
const languageCode = attribute.replace('_name', '').replace('jform_associations_', '');

Expand All @@ -182,11 +177,7 @@ Joomla = window.Joomla || {};
let clear = document.getElementById(`${formControl}_associations_${languageCode}_clear`);
clear = clear || element.querySelector('[data-button-action="clear"]');

if (clear.onclick) {
clear.onclick();
} else if (clear.click) {
clear.click();
}
clear.click();
});

// If associations existed, send a warning to the user
Expand Down
2 changes: 1 addition & 1 deletion build/media_source/com_cache/js/admin-cache-default.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Joomla = window.Joomla || {};
'use strict';

document.addEventListener('DOMContentLoaded', () => {
[].slice.call(document.querySelectorAll('.cache-entry')).forEach((el) => {
document.querySelectorAll('.cache-entry').forEach((el) => {
el.addEventListener('click', ({ currentTarget }) => {
Joomla.isChecked(currentTarget.checked);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ const handleCategoryToggleButtonClick = ({ currentTarget }) => {
target.toggleAttribute('hidden');
};

Array.from(document.querySelectorAll(buttonsSelector)).forEach((button) => {
document.querySelectorAll(buttonsSelector).forEach((button) => {
button.addEventListener('click', handleCategoryToggleButtonClick);
});
3 changes: 1 addition & 2 deletions build/media_source/com_config/js/config-default.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
* Register events
*/
const registerEvents = () => {
const buttons = [].slice.call(document.querySelectorAll(`[${buttonDataSelector}]`));
buttons.forEach((button) => {
document.querySelectorAll(`[${buttonDataSelector}]`).forEach((button) => {
button.addEventListener('click', (e) => {
e.preventDefault();
const task = e.currentTarget.getAttribute(buttonDataSelector);
Expand Down
11 changes: 4 additions & 7 deletions build/media_source/com_config/js/config-filters.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
const recursiveApplyChanges = (id) => {
const childs = [].slice.call(document.querySelectorAll(`#filter-config select[data-parent="${id}"]`));
childs.map((child) => {
document.querySelectorAll(`#filter-config select[data-parent="${id}"]`).forEach((child) => {
recursiveApplyChanges(child.dataset.id);
child.value = 'NONE';
return child;
});
};

Expand All @@ -16,15 +14,14 @@ const applyChanges = (event) => {
const currentFilter = currentElement.options[currentElement.selectedIndex].value;

if (currentFilter === 'NONE') {
const childs = [].slice.call(document.querySelectorAll(`#filter-config select[data-parent="${currentElement.dataset.id}"]`));
const childs = document.querySelectorAll(`#filter-config select[data-parent="${currentElement.dataset.id}"]`);
if (childs.length && window.confirm(Joomla.Text._('COM_CONFIG_TEXT_FILTERS_NOTE'))) {
childs.map((child) => {
childs.forEach((child) => {
recursiveApplyChanges(child.dataset.id);
child.value = 'NONE';
return child;
});
}
}
};

[].slice.call(document.querySelectorAll('#filter-config select')).map((select) => select.addEventListener('change', applyChanges));
document.querySelectorAll('#filter-config select').forEach((select) => select.addEventListener('change', applyChanges));
3 changes: 1 addition & 2 deletions build/media_source/com_config/js/modules-default.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
* Register events
*/
const registerEvents = () => {
const buttons = [].slice.call(document.querySelectorAll(`[${buttonDataSelector}]`));
buttons.forEach((button) => {
document.querySelectorAll(`[${buttonDataSelector}]`).forEach((button) => {
button.addEventListener('click', (e) => {
e.preventDefault();
const task = e.currentTarget.getAttribute(buttonDataSelector);
Expand Down
3 changes: 1 addition & 2 deletions build/media_source/com_config/js/templates-default.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
* Register events
*/
const registerEvents = () => {
const buttons = [].slice.call(document.querySelectorAll(`[${buttonDataSelector}]`));
buttons.forEach((button) => {
document.querySelectorAll(`[${buttonDataSelector}]`).forEach((button) => {
button.addEventListener('click', (e) => {
e.preventDefault();
const task = e.currentTarget.getAttribute(buttonDataSelector);
Expand Down
9 changes: 3 additions & 6 deletions build/media_source/com_contact/js/admin-contacts-modal.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@
};

document.addEventListener('DOMContentLoaded', () => {
// Get the elements
const elements = document.querySelectorAll('.select-link');

for (let i = 0, l = elements.length; l > i; i += 1) {
document.querySelectorAll('.select-link').forEach((element) => {
// Listen for click event
elements[i].addEventListener('click', (event) => {
element.addEventListener('click', (event) => {
event.preventDefault();
const functionName = event.target.getAttribute('data-function');

Expand All @@ -64,6 +61,6 @@
window.parent.Joomla.Modal.getCurrent().close();
}
});
}
});
});
})();
4 changes: 1 addition & 3 deletions build/media_source/com_content/js/articles-status.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
'use strict';

document.addEventListener('DOMContentLoaded', () => {
const elements = [].slice.call(document.querySelectorAll('.article-status'));

elements.forEach((element) => {
document.querySelectorAll('.article-status').forEach((element) => {
element.addEventListener('click', (event) => {
event.stopPropagation();
});
Expand Down
3 changes: 1 addition & 2 deletions build/media_source/com_content/js/form-edit.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

// Register events
document.addEventListener('DOMContentLoaded', () => {
const buttons = [].slice.call(document.querySelectorAll(`[${buttonDataSelector}]`));
buttons.forEach((button) => {
document.querySelectorAll(`[${buttonDataSelector}]`).forEach((button) => {
button.addEventListener('click', (e) => {
e.preventDefault();
const task = e.target.getAttribute(buttonDataSelector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
};

const onBoot = () => {
const diffs = [].slice.call(document.querySelectorAll('.original'));
diffs.forEach((fragment) => {
document.querySelectorAll('.original').forEach((fragment) => {
compare(fragment, fragment.nextElementSibling);
});

Expand Down
3 changes: 1 addition & 2 deletions build/media_source/com_cpanel/js/admin-cpanel-default.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ const debounce = (callback, time = 250, interval) => (...args) => clearTimeout(i
const onBoot = () => {
const cpanelModules = document.getElementById('content');
if (cpanelModules) {
const links = [].slice.call(cpanelModules.querySelectorAll('.unpublish-module'));
links.forEach((link) => {
cpanelModules.querySelectorAll('.unpublish-module').forEach((link) => {
link.addEventListener('click', ({ target }) => Joomla.unpublishModule(target));
});
}
Expand Down
25 changes: 8 additions & 17 deletions build/media_source/com_cpanel/js/admin-system-loader.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
window.removeEventListener('load', init);

// Get the elements
const elements = [].slice.call(document.querySelectorAll('.system-counter'));
const elements = document.querySelectorAll('.system-counter');

if (elements.length) {
elements.forEach((element) => {
Expand All @@ -31,30 +31,21 @@
}

if (response.error || !response.success) {
element.classList.remove('icon-spin');
element.classList.remove('icon-spinner');
element.classList.add('text-danger');
element.classList.add('icon-remove');
element.classList.remove('icon-spin', 'icon-spinner');
element.classList.add('text-danger', 'icon-remove');
} else if (response.data) {
const elem = document.createElement('span');

elem.classList.add('float-end');
elem.classList.add('badge');
elem.classList.add('bg-warning', 'text-dark');
elem.classList.add('float-end', 'badge', 'bg-warning', 'text-dark');
elem.innerHTML = Joomla.sanitizeHtml(response.data);

element.parentNode.replaceChild(elem, element);
} else {
element.classList.remove('icon-spin');
element.classList.remove('icon-spinner');
element.classList.add('icon-check');
element.classList.add('text-success');
element.classList.remove('icon-spin', 'icon-spinner');
element.classList.add('icon-check', 'text-success');
}
}).catch(() => {
element.classList.remove('icon-spin');
element.classList.remove('icon-spinner');
element.classList.add('text-danger');
element.classList.add('icon-remove');
element.classList.remove('icon-spin', 'icon-spinner');
element.classList.add('text-danger', 'icon-remove');
});
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

Joomla.fieldsChangeContext = (context) => {
'use strict';

Expand Down
28 changes: 11 additions & 17 deletions build/media_source/com_finder/js/finder-edit.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,26 @@ Joomla = window.Joomla || {};

document.addEventListener('DOMContentLoaded', () => {
// Handle toggle all
[].slice.call(document.querySelectorAll('.filter-toggle-all')).forEach((button) => {
document.querySelectorAll('.filter-toggle-all').forEach((button) => {
button.addEventListener('click', () => {
[].slice.call(document.querySelectorAll('.filter-node')).forEach((node) => {
node.click();
});
document.querySelectorAll('.filter-node').forEach((node) => node.click());
});
});

// Update the count
[].slice.call(document.querySelectorAll('.filter-node')).forEach(() => {
document.querySelectorAll('.filter-node').forEach(() => {
const count = document.getElementById('jform_map_count');
if (count) {
count.value = document.querySelectorAll('input[type="checkbox"]:checked').length;
}
});

Array.from(document.querySelectorAll('.js-filter'))
.forEach((button) => {
button.addEventListener('click', (event) => {
const btn = event.currentTarget;
Array.from(document.querySelectorAll(`.${btn.dataset.id}`))
.map((el) => el.click());
});
document.querySelectorAll('.js-filter').forEach((button) => {
button.addEventListener('click', (event) => {
const btn = event.currentTarget;
document.querySelectorAll(`.${btn.dataset.id}`).forEach((el) => el.click());
});
});

// Expand/collapse
const expandAccordion = document.getElementById('expandAccordion');
Expand All @@ -45,17 +41,15 @@ Joomla = window.Joomla || {};
if (event.target.innerText === Joomla.Text._('COM_FINDER_FILTER_SHOW_ALL')) {
event.target.innerText = Joomla.Text._('COM_FINDER_FILTER_HIDE_ALL');

elements = [].slice.call(document.querySelectorAll('.accordion-button.collapsed'));
elements = document.querySelectorAll('.accordion-button.collapsed');
} else {
event.target.innerText = Joomla.Text._('COM_FINDER_FILTER_SHOW_ALL');

elements = [].slice.call(document.querySelectorAll('.accordion-button:not(.collapsed)'));
elements = document.querySelectorAll('.accordion-button:not(.collapsed)');
}

if (elements) {
elements.forEach((element) => {
element.click();
});
elements.forEach((element) => element.click());
}
});
}
Expand Down
8 changes: 2 additions & 6 deletions build/media_source/com_finder/js/finder.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@

// The boot sequence
const onBoot = () => {
const searchWords = [].slice.call(document.querySelectorAll('.js-finder-search-query'));

searchWords.forEach((searchword) => {
document.querySelectorAll('.js-finder-search-query').forEach((searchword) => {
// Handle the auto suggestion
if (Joomla.getOptions('finder-search')) {
searchword.awesomplete = new Awesomplete(searchword);
Expand All @@ -85,9 +83,7 @@
}
});

const forms = [].slice.call(document.querySelectorAll('.js-finder-searchform'));

forms.forEach((form) => {
document.querySelectorAll('.js-finder-searchform').forEach((form) => {
form.addEventListener('submit', onSubmit);
});

Expand Down

0 comments on commit 2cd81cc

Please sign in to comment.