From 7d2ca3c07f347a819cd7e56134c9201aac9ff238 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 21 Oct 2023 13:16:19 +0200 Subject: toolbar menus: Click to open, click anywhere or leave window to close. --- public/common/client.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'public') diff --git a/public/common/client.js b/public/common/client.js index 2d6e94d..8168250 100644 --- a/public/common/client.js +++ b/public/common/client.js @@ -769,13 +769,30 @@ function close_menus(self) { } for (let node of document.querySelectorAll("#toolbar > details")) { - node.onclick = function () { close_menus(node) } - node.onmouseleave = function () { node.removeAttribute("open") } + //node.onclick = function () { close_menus(node) } + //node.onmouseleave = function () { node.removeAttribute("open") } } + +/* close menu after selecting something */ for (let node of document.querySelectorAll("#toolbar > details > menu")) { node.onclick = function () { close_menus(null) } } +/* click anywhere else than menu to close it */ +window.addEventListener("mousedown", function (evt) { + let e = evt.target + while (e) { + if (e.tagName === "DETAILS") + return + e = e.parentElement + } + close_menus(null) +}) + +window.addEventListener("blur", function (evt) { + close_menus(null) +}) + function toggle_fullscreen() { // Safari on iPhone doesn't support Fullscreen if (typeof document.documentElement.requestFullscreen !== "function") -- cgit v1.2.3