summaryrefslogtreecommitdiff
path: root/kvmd/web/js/ui.js
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-07-31 21:57:20 +0300
committerDevaev Maxim <[email protected]>2018-07-31 21:57:20 +0300
commit3a748859ffd961552f272f751c7329e3021ac375 (patch)
tree964ab8d98ea14f642f95bf5384a83a0580fdd2ee /kvmd/web/js/ui.js
parent89fca2752093c8f4ec42b7c869b0e72cc3eee7f5 (diff)
js-based windows centering
Diffstat (limited to 'kvmd/web/js/ui.js')
-rw-r--r--kvmd/web/js/ui.js42
1 files changed, 23 insertions, 19 deletions
diff --git a/kvmd/web/js/ui.js b/kvmd/web/js/ui.js
index 088a7253..c0b07198 100644
--- a/kvmd/web/js/ui.js
+++ b/kvmd/web/js/ui.js
@@ -12,16 +12,13 @@ var ui = new function() {
Array.prototype.forEach.call(document.getElementsByClassName("window"), function(el_window) {
var el_grab = el_window.querySelector(".window-header .window-grab");
- el_window.style.display = window.getComputedStyle(el_window, null).display;
- el_window.style.zIndex = parseInt(window.getComputedStyle(el_window, null).zIndex);
-
__makeWindowMovable(el_grab, el_window);
__windows.push(el_window);
var el_button = el_window.querySelector(".window-header .window-button-close");
if (el_button) {
el_button.onclick = function() {
- el_window.style.display = "none";
+ el_window.style.visibility = "hidden";
__raiseLastWindow();
};
}
@@ -56,35 +53,42 @@ var ui = new function() {
window.onmouseup = __globalMouseButtonHandler;
// window.oncontextmenu = __globalMouseButtonHandler;
- __raiseWindow($("stream-window"));
+ ui.showWindow("stream-window");
};
this.showWindow = function(id) {
var el_window = $(id);
if (!__isWindowOnPage(el_window)) {
- el_window.style.top = "50%";
- el_window.style.left = "50%";
+ var view = __getViewGeometry();
+ var rect = el_window.getBoundingClientRect();
+ el_window.style.top = Math.max($("ctl").clientHeight, Math.round((view.bottom - rect.height) / 2)) + "px";
+ el_window.style.left = Math.round((view.right - rect.width) / 2) + "px";
}
- el_window.style.display = "block";
+ el_window.style.visibility = "visible";
__raiseWindow(el_window);
};
var __isWindowOnPage = function(el_window) {
- var view_top = $("ctl").clientHeight;
- var view_bottom = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
- var view_left = 0;
- var view_right = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
-
+ var view = __getViewGeometry();
var rect = el_window.getBoundingClientRect();
return (
- (rect.bottom - el_window.clientHeight / 1.5) <= view_bottom
- && rect.top >= view_top
- && (rect.left + el_window.clientWidth / 1.5) >= view_left
- && (rect.right - el_window.clientWidth / 1.5) <= view_right
+ (rect.bottom - el_window.clientHeight / 1.5) <= view.bottom
+ && rect.top >= view.top
+ && (rect.left + el_window.clientWidth / 1.5) >= view.left
+ && (rect.right - el_window.clientWidth / 1.5) <= view.right
);
};
+ var __getViewGeometry = function() {
+ return {
+ top: $("ctl").clientHeight,
+ bottom: Math.max(document.documentElement.clientHeight, window.innerHeight || 0),
+ left: 0,
+ right: Math.max(document.documentElement.clientWidth, window.innerWidth || 0),
+ };
+ };
+
var __toggleMenu = function(el_a) {
var all_hidden = true;
@@ -178,8 +182,8 @@ var ui = new function() {
var last_el_window = null;
var max_z_index = 0;
__windows.forEach(function(el_window) {
- z_index = parseInt(el_window.style.zIndex);
- if (max_z_index < z_index && el_window.style.display !== "none") {
+ z_index = parseInt(window.getComputedStyle(el_window, null).zIndex);
+ if (max_z_index < z_index && window.getComputedStyle(el_window, null).visibility !== "hidden") {
last_el_window = el_window;
max_z_index = z_index;
}