mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2025-01-27 04:23:21 +01:00
UI: close sidebars by clicking outside their areas on mobile
This commit is contained in:
parent
636a6621cc
commit
0a15cff6a0
36
js/main.js
36
js/main.js
@ -344,6 +344,21 @@ document.addEventListener("click", function (event) {
|
|||||||
if (event.target.classList.contains("pfp_character")) {
|
if (event.target.classList.contains("pfp_character")) {
|
||||||
toggleBigPicture();
|
toggleBigPicture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle sidebar clicks on mobile
|
||||||
|
if (isMobile()) {
|
||||||
|
// Check if the click did NOT originate from any of the specified toggle buttons or elements
|
||||||
|
if (
|
||||||
|
target.closest("#navigation-toggle") !== navigationToggle &&
|
||||||
|
target.closest("#past-chats-toggle") !== pastChatsToggle &&
|
||||||
|
target.closest("#chat-controls-toggle") !== chatControlsToggle &&
|
||||||
|
target.closest(".header_bar") !== headerBar &&
|
||||||
|
target.closest("#past-chats-row") !== pastChatsRow &&
|
||||||
|
target.closest("#chat-controls") !== chatControlsRow
|
||||||
|
) {
|
||||||
|
handleIndividualSidebarClose(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//------------------------------------------------
|
//------------------------------------------------
|
||||||
@ -656,7 +671,26 @@ headerBar.appendChild(navigationToggle);
|
|||||||
const pastChatsToggle = document.getElementById("past-chats-toggle");
|
const pastChatsToggle = document.getElementById("past-chats-toggle");
|
||||||
const chatControlsToggle = document.getElementById("chat-controls-toggle");
|
const chatControlsToggle = document.getElementById("chat-controls-toggle");
|
||||||
|
|
||||||
function toggleSidebar(sidebar, toggle) {
|
function handleIndividualSidebarClose(event) {
|
||||||
|
const target = event.target;
|
||||||
|
|
||||||
|
// Close navigation bar if click is outside and it is open
|
||||||
|
if (!headerBar.contains(target) && !headerBar.classList.contains("sidebar-hidden")) {
|
||||||
|
toggleSidebar(headerBar, navigationToggle, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close past chats row if click is outside and it is open
|
||||||
|
if (!pastChatsRow.contains(target) && !pastChatsRow.classList.contains("sidebar-hidden")) {
|
||||||
|
toggleSidebar(pastChatsRow, pastChatsToggle, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close chat controls row if click is outside and it is open
|
||||||
|
if (!chatControlsRow.contains(target) && !chatControlsRow.classList.contains("sidebar-hidden")) {
|
||||||
|
toggleSidebar(chatControlsRow, chatControlsToggle, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleSidebar(sidebar, toggle, forceClose = false) {
|
||||||
const isCurrentlyHidden = sidebar.classList.contains("sidebar-hidden");
|
const isCurrentlyHidden = sidebar.classList.contains("sidebar-hidden");
|
||||||
const shouldClose = !isCurrentlyHidden;
|
const shouldClose = !isCurrentlyHidden;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user