-
Notifications
You must be signed in to change notification settings - Fork 6
/
high-school-search.js
64 lines (58 loc) · 2.05 KB
/
high-school-search.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(function (Drupal) {
Drupal.behaviors.HighSchoolSearch = {};
Drupal.behaviors.HighSchoolSearch.attach = function (context) {
// Find all select elements inside high school search.
const selectElements = context.querySelectorAll(
'.unit-search--high-school .js-form-item-emphasis .form-select, ' +
'.unit-search--high-school .js-form-item-mission .form-select'
);
selectElements.forEach(
function(select) {
disableOtherSelects(select, selectElements);
}
);
for (let select of selectElements) {
select.addEventListener('change', function (){
disableOtherSelects(this, selectElements);
});
}
};
// Set attributes based on if the select should be disabled or not.
function toggleSelectActivity(select, disabled) {
const helpText = select.nextElementSibling;
if (disabled) {
helpText.textContent = Drupal.t(
'Filter on the form has been selected and some of the other ' +
'filters might be dimmed because of your selection. To use the ' +
'filters that were dimmed select the option All on the selected ' +
'filter.'
);
select.parentElement.classList.add('hdbt--select-wrapper--disabled');
select.disabled = true;
select.setAttribute('aria-disabled', 'true');
} else {
helpText.textContent = '';
select.parentElement.classList.remove(
'hdbt--select-wrapper--disabled'
);
select.disabled = false;
select.setAttribute('aria-disabled', 'false');
}
}
// Disable all other selects except the one that has some OTHER option selected
// than 'All' and enable them all if they all have 'All' option selected.
function disableOtherSelects(selected, selectElements) {
if (selected.value !== 'All') {
for (let select of selectElements) {
toggleSelectActivity(select, select !== selected);
}
}
else {
for (let select of selectElements) {
if (select !== selected) {
toggleSelectActivity(select, false);
}
}
}
}
})(Drupal);