hawk / files / public / js / collapsible.js
collapsible.js
| 1 | var coll = document.getElementsByClassName("collapsible"); |
| 2 | var i; |
| 3 | |
| 4 | for (i = 0; i < coll.length; i++) { |
| 5 | const item = coll[i]; |
| 6 | if (item.classList.contains("active")) { |
| 7 | const content = item.nextElementSibling; |
| 8 | content.style.maxHeight = content.scrollHeight + "px"; |
| 9 | item.after = "▼" |
| 10 | } |
| 11 | item.addEventListener("click", function () { |
| 12 | this.classList.toggle("active"); |
| 13 | var content = this.nextElementSibling; |
| 14 | if (content.style.maxHeight) { |
| 15 | content.style.maxHeight = null; |
| 16 | item.after = "▶" |
| 17 | } else { |
| 18 | content.style.maxHeight = content.scrollHeight + "px"; |
| 19 | item.after = "▼" |
| 20 | } |
| 21 | }); |
| 22 | } |