diff options
Diffstat (limited to 'pydis_site/static/js/wiki/dropdown.js')
-rw-r--r-- | pydis_site/static/js/wiki/dropdown.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/pydis_site/static/js/wiki/dropdown.js b/pydis_site/static/js/wiki/dropdown.js new file mode 100644 index 00000000..a914a4ab --- /dev/null +++ b/pydis_site/static/js/wiki/dropdown.js @@ -0,0 +1,35 @@ +(function() { + window.dropdowns = {}; + + let elements = document.getElementsByClassName("dropdown"); + + for (let element of elements) { + let menu_element = element.getElementsByClassName("dropdown-menu")[0]; + + function show() { + $(element).addClass("is-active"); + } + + function hide() { + $(element).removeClass("is-active"); + } + + function handle_event(e) { + show(); + + $(document.body).on("click." + menu_element.id, function() { + hide(); + + $(document.body).off("click." + menu_element.id); + }); + + e.stopPropagation(); + } + + $(element).click(handle_event); + $(element).hover(handle_event); + $(element).mouseleave(hide); + + window.dropdowns[menu_element.id] = element; + } +})(); |