mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 01:30:31 +08:00
minor js fixes
This commit is contained in:
parent
52bf4f38e4
commit
211401b52c
@ -5,11 +5,20 @@ var atx = new function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.clearLeds = function() {
|
this.clearLeds = function() {
|
||||||
atx.setLedsState(false, false);
|
[
|
||||||
|
"atx-power-led",
|
||||||
|
"atx-hdd-led",
|
||||||
|
].forEach(function(name) {
|
||||||
|
$(name).className = "led-off";
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.clickButton = function(el_button) {
|
this.clickButton = function(el) {
|
||||||
switch (el_button.id) {
|
var button = null;
|
||||||
|
var confirm_msg = null;
|
||||||
|
var timeout = null;
|
||||||
|
|
||||||
|
switch (el.id) {
|
||||||
case "atx-power-button":
|
case "atx-power-button":
|
||||||
var button = "power";
|
var button = "power";
|
||||||
var confirm_msg = "Are you sure to click the power button?";
|
var confirm_msg = "Are you sure to click the power button?";
|
||||||
@ -17,15 +26,12 @@ var atx = new function() {
|
|||||||
case "atx-power-button-long":
|
case "atx-power-button-long":
|
||||||
var button = "power_long";
|
var button = "power_long";
|
||||||
var confirm_msg = "Are you sure to perform the long press of the power button?";
|
var confirm_msg = "Are you sure to perform the long press of the power button?";
|
||||||
|
var timeout = 15000;
|
||||||
break;
|
break;
|
||||||
case "atx-reset-button":
|
case "atx-reset-button":
|
||||||
var button = "reset";
|
var button = "reset";
|
||||||
var confirm_msg = "Are you sure to reboot the server?";
|
var confirm_msg = "Are you sure to reboot the server?";
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
var button = null;
|
|
||||||
var confirm_msg = null;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (button && confirm(confirm_msg)) {
|
if (button && confirm(confirm_msg)) {
|
||||||
@ -39,7 +45,7 @@ var atx = new function() {
|
|||||||
}
|
}
|
||||||
__setButtonsBusy(false);
|
__setButtonsBusy(false);
|
||||||
}
|
}
|
||||||
});
|
}, timeout);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -35,9 +35,9 @@ var mouse = new function() {
|
|||||||
var __buttonHandler = function(ws, event, state) {
|
var __buttonHandler = function(ws, event, state) {
|
||||||
// https://www.w3schools.com/jsref/event_button.asp
|
// https://www.w3schools.com/jsref/event_button.asp
|
||||||
switch (event.button) {
|
switch (event.button) {
|
||||||
case 0: var button = "Left"; break;
|
case 0: var button = "left"; break;
|
||||||
case 2: var button = "Right"; break;
|
case 2: var button = "right"; break;
|
||||||
default: var button = null; break
|
default: var button = null; break;
|
||||||
}
|
}
|
||||||
if (button) {
|
if (button) {
|
||||||
tools.debug("Mouse button", (state ? "pressed:" : "released:"), button);
|
tools.debug("Mouse button", (state ? "pressed:" : "released:"), button);
|
||||||
|
|||||||
@ -32,8 +32,11 @@ var session = new function() {
|
|||||||
|
|
||||||
var __wsErrorHandler = function(event) {
|
var __wsErrorHandler = function(event) {
|
||||||
tools.error("WebSocket error:", event);
|
tools.error("WebSocket error:", event);
|
||||||
__ws.close();
|
if (__ws) {
|
||||||
__ws = null;
|
__ws.onclose = null;
|
||||||
|
__ws.close();
|
||||||
|
__wsCloseHandler(null);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var __wsCloseHandler = function(event) {
|
var __wsCloseHandler = function(event) {
|
||||||
@ -44,6 +47,7 @@ var session = new function() {
|
|||||||
}
|
}
|
||||||
hid.clearCapture();
|
hid.clearCapture();
|
||||||
atx.clearLeds();
|
atx.clearLeds();
|
||||||
|
__ws = null;
|
||||||
setTimeout(session.startPoller, 1000);
|
setTimeout(session.startPoller, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57,8 +61,9 @@ var session = new function() {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
tools.error("Ping error:", err.message);
|
tools.error("Ping error:", err.message);
|
||||||
if (__ws) {
|
if (__ws) {
|
||||||
|
__ws.onclose = null;
|
||||||
__ws.close();
|
__ws.close();
|
||||||
__ws = null;
|
__wsCloseHandler(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
var tools = new function() {
|
var tools = new function() {
|
||||||
this.makeRequest = function(method, url, callback) {
|
this.makeRequest = function(method, url, callback, timeout=null) {
|
||||||
var http = new XMLHttpRequest();
|
var http = new XMLHttpRequest();
|
||||||
http.open(method, url, true)
|
http.open(method, url, true)
|
||||||
http.onreadystatechange = callback;
|
http.onreadystatechange = callback;
|
||||||
|
http.timeout = timeout ? timeout : 5000;
|
||||||
http.send();
|
http.send();
|
||||||
return http;
|
return http;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user