|
9 | 9 | * @param {String} toggleClass The class name of the DIVs to toggle display for |
10 | 10 | */ |
11 | 11 | Joomla.toggleInlineHelp = (toggleClass) => { |
12 | | - [].slice.call(document.querySelectorAll(`div.${toggleClass}`)) |
13 | | - .forEach((elDiv) => { |
14 | | - // Toggle the visibility of the node by toggling the 'd-none' Bootstrap class. |
15 | | - elDiv.classList.toggle('d-none'); |
16 | | - // The ID of the description whose visibility is toggled. |
17 | | - const myId = elDiv.id; |
18 | | - // The ID of the control described by this node (same ID, minus the '-desc' suffix). |
19 | | - const controlId = myId ? myId.substring(0, myId.length - 5) : null; |
20 | | - // Get the control described by this node. |
21 | | - const elControl = controlId ? document.getElementById(controlId) : null; |
22 | | - // Is this node hidden? |
23 | | - const isHidden = elDiv.classList.contains('d-none'); |
| 12 | + document.querySelectorAll(`div.${toggleClass}`).forEach((elDiv) => { |
| 13 | + // Toggle the visibility of the node by toggling the 'd-none' Bootstrap class. |
| 14 | + elDiv.classList.toggle('d-none'); |
| 15 | + // The ID of the description whose visibility is toggled. |
| 16 | + const myId = elDiv.id; |
| 17 | + // The ID of the control described by this node (same ID, minus the '-desc' suffix). |
| 18 | + const controlId = myId ? myId.substring(0, myId.length - 5) : null; |
| 19 | + // Get the control described by this node. |
| 20 | + const elControl = controlId ? document.getElementById(controlId) : null; |
| 21 | + // Is this node hidden? |
| 22 | + const isHidden = elDiv.classList.contains('d-none'); |
24 | 23 |
|
25 | | - // If we do not have a control we will exit early |
26 | | - if (!controlId || !elControl) { |
27 | | - return; |
28 | | - } |
| 24 | + // If we do not have a control we will exit early |
| 25 | + if (!controlId || !elControl) { |
| 26 | + return; |
| 27 | + } |
29 | 28 |
|
30 | | - // Unset the aria-describedby attribute in the control when the description is hidden and vice–versa. |
31 | | - if (isHidden && elControl.hasAttribute('aria-describedby')) { |
32 | | - elControl.removeAttribute('aria-describedby'); |
33 | | - } else if (!isHidden) { |
34 | | - elControl.setAttribute('aria-describedby', myId); |
35 | | - } |
36 | | - }); |
| 29 | + // Unset the aria-describedby attribute in the control when the description is hidden and vice–versa. |
| 30 | + if (isHidden && elControl.hasAttribute('aria-describedby')) { |
| 31 | + elControl.removeAttribute('aria-describedby'); |
| 32 | + } else if (!isHidden) { |
| 33 | + elControl.setAttribute('aria-describedby', myId); |
| 34 | + } |
| 35 | + }); |
37 | 36 | }; |
38 | 37 |
|
39 | 38 | // Initialisation. Clicking on anything with the button-inlinehelp class will toggle the inline help. |
40 | | -[].slice.call(document.querySelectorAll('.button-inlinehelp')) |
41 | | - .forEach((elToggler) => { |
42 | | - // The class of the DIVs to toggle visibility on is defined by the data-class attribute of the click target. |
43 | | - const toggleClass = elToggler.dataset.class ?? 'hide-aware-inline-help'; |
44 | | - const collection = document.getElementsByClassName(toggleClass); |
| 39 | +document.querySelectorAll('.button-inlinehelp').forEach((elToggler) => { |
| 40 | + // The class of the DIVs to toggle visibility on is defined by the data-class attribute of the click target. |
| 41 | + const toggleClass = elToggler.dataset.class ?? 'hide-aware-inline-help'; |
| 42 | + const collection = document.getElementsByClassName(toggleClass); |
45 | 43 |
|
46 | | - // no description => hide inlinehelp button |
47 | | - if (collection.length === 0) { |
48 | | - elToggler.classList.add('d-none'); |
49 | | - return; |
50 | | - } |
| 44 | + // no description => hide inlinehelp button |
| 45 | + if (collection.length === 0) { |
| 46 | + elToggler.classList.add('d-none'); |
| 47 | + return; |
| 48 | + } |
51 | 49 |
|
52 | | - // Add the click handler. |
53 | | - elToggler.addEventListener('click', (event) => { |
54 | | - event.preventDefault(); |
55 | | - Joomla.toggleInlineHelp(toggleClass); |
56 | | - }); |
| 50 | + // Add the click handler. |
| 51 | + elToggler.addEventListener('click', (event) => { |
| 52 | + event.preventDefault(); |
| 53 | + Joomla.toggleInlineHelp(toggleClass); |
57 | 54 | }); |
| 55 | +}); |
0 commit comments