From 1936bcde37d2b45be87a77117da0375c0fe8592f Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 10 Aug 2024 11:18:52 -0700 Subject: [PATCH] Dropdown menus to open up near bottom of the page --- web/static/js/bulma.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/web/static/js/bulma.js b/web/static/js/bulma.js index 5558eeb..bd2d65a 100644 --- a/web/static/js/bulma.js +++ b/web/static/js/bulma.js @@ -1,4 +1,4 @@ -// Hamburger menu script for mobile. +// Bulma CSS fixes and features for nonshy. document.addEventListener('DOMContentLoaded', () => { // Make all off-site hyperlinks open in a new tab. @@ -84,6 +84,19 @@ document.addEventListener('DOMContentLoaded', () => { // Dropdown menus. (document.querySelectorAll(".dropdown") || []).forEach(node => { + // If this dropdown is near the bottom of the page, make it open upwards. + if (!node.classList.contains("is-up") && !node.classList.contains("is-right")) { + let offsetTop = node.offsetTop, + body = document.body, + html = document.documentElement, + pageHeight = Math.max(body.scrollHeight, body.offsetHeight, + html.clientHeight, html.scrollHeight, html.offsetHeight, + ); + if (pageHeight - offsetTop < 450) { + node.classList.add("is-up"); + } + } + const button = node.querySelector("button"); button.addEventListener("click", (e) => { node.classList.toggle("is-active");