Skip to content

Commit 4f85ef5

Browse files
authored
[4.0] Convert inline to file and remove jQuery (#34478)
1 parent 9812f17 commit 4f85ef5

File tree

3 files changed

+54
-38
lines changed

3 files changed

+54
-38
lines changed

administrator/components/com_config/src/Field/FiltersField.php

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Joomla\CMS\Factory;
1515
use Joomla\CMS\Form\FormField;
16-
use Joomla\CMS\HTML\HTMLHelper;
1716
use Joomla\CMS\Language\Text;
1817
use Joomla\CMS\Layout\LayoutHelper;
1918

@@ -43,47 +42,11 @@ class FiltersField extends FormField
4342
*/
4443
protected function getInput()
4544
{
46-
// Load Framework
47-
HTMLHelper::_('jquery.framework');
48-
4945
// Add translation string for notification
5046
Text::script('COM_CONFIG_TEXT_FILTERS_NOTE');
5147

5248
// Add Javascript
53-
$doc = Factory::getDocument();
54-
$doc->addScriptDeclaration('
55-
jQuery( document ).ready(function( $ ) {
56-
$("#filter-config select").change(function() {
57-
var currentFilter = $(this).children("option:selected").val();
58-
59-
if($(this).children("option:selected").val() === "NONE") {
60-
var child = $("#filter-config select[data-parent=" + $(this).attr("data-id") + "]");
61-
62-
while(child.length !== 0) {
63-
if(child.children("option:selected").val() !== "NONE") {
64-
alert(Joomla.Text._("COM_CONFIG_TEXT_FILTERS_NOTE"));
65-
break;
66-
}
67-
68-
child = $("#filter-config select[data-parent=" + child.attr("data-id") + "]");
69-
}
70-
71-
return;
72-
}
73-
74-
var parent = $("#filter-config select[data-id=" + $(this).attr("data-parent") + "]");
75-
76-
while(parent.length !== 0) {
77-
if(parent.children("option:selected").val() === "NONE") {
78-
alert(Joomla.Text._("COM_CONFIG_TEXT_FILTERS_NOTE"));
79-
break;
80-
}
81-
82-
parent = $("#filter-config select[data-id=" + parent.attr("data-parent") + "]")
83-
}
84-
});
85-
});'
86-
);
49+
Factory::getDocument()->getWebAssetManager()->useScript('com_config.filters');
8750

8851
// Get the available user groups.
8952
$groups = $this->getUserGroups();

build/media_source/com_config/joomla.asset.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,29 @@
7373
"attributes": {
7474
"type": "module"
7575
}
76+
},
77+
{
78+
"name": "com_config.filters.es5",
79+
"type": "script",
80+
"uri": "com_config/config-filters-es5.min.js",
81+
"dependencies": [
82+
"core"
83+
],
84+
"attributes": {
85+
"nomodule": true,
86+
"defer": true
87+
}
88+
},
89+
{
90+
"name": "com_config.filters",
91+
"type": "script",
92+
"uri": "com_config/config-filters.min.js",
93+
"dependencies": [
94+
"com_config.filters.es5"
95+
],
96+
"attributes": {
97+
"type": "module"
98+
}
7699
}
77100
]
78101
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
3+
* @license GNU General Public License version 2 or later; see LICENSE.txt
4+
*/
5+
const recursiveApplyChanges = (id) => {
6+
const childs = [].slice.call(document.querySelectorAll(`#filter-config select[data-parent="${id}"]`));
7+
childs.map((child) => {
8+
recursiveApplyChanges(child.dataset.id);
9+
child.value = 'NONE';
10+
return child;
11+
});
12+
};
13+
14+
const applyChanges = (event) => {
15+
const currentElement = event.currentTarget;
16+
const currentFilter = currentElement.options[currentElement.selectedIndex].value;
17+
18+
if (currentFilter === 'NONE') {
19+
const childs = [].slice.call(document.querySelectorAll(`#filter-config select[data-parent="${currentElement.dataset.id}"]`));
20+
if (childs.length && window.confirm(Joomla.Text._('COM_CONFIG_TEXT_FILTERS_NOTE'))) {
21+
childs.map((child) => {
22+
recursiveApplyChanges(child.dataset.id);
23+
child.value = 'NONE';
24+
return child;
25+
});
26+
}
27+
}
28+
};
29+
30+
[].slice.call(document.querySelectorAll('#filter-config select')).map((select) => select.addEventListener('change', applyChanges));

0 commit comments

Comments
 (0)