From c6314709ef4da86a21af0cfbc36f4b40176217c4 Mon Sep 17 00:00:00 2001 From: bluesaxman Date: Tue, 20 Dec 2022 11:38:41 -0700 Subject: [PATCH] Added focusing windows on click, only effects draggable windows --- css/css.css | 2 +- libs/blueui.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/css/css.css b/css/css.css index f6c30db..abd2de2 100644 --- a/css/css.css +++ b/css/css.css @@ -82,6 +82,6 @@ body > .bui_window_root { cursor: pointer; } -.active_window { +.focus_window { z-index: 1000; } diff --git a/libs/blueui.js b/libs/blueui.js index 0427217..9887cc0 100644 --- a/libs/blueui.js +++ b/libs/blueui.js @@ -99,6 +99,11 @@ function makeResizeable (targetNode, handleNode) { } } +function focus_window (window_element) { + var old_focus = Array.from(document.getElementsByClassName("focus_window")); + old_focus.forEach(e => e.classList.remove("focus_window")); + window_element.classList.add("focus_window"); +} class buiWindow { constructor (title="", height=100, width=100, min=false, close=true, draggable=true, sizeable=true) { @@ -113,6 +118,7 @@ class buiWindow { draggable = "boolean" == typeof draggable ? draggable : true; if (draggable) { makeDraggable(this.root, this.titlebar); + this.root.addEventListener("click", this.focus, {useCapture: true}); } min = "boolean" == typeof min ? min : false; close = "boolean" == typeof close ? close : false; @@ -147,6 +153,8 @@ class buiWindow { this.root.appendChild(this.main); } + focus () { focus_window(this); } + minimize () { var current = this.content.style.display == "none" ? "revert" : "none"; this.content.style.display = current;