mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
refactoring
This commit is contained in:
parent
a8773eab1e
commit
9a243eaa04
@ -12,6 +12,35 @@ function Hid() {
|
||||
var __mouse = new Mouse();
|
||||
|
||||
var __init__ = function() {
|
||||
var __hidden_attr = null;
|
||||
var __visibility_change_attr = null;
|
||||
|
||||
if (typeof document.hidden !== "undefined") {
|
||||
__hidden_attr = "hidden";
|
||||
__visibility_change_attr = "visibilitychange";
|
||||
} else if (typeof document.webkitHidden !== "undefined") {
|
||||
__hidden_attr = "webkitHidden";
|
||||
__visibility_change_attr = "webkitvisibilitychange";
|
||||
} else if (typeof document.mozHidden !== "undefined") {
|
||||
__hidden_attr = "mozHidden";
|
||||
__visibility_change_attr = "mozvisibilitychange";
|
||||
}
|
||||
|
||||
if (__visibility_change_attr) {
|
||||
document.addEventListener(
|
||||
__visibility_change_attr,
|
||||
function() {
|
||||
if (document[__hidden_attr]) {
|
||||
__releaseAll();
|
||||
}
|
||||
},
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
window.onpagehide = __releaseAll;
|
||||
window.onblur = __releaseAll;
|
||||
|
||||
if (window.navigator.clipboard && window.navigator.clipboard.readText) {
|
||||
__chars_to_codes = __buildCharsToCodes();
|
||||
$("pak-button").onclick = __pasteAsKeys;
|
||||
@ -33,12 +62,7 @@ function Hid() {
|
||||
$("pak-button").disabled = !(window.navigator.clipboard && window.navigator.clipboard.readText && ws);
|
||||
};
|
||||
|
||||
self.updateLeds = function() {
|
||||
__keyboard.updateLeds();
|
||||
__mouse.updateLeds();
|
||||
};
|
||||
|
||||
self.releaseAll = function() {
|
||||
var __releaseAll = function() {
|
||||
__keyboard.releaseAll();
|
||||
};
|
||||
|
||||
|
||||
@ -20,9 +20,13 @@ function Keyboard() {
|
||||
|
||||
$("keyboard-window").onkeydown = (event) => __keyboardHandler(event, true);
|
||||
$("keyboard-window").onkeyup = (event) => __keyboardHandler(event, false);
|
||||
$("keyboard-window").onfocus = __updateLeds;
|
||||
$("keyboard-window").onblur = __updateLeds;
|
||||
|
||||
$("stream-window").onkeydown = (event) => __keyboardHandler(event, true);
|
||||
$("stream-window").onkeyup = (event) => __keyboardHandler(event, false);
|
||||
$("stream-window").onfocus = __updateLeds;
|
||||
$("stream-window").onblur = __updateLeds;
|
||||
|
||||
Array.prototype.forEach.call($$("key"), function(el_key) {
|
||||
el_key.onmousedown = () => __clickHandler(el_key, true);
|
||||
@ -54,17 +58,7 @@ function Keyboard() {
|
||||
self.releaseAll();
|
||||
__ws = ws;
|
||||
}
|
||||
self.updateLeds();
|
||||
};
|
||||
|
||||
self.updateLeds = function() {
|
||||
if (__ws && (document.activeElement === $("stream-window") || document.activeElement === $("keyboard-window"))) {
|
||||
$("hid-keyboard-led").className = "led-on";
|
||||
$("hid-keyboard-led").title = "Keyboard captured";
|
||||
} else {
|
||||
$("hid-keyboard-led").className = "led-off";
|
||||
$("hid-keyboard-led").title = "Keyboard free";
|
||||
}
|
||||
__updateLeds();
|
||||
};
|
||||
|
||||
self.releaseAll = function() {
|
||||
@ -82,6 +76,16 @@ function Keyboard() {
|
||||
));
|
||||
};
|
||||
|
||||
var __updateLeds = function() {
|
||||
if (__ws && (document.activeElement === $("stream-window") || document.activeElement === $("keyboard-window"))) {
|
||||
$("hid-keyboard-led").className = "led-on";
|
||||
$("hid-keyboard-led").title = "Keyboard captured";
|
||||
} else {
|
||||
$("hid-keyboard-led").className = "led-off";
|
||||
$("hid-keyboard-led").title = "Keyboard free";
|
||||
}
|
||||
};
|
||||
|
||||
var __keyboardHandler = function(event, state) {
|
||||
event.preventDefault();
|
||||
var el_key = $(event.code);
|
||||
|
||||
@ -7,9 +7,8 @@ function main() {
|
||||
) {
|
||||
$("bad-browser-modal").style.visibility = "visible";
|
||||
} else {
|
||||
var hid = new Hid();
|
||||
var ui = new Ui(hid);
|
||||
new Session(new Atx(), hid, new Msd());
|
||||
var ui = new Ui();
|
||||
new Session(new Atx(), new Hid(), new Msd());
|
||||
new Stream(ui);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,17 @@ function Mouse() {
|
||||
}
|
||||
};
|
||||
|
||||
self.updateLeds = function() {
|
||||
var __hoverStream = function() {
|
||||
__stream_hovered = true;
|
||||
__updateLeds();
|
||||
};
|
||||
|
||||
var __leaveStream = function() {
|
||||
__stream_hovered = false;
|
||||
__updateLeds();
|
||||
};
|
||||
|
||||
var __updateLeds = function() {
|
||||
if (__ws && __stream_hovered) {
|
||||
$("hid-mouse-led").className = "led-on";
|
||||
$("hid-mouse-led").title = "Mouse tracked";
|
||||
@ -48,16 +58,6 @@ function Mouse() {
|
||||
}
|
||||
};
|
||||
|
||||
var __hoverStream = function() {
|
||||
__stream_hovered = true;
|
||||
self.updateLeds();
|
||||
};
|
||||
|
||||
var __leaveStream = function() {
|
||||
__stream_hovered = false;
|
||||
self.updateLeds();
|
||||
};
|
||||
|
||||
var __touchHandler = function(event, state) {
|
||||
if (state) {
|
||||
var rect = event.touches[0].target.getBoundingClientRect();
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
function Ui(hid) {
|
||||
function Ui() {
|
||||
var self = this;
|
||||
|
||||
/********************************************************************************/
|
||||
@ -26,35 +26,6 @@ function Ui(hid) {
|
||||
}
|
||||
});
|
||||
|
||||
var __hidden_attr = null;
|
||||
var __visibility_change_attr = null;
|
||||
|
||||
if (typeof document.hidden !== "undefined") {
|
||||
__hidden_attr = "hidden";
|
||||
__visibility_change_attr = "visibilitychange";
|
||||
} else if (typeof document.webkitHidden !== "undefined") {
|
||||
__hidden_attr = "webkitHidden";
|
||||
__visibility_change_attr = "webkitvisibilitychange";
|
||||
} else if (typeof document.mozHidden !== "undefined") {
|
||||
__hidden_attr = "mozHidden";
|
||||
__visibility_change_attr = "mozvisibilitychange";
|
||||
}
|
||||
|
||||
if (__visibility_change_attr) {
|
||||
document.addEventListener(
|
||||
__visibility_change_attr,
|
||||
function() {
|
||||
if (document[__hidden_attr]) {
|
||||
hid.releaseAll();
|
||||
}
|
||||
},
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
window.onpagehide = hid.releaseAll;
|
||||
window.onblur = hid.releaseAll;
|
||||
|
||||
window.onmouseup = __globalMouseButtonHandler;
|
||||
// window.oncontextmenu = __globalMouseButtonHandler;
|
||||
|
||||
@ -144,7 +115,6 @@ function Ui(hid) {
|
||||
};
|
||||
|
||||
var __globalMouseButtonHandler = function(event) {
|
||||
hid.updateLeds();
|
||||
if (!event.target.matches(".ctl-item")) {
|
||||
for (var el_item = event.target; el_item && el_item !== document; el_item = el_item.parentNode) {
|
||||
if (el_item.hasAttribute("data-force-hide-menu")) {
|
||||
@ -251,7 +221,6 @@ function Ui(hid) {
|
||||
|
||||
var __raiseWindow = function(el_window) {
|
||||
el_window.focus();
|
||||
hid.updateLeds();
|
||||
if (parseInt(el_window.style.zIndex) !== __top_z_index) {
|
||||
var z_index = __top_z_index + 1;
|
||||
el_window.style.zIndex = z_index;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user