diff options
author | 2019-04-14 20:00:51 +0100 | |
---|---|---|
committer | 2019-04-14 20:00:51 +0100 | |
commit | bb22b1b5c5a3989729f40267621050341807a279 (patch) | |
tree | e40bd8a5f89c00c0620778948265ae350b5ecbd6 /pydis_site/static/js/wiki | |
parent | More styling - breadcrumbs and messages (diff) |
Breadcrumb/article menu work
Diffstat (limited to 'pydis_site/static/js/wiki')
-rw-r--r-- | pydis_site/static/js/wiki/dropdown.js | 37 |
1 files changed, 37 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..55b2e9fc --- /dev/null +++ b/pydis_site/static/js/wiki/dropdown.js @@ -0,0 +1,37 @@ +// TODO: Move to django-simple-bulma + +(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; + } +})(); |