Close the menu on second click. (#5110)

This commit is contained in:
Guanghua Lu 2024-01-05 00:52:11 +08:00 committed by GitHub
parent e4d724eb3f
commit 3bb4b0504e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -193,6 +193,7 @@ for (i = 0; i < slimDropdownElements.length; i++) {
var buttonsInChat = document.querySelectorAll("#chat-tab:not(.old-ui) #chat-buttons button"); var buttonsInChat = document.querySelectorAll("#chat-tab:not(.old-ui) #chat-buttons button");
var button = document.getElementById("hover-element-button"); var button = document.getElementById("hover-element-button");
var menu = document.getElementById("hover-menu"); var menu = document.getElementById("hover-menu");
var istouchscreen = (navigator.maxTouchPoints > 0) || "ontouchstart" in document.documentElement;
function showMenu() { function showMenu() {
menu.style.display = "flex"; // Show the menu menu.style.display = "flex"; // Show the menu
@ -200,7 +201,9 @@ function showMenu() {
function hideMenu() { function hideMenu() {
menu.style.display = "none"; // Hide the menu 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) { if (buttonsInChat.length > 0) {
@ -235,11 +238,18 @@ function isMouseOverButtonOrMenu() {
} }
button.addEventListener("mouseenter", function () { button.addEventListener("mouseenter", function () {
if (!istouchscreen) {
showMenu(); showMenu();
}
}); });
button.addEventListener("click", function () { button.addEventListener("click", function () {
if (menu.style.display === "flex") {
hideMenu();
}
else {
showMenu(); showMenu();
}
}); });
// Add event listener for mouseleave on the button // Add event listener for mouseleave on the button