|
1 |
| -import { getElements } from '../util'; |
| 1 | +import { getElements, toggleVisibility } from '../util'; |
2 | 2 |
|
3 | 3 | type ShowHideMap = {
|
4 | 4 | default: { hide: string[]; show: string[] };
|
@@ -62,19 +62,21 @@ const showHideMap: ShowHideMap = {
|
62 | 62 | */
|
63 | 63 | function toggleParentVisibility(query: string, action: 'show' | 'hide') {
|
64 | 64 | for (const element of getElements(query)) {
|
65 |
| - if (action === 'show') { |
66 |
| - element.parentElement?.classList.remove('d-none', 'invisible'); |
67 |
| - } else { |
68 |
| - element.parentElement?.classList.add('d-none', 'invisible'); |
| 65 | + const parent = element.parentElement?.parentElement as Nullable<HTMLDivElement>; |
| 66 | + if (parent !== null) { |
| 67 | + if (action === 'show') { |
| 68 | + toggleVisibility(parent, 'show'); |
| 69 | + } else { |
| 70 | + toggleVisibility(parent, 'hide'); |
| 71 | + } |
69 | 72 | }
|
70 | 73 | }
|
71 | 74 | }
|
72 | 75 |
|
73 | 76 | /**
|
74 | 77 | * Handle changes to the Scope Type field.
|
75 | 78 | */
|
76 |
| -function handleScopeChange(event: Event) { |
77 |
| - const element = event.currentTarget as HTMLSelectElement; |
| 79 | +function handleScopeChange(element: HTMLSelectElement) { |
78 | 80 | // Scope type's innerText looks something like `DCIM > region`.
|
79 | 81 | const scopeType = element.options[element.selectedIndex].innerText.toLowerCase();
|
80 | 82 |
|
@@ -104,6 +106,7 @@ function handleScopeChange(event: Event) {
|
104 | 106 | */
|
105 | 107 | export function initScopeSelector(): void {
|
106 | 108 | for (const element of getElements<HTMLSelectElement>('#id_scope_type')) {
|
107 |
| - element.addEventListener('change', handleScopeChange); |
| 109 | + handleScopeChange(element); |
| 110 | + element.addEventListener('change', () => handleScopeChange(element)); |
108 | 111 | }
|
109 | 112 | }
|
0 commit comments