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 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