Index: static/js/main.js |
=================================================================== |
--- a/static/js/main.js |
+++ b/static/js/main.js |
@@ -1,16 +1,23 @@ |
(function(){ |
document.addEventListener("DOMContentLoaded", function() |
{ |
+ /************************************************************************** |
+ * General |
+ **************************************************************************/ |
+ |
// Change html class name from "no-js" to "js" |
document.documentElement.className = "js"; |
- // Toggle Navbar Collapse |
+ /************************************************************************** |
+ * Navbar |
+ **************************************************************************/ |
+ |
function toggleNavbarCollapse() |
{ |
var navbarCollapseEls = this.parentElement.getElementsByClassName("navbar-collapse"); |
for (var i = 0; i < navbarCollapseEls.length; i++) |
{ |
navbarCollapseEls[i] |
.classList.toggle("open") |
} |
@@ -18,36 +25,61 @@ |
var toggleNavbarCollapseEls = document.getElementsByClassName("toggle-navbar-collapse"); |
for (var i = 0; i < toggleNavbarCollapseEls.length; i++) |
{ |
toggleNavbarCollapseEls[i] |
.addEventListener("click", toggleNavbarCollapse, false); |
} |
- // Custom Select |
- function onClickCustomSelect() |
+ /************************************************************************** |
+ * CustomSelect |
+ **************************************************************************/ |
+ |
+ function CustomSelect(select) |
{ |
- var options = this.nextElementSibling; |
- if (options.getAttribute("aria-hidden") == "true") |
+ this.select = select; |
+ this.close(); |
+ select.addEventListener("click", this._onClick.bind(this), false); |
+ } |
+ |
+ CustomSelect.prototype._onClick = function(event) |
+ { |
+ if (event.target.classList.contains("custom-select-selected")) |
{ |
- options.removeAttribute("aria-hidden"); |
- this.setAttribute("aria-expanded", "true"); |
- } |
- else |
- { |
- options.setAttribute("aria-hidden", "true"); |
- this.setAttribute("aria-expanded", "false"); |
+ var options = this.select.querySelector(".custom-select-options"); |
+ if (options.getAttribute("aria-hidden") == "true") |
+ { |
+ this.open(); |
+ } |
+ else |
+ { |
+ this.close(); |
+ } |
} |
} |
- var customSelectEls = document.getElementsByClassName('custom-select-selected'); |
- for (var i = 0; i < customSelectEls.length; i++) |
+ CustomSelect.prototype.open = function() |
{ |
- customSelectEls[i] |
- .addEventListener("click", onClickCustomSelect, false); |
- customSelectEls[i] |
- .nextElementSibling |
+ this.select |
+ .querySelector(".custom-select-selected") |
+ .setAttribute("aria-expanded", "true"); |
+ |
+ this.select |
+ .querySelector(".custom-select-options") |
+ .removeAttribute("aria-hidden"); |
+ } |
+ |
+ CustomSelect.prototype.close = function() |
+ { |
+ this.select |
+ .querySelector(".custom-select-selected") |
+ .setAttribute("aria-expanded", "false"); |
+ |
+ this.select |
+ .querySelector(".custom-select-options") |
.setAttribute("aria-hidden", "true"); |
} |
+ |
+ new CustomSelect(document.getElementById("language-select")); |
}, false); |
}()); |