From 3bb4b0504ef32fd62d8d57b61fa76b021cb974fa Mon Sep 17 00:00:00 2001 From: Guanghua Lu <102669562+Touch-Night@users.noreply.github.com> Date: Fri, 5 Jan 2024 00:52:11 +0800 Subject: [PATCH] Close the menu on second click. (#5110) --- js/main.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/js/main.js b/js/main.js index 59c70c73..cd7e5068 100644 --- a/js/main.js +++ b/js/main.js @@ -193,6 +193,7 @@ for (i = 0; i < slimDropdownElements.length; i++) { var buttonsInChat = document.querySelectorAll("#chat-tab:not(.old-ui) #chat-buttons button"); var button = document.getElementById("hover-element-button"); var menu = document.getElementById("hover-menu"); +var istouchscreen = (navigator.maxTouchPoints > 0) || "ontouchstart" in document.documentElement; function showMenu() { menu.style.display = "flex"; // Show the menu @@ -200,7 +201,9 @@ function showMenu() { function hideMenu() { menu.style.display = "none"; // Hide the menu - document.querySelector("#chat-input textarea").focus(); + if (!istouchscreen) { + document.querySelector("#chat-input textarea").focus(); // Focus on the chat input + } } if (buttonsInChat.length > 0) { @@ -235,11 +238,18 @@ function isMouseOverButtonOrMenu() { } button.addEventListener("mouseenter", function () { - showMenu(); + if (!istouchscreen) { + showMenu(); + } }); button.addEventListener("click", function () { + if (menu.style.display === "flex") { + hideMenu(); + } + else { showMenu(); + } }); // Add event listener for mouseleave on the button