OLD | NEW |
1 (function(){ | 1 (function(){ |
2 document.addEventListener("DOMContentLoaded", function() | 2 document.addEventListener("DOMContentLoaded", function() |
3 { | 3 { |
4 | 4 |
5 // Change html class name from "no-js" to "js" | 5 // Change html class name from "no-js" to "js" |
6 document.documentElement.className = "js"; | 6 document.documentElement.className = "js"; |
7 | 7 |
8 // Toggle Navbar Collapse | 8 // Toggle Navbar Collapse |
9 function toggleNavbarCollapse() | 9 function toggleNavbarCollapse() |
10 { | 10 { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 var customSelectEls = document.getElementsByClassName('custom-select-selecte
d'); | 42 var customSelectEls = document.getElementsByClassName('custom-select-selecte
d'); |
43 for (var i = 0; i < customSelectEls.length; i++) | 43 for (var i = 0; i < customSelectEls.length; i++) |
44 { | 44 { |
45 customSelectEls[i] | 45 customSelectEls[i] |
46 .addEventListener("click", onClickCustomSelect, false); | 46 .addEventListener("click", onClickCustomSelect, false); |
47 customSelectEls[i] | 47 customSelectEls[i] |
48 .nextElementSibling | 48 .nextElementSibling |
49 .setAttribute("aria-hidden", "true"); | 49 .setAttribute("aria-hidden", "true"); |
50 } | 50 } |
51 | 51 |
| 52 // Accordion menu |
| 53 |
| 54 function Accordion(accordion) |
| 55 { |
| 56 this.accordion = accordion; |
| 57 |
| 58 var accordionButtons = this.accordion.getElementsByClassName('accordion-to
ggle-button'); |
| 59 for (var i = 0; i < accordionButtons.length; i++) |
| 60 { |
| 61 // Close all sections except the first |
| 62 if (i !== 0) |
| 63 { |
| 64 accordionButtons[i].setAttribute("aria-expanded", "false"); |
| 65 document |
| 66 .getElementById( accordionButtons[i].getAttribute("aria-controls") ) |
| 67 .setAttribute("hidden", "true"); |
| 68 } |
| 69 } |
| 70 |
| 71 this.accordion |
| 72 .addEventListener("click", this._onClick.bind(this), false); |
| 73 this.accordion |
| 74 .addEventListener("keydown", this._onKeyDown.bind(this), false); |
| 75 } |
| 76 |
| 77 Accordion.prototype.toggleSection = function(clickedButton) |
| 78 { |
| 79 // Hide currently expanded section |
| 80 var expandedButton = this.accordion.querySelector("button[aria-expanded='t
rue']"); |
| 81 if (expandedButton) |
| 82 { |
| 83 expandedButton.setAttribute("aria-expanded", "false"); |
| 84 document |
| 85 .getElementById( expandedButton.getAttribute("aria-controls") ) |
| 86 .setAttribute("hidden", "true"); |
| 87 } |
| 88 |
| 89 // If currently expanded section is clicked |
| 90 if (expandedButton === clickedButton) return; |
| 91 |
| 92 // Expand new section |
| 93 clickedButton.setAttribute("aria-expanded", "true"); |
| 94 document |
| 95 .getElementById( clickedButton.getAttribute("aria-controls") ) |
| 96 .removeAttribute("hidden"); |
| 97 } |
| 98 |
| 99 Accordion.prototype.focusNextSection = function() |
| 100 { |
| 101 var currentFocus = document.activeElement; |
| 102 var nextheading = currentFocus.parentElement.nextElementSibling.nextElemen
tSibling; |
| 103 |
| 104 if (nextheading) |
| 105 { |
| 106 nextheading // .accordion-heading |
| 107 .firstElementChild // .accordion-toggle-button |
| 108 .focus(); |
| 109 } |
| 110 else |
| 111 { |
| 112 this.accordion |
| 113 .firstElementChild // .accordion-heading |
| 114 .firstElementChild // .accordion-toggle-button |
| 115 .focus(); |
| 116 } |
| 117 } |
| 118 |
| 119 Accordion.prototype.focusPrevSection = function() |
| 120 { |
| 121 var currentFocus = document.activeElement; |
| 122 var prevAccordionBody = currentFocus.parentElement.previousElementSibling; |
| 123 |
| 124 if (prevAccordionBody) |
| 125 { |
| 126 prevAccordionBody // .accordion-body |
| 127 .previousElementSibling // .accordion-heading |
| 128 .firstElementChild // .accordion-toggle-button |
| 129 .focus(); |
| 130 } |
| 131 else |
| 132 { |
| 133 this.accordion |
| 134 .lastElementChild // .accordion-body |
| 135 .previousElementSibling // .accordion-heading |
| 136 .firstElementChild // .accordion-toggle-button |
| 137 .focus(); |
| 138 } |
| 139 } |
| 140 |
| 141 Accordion.prototype._onKeyDown = function(event) |
| 142 { |
| 143 if (!event.target.classList.contains("accordion-toggle-button")) return; |
| 144 |
| 145 if (event.key == "ArrowUp" || event.keyCode == 38) |
| 146 { |
| 147 this.focusPrevSection(); |
| 148 } |
| 149 else if (event.key == "ArrowDown" || event.keyCode == 40) |
| 150 { |
| 151 this.focusNextSection(); |
| 152 } |
| 153 } |
| 154 |
| 155 Accordion.prototype._onClick = function(event) |
| 156 { |
| 157 if (!event.target.classList.contains("accordion-toggle-button")) return; |
| 158 |
| 159 this.toggleSection(event.target); |
| 160 } |
| 161 |
| 162 var accordions = document.getElementsByClassName('accordion'); |
| 163 for (var i = 0; i < accordions.length; i++) |
| 164 { |
| 165 new Accordion(accordions[i]); |
| 166 } |
| 167 |
52 }, false); | 168 }, false); |
53 }()); | 169 }()); |
OLD | NEW |