| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 (function(){ | 1 (function(){ |
| 2 document.addEventListener("DOMContentLoaded", function() | 2 document.addEventListener("DOMContentLoaded", function() |
| 3 { | 3 { |
| 4 | 4 |
| 5 /* ****************************************** | |
|
ire
2017/10/04 08:07:40
The document was starting to get really long so I
juliandoucette
2017/10/09 23:14:15
Acknowledged.
We should be consistent about how w
ire
2017/10/10 11:54:18
I think I actually prefer your way so updating tha
| |
| 6 * | |
| 7 * General | |
| 8 * | |
| 9 * ****************************************** */ | |
| 10 | |
| 5 // Change html class name from "no-js" to "js" | 11 // Change html class name from "no-js" to "js" |
| 6 document.documentElement.className = "js"; | 12 document.documentElement.className = "js"; |
| 7 | 13 |
| 8 // Toggle Navbar Collapse | 14 /* ****************************************** |
| 15 * | |
| 16 * Navbar | |
| 17 * | |
| 18 * ****************************************** */ | |
| 19 | |
| 9 function toggleNavbarCollapse() | 20 function toggleNavbarCollapse() |
| 10 { | 21 { |
| 11 var navbarCollapseEls = this.parentElement.getElementsByClassName("navbar- collapse"); | 22 var navbarCollapseEls = this.parentElement.getElementsByClassName("navbar- collapse"); |
| 12 for (var i = 0; i < navbarCollapseEls.length; i++) | 23 for (var i = 0; i < navbarCollapseEls.length; i++) |
| 13 { | 24 { |
| 14 navbarCollapseEls[i] | 25 navbarCollapseEls[i] |
| 15 .classList.toggle("open") | 26 .classList.toggle("open") |
| 16 } | 27 } |
| 17 } | 28 } |
| 18 | 29 |
| 19 var toggleNavbarCollapseEls = document.getElementsByClassName("toggle-navbar -collapse"); | 30 var toggleNavbarCollapseEls = document.getElementsByClassName("toggle-navbar -collapse"); |
| 20 for (var i = 0; i < toggleNavbarCollapseEls.length; i++) | 31 for (var i = 0; i < toggleNavbarCollapseEls.length; i++) |
| 21 { | 32 { |
| 22 toggleNavbarCollapseEls[i] | 33 toggleNavbarCollapseEls[i] |
| 23 .addEventListener("click", toggleNavbarCollapse, false); | 34 .addEventListener("click", toggleNavbarCollapse, false); |
| 24 } | 35 } |
| 25 | 36 |
| 26 // Custom Select | 37 /* ****************************************** |
| 27 function onClickCustomSelect() | 38 * |
| 39 * CustomSelect | |
| 40 * | |
| 41 * ****************************************** */ | |
| 42 | |
| 43 function CustomSelect(select) | |
| 28 { | 44 { |
| 29 var options = this.nextElementSibling; | 45 this.select = select; |
| 30 if (options.getAttribute("aria-hidden") == "true") | 46 this.close(); |
| 47 select.addEventListener("click", this._onClick.bind(this), false); | |
| 48 } | |
| 49 | |
| 50 CustomSelect.prototype._onClick = function(event) | |
| 51 { | |
| 52 if (event.target.classList.contains("custom-select-selected")) | |
| 31 { | 53 { |
| 32 options.removeAttribute("aria-hidden"); | 54 var options = this.select.querySelector(".custom-select-options"); |
| 33 this.setAttribute("aria-expanded", "true"); | 55 if (options.getAttribute("aria-hidden") == "true") |
| 34 } | 56 { |
| 35 else | 57 this.open(); |
| 36 { | 58 } |
| 37 options.setAttribute("aria-hidden", "true"); | 59 else |
| 38 this.setAttribute("aria-expanded", "false"); | 60 { |
| 61 this.close(); | |
| 62 } | |
| 39 } | 63 } |
| 40 } | 64 } |
| 41 | 65 |
| 42 var customSelectEls = document.getElementsByClassName('custom-select-selecte d'); | 66 CustomSelect.prototype.open = function() |
| 43 for (var i = 0; i < customSelectEls.length; i++) | |
| 44 { | 67 { |
| 45 customSelectEls[i] | 68 this.select |
| 46 .addEventListener("click", onClickCustomSelect, false); | 69 .querySelector(".custom-select-selected") |
| 47 customSelectEls[i] | 70 .setAttribute("aria-expanded", "true"); |
| 48 .nextElementSibling | 71 |
| 72 this.select | |
| 73 .querySelector(".custom-select-options") | |
| 74 .removeAttribute("aria-hidden"); | |
| 75 } | |
| 76 | |
| 77 CustomSelect.prototype.close = function() | |
| 78 { | |
| 79 this.select | |
| 80 .querySelector(".custom-select-selected") | |
| 81 .setAttribute("aria-expanded", "false"); | |
| 82 | |
| 83 this.select | |
| 84 .querySelector(".custom-select-options") | |
| 49 .setAttribute("aria-hidden", "true"); | 85 .setAttribute("aria-hidden", "true"); |
| 50 } | 86 } |
| 87 | |
| 88 new CustomSelect(document.getElementById("language-select")); | |
| 51 | 89 |
| 52 }, false); | 90 }, false); |
| 53 }()); | 91 }()); |
| OLD | NEW |