aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/static/js/wiki
diff options
context:
space:
mode:
Diffstat (limited to 'pydis_site/static/js/wiki')
-rw-r--r--pydis_site/static/js/wiki/dropdown.js37
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;
+ }
+})();