toggle windows

This commit is contained in:
2026-01-21 09:09:57 +01:00
parent dc2f11514c
commit 439b192c43
2 changed files with 47 additions and 4 deletions
+12 -3
View File
@@ -28,10 +28,19 @@ const global_chat = new GlobalChat();
// Actions UI
document.getElementById("login").addEventListener("click", () => {
loginWindow.show();
// Toggle login window visibility
if (loginWindow.main && loginWindow.main.style.display !== "none") {
loginWindow.hide();
} else {
loginWindow.show();
}
});
document.getElementById("global_chat").addEventListener("click", () => {
console.log("showing");
// Toggle global chat visibility
if (global_chat.main && global_chat.main.style.display !== "none") {
global_chat.hide();
} else {
global_chat.show();
});
}
});
+35 -1
View File
@@ -12,6 +12,8 @@ export class fenetre {
this.main.style.color = "white";
this.main.style.zIndex = "100";
this.main.style.display = "none";
// Mark windows for layout management (side-by-side when multiple open)
this.main.classList.add("trans-window");
// Header
this.header = document.createElement("div");
@@ -38,11 +40,43 @@ export class fenetre {
}
show() {
// If no other windows are open, center this window
const openWindows = Array.from(document.querySelectorAll(".trans-window"))
.filter(el => el.style.display !== "none");
if (openWindows.length === 0) {
this.main.style.left = "50%";
this.main.style.top = "50%";
this.main.style.transform = "translate(-50%, -50%)";
} else if (openWindows.length === 1) {
// Layout two windows side-by-side: left and right
const other = openWindows[0];
other.style.left = "15%";
other.style.top = "50%";
other.style.transform = "translate(-50%, -50%)";
this.main.style.left = "65%";
this.main.style.top = "50%";
this.main.style.transform = "translate(-50%, -50%)";
} else {
// Fallback: center if more than two windows are open
this.main.style.left = "50%";
this.main.style.top = "50%";
this.main.style.transform = "translate(-50%, -50%)";
}
this.main.style.display = "block";
}
hide() {
this.main.style.display = "none";
// If only one window remains visible, center it
const visibles = Array.from(document.querySelectorAll(".trans-window"))
.filter(el => el.style.display !== "none");
if (visibles.length === 1) {
const w = visibles[0];
w.style.left = "50%";
w.style.top = "50%";
w.style.transform = "translate(-50%, -50%)";
}
}
}