diff options
author | Devaev Maxim <[email protected]> | 2018-07-22 17:23:33 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-07-22 17:23:33 +0300 |
commit | c462aedad902c57f7bd679f2da48c072652297c4 (patch) | |
tree | 36e84245c4effe7c8e40199b63ec84a831756006 /kvmd/web/js/ui.js | |
parent | 41576d7f62e40ccf5455fba3fa13d45ed5363ab1 (diff) |
smart menubar
Diffstat (limited to 'kvmd/web/js/ui.js')
-rw-r--r-- | kvmd/web/js/ui.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/kvmd/web/js/ui.js b/kvmd/web/js/ui.js new file mode 100644 index 00000000..60fcf70f --- /dev/null +++ b/kvmd/web/js/ui.js @@ -0,0 +1,28 @@ +var ui = new function() { + this.toggleMenu = function(el_a) { + Array.prototype.forEach.call(document.getElementsByClassName("ctl-item"), function(el_item) { + var el_menu = el_item.parentElement.querySelector(".ctl-dropdown-content"); + if (el_item === el_a && el_menu.style.display === "none") { + el_menu.style.display = "block"; + el_item.setAttribute("style", "background-color: var(--bg-color-selected)"); + } else { + el_menu.style.display = "none"; + el_item.setAttribute("style", "background-color: default"); + } + }); + }; + + this.windowClickHandler = function(event) { + if (!event.target.matches(".ctl-item")) { + for (el_item = event.target; el_item && el_item !== document; el_item = el_item.parentNode) { + if (el_item.hasAttribute("data-force-hide-menu")) { + break; + } + else if (el_item.hasAttribute("data-dont-hide-menu")) { + return; + } + } + ui.toggleMenu(null); + } + }; +}; |