mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-02-01 10:31:54 +08:00
floating windows
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
function main () {
|
||||
window.onclick = ui.windowClickHandler;
|
||||
ui.init();
|
||||
session.loadKvmdVersion();
|
||||
session.startPoller();
|
||||
stream.startPoller();
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
var ui = new function() {
|
||||
this.init = function() {
|
||||
window.onclick = __windowClickHandler;
|
||||
|
||||
Array.prototype.forEach.call(document.getElementsByClassName("window"), function(el_window) {
|
||||
var el_header = el_window.querySelector(".window-header");
|
||||
__makeWindowMovable(el_header, el_window);
|
||||
});
|
||||
};
|
||||
|
||||
this.toggleMenu = function(el_a) {
|
||||
Array.prototype.forEach.call(document.getElementsByClassName("ctl-item"), function(el_item) {
|
||||
var el_menu = el_item.parentElement.querySelector(".ctl-dropdown-content");
|
||||
@@ -12,7 +21,7 @@ var ui = new function() {
|
||||
});
|
||||
};
|
||||
|
||||
this.windowClickHandler = function(event) {
|
||||
var __windowClickHandler = function(event) {
|
||||
if (!event.target.matches(".ctl-item")) {
|
||||
for (el_item = event.target; el_item && el_item !== document; el_item = el_item.parentNode) {
|
||||
if (el_item.hasAttribute("data-force-hide-menu")) {
|
||||
@@ -25,4 +34,36 @@ var ui = new function() {
|
||||
ui.toggleMenu(null);
|
||||
}
|
||||
};
|
||||
|
||||
var __makeWindowMovable = function(el_header, el_body) {
|
||||
var prev_x = 0;
|
||||
var prev_y = 0;
|
||||
|
||||
function startMoving(event) {
|
||||
event = (event || window.event);
|
||||
event.preventDefault();
|
||||
prev_x = event.clientX;
|
||||
prev_y = event.clientY;
|
||||
document.onmousemove = doMoving;
|
||||
document.onmouseup = stopMoving;
|
||||
}
|
||||
|
||||
function doMoving(event) {
|
||||
event = (event || window.event);
|
||||
event.preventDefault();
|
||||
x = prev_x - event.clientX;
|
||||
y = prev_y - event.clientY;
|
||||
prev_x = event.clientX;
|
||||
prev_y = event.clientY;
|
||||
el_body.style.top = (el_body.offsetTop - y) + "px";
|
||||
el_body.style.left = (el_body.offsetLeft - x) + "px";
|
||||
}
|
||||
|
||||
function stopMoving() {
|
||||
document.onmousemove = null;
|
||||
document.onmouseup = null;
|
||||
}
|
||||
|
||||
el_header.onmousedown = startMoving;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user