summaryrefslogtreecommitdiff
path: root/kvmd/web/js/hid.js
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-08-27 13:33:15 +0300
committerDevaev Maxim <[email protected]>2018-08-27 13:33:15 +0300
commit9a243eaa0402aebc61cd7a247a04b57bd8ec0ad3 (patch)
tree7fb8b66ac413ad516b517542cacb4895e41b8710 /kvmd/web/js/hid.js
parenta8773eab1e8f82a7bd862492e5520dcb9690a5e0 (diff)
refactoring
Diffstat (limited to 'kvmd/web/js/hid.js')
-rw-r--r--kvmd/web/js/hid.js36
1 files changed, 30 insertions, 6 deletions
diff --git a/kvmd/web/js/hid.js b/kvmd/web/js/hid.js
index eef503d1..50bbd5e7 100644
--- a/kvmd/web/js/hid.js
+++ b/kvmd/web/js/hid.js
@@ -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();
};