diff options
author | Devaev Maxim <[email protected]> | 2018-12-18 23:25:23 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-12-18 23:28:08 +0300 |
commit | 3e7b5bf04908dbcf14bbeafc052bce9c51bb6b2c (patch) | |
tree | 9d7d008bb4f65769beeb2196dd7d4cae8143a169 /web | |
parent | 8867b32356d0731dfffa2687e669cb9462f206b8 (diff) |
refactoring
Diffstat (limited to 'web')
-rw-r--r-- | web/share/js/kvm/hid.js | 2 | ||||
-rw-r--r-- | web/share/js/kvm/keyboard.js | 20 | ||||
-rw-r--r-- | web/share/js/kvm/mouse.js | 2 | ||||
-rw-r--r-- | web/share/js/tools.js | 3 | ||||
-rw-r--r-- | web/share/js/wm.js | 8 |
5 files changed, 19 insertions, 16 deletions
diff --git a/web/share/js/kvm/hid.js b/web/share/js/kvm/hid.js index 49d659ab..1c60b099 100644 --- a/web/share/js/kvm/hid.js +++ b/web/share/js/kvm/hid.js @@ -46,7 +46,7 @@ function Hid() { tools.setOnClick($("hid-pak-button"), __clickPasteAsKeysButton); tools.setOnClick($("hid-reset-button"), __clickResetButton); - Array.prototype.forEach.call(document.querySelectorAll("[data-shortcut]"), function(el_shortcut) { + tools.forEach($$$("[data-shortcut]"), function(el_shortcut) { tools.setOnClick(el_shortcut, () => __emitShortcut(el_shortcut.getAttribute("data-shortcut").split(" "))); }); }; diff --git a/web/share/js/kvm/keyboard.js b/web/share/js/kvm/keyboard.js index 3c821406..c424c659 100644 --- a/web/share/js/kvm/keyboard.js +++ b/web/share/js/kvm/keyboard.js @@ -5,8 +5,8 @@ function Keyboard() { var __ws = null; - var __keys = [].slice.call(document.querySelectorAll("div#keyboard-desktop div.keyboard-block div.keyboard-row div.key")); - var __modifiers = [].slice.call(document.querySelectorAll("div#keyboard-desktop div.keyboard-block div.keyboard-row div.modifier")); + var __keys = [].slice.call($$$("div#keyboard-desktop div.keyboard-block div.keyboard-row div.key")); + var __modifiers = [].slice.call($$$("div#keyboard-desktop div.keyboard-block div.keyboard-row div.modifier")); var __init__ = function() { $("hid-keyboard-led").title = "Keyboard free"; @@ -24,7 +24,7 @@ function Keyboard() { window.addEventListener("focusin", __updateLeds); window.addEventListener("focusout", __updateLeds); - Array.prototype.forEach.call($$("key"), function(el_key) { + tools.forEach($$("key"), function(el_key) { tools.setOnDown(el_key, () => __clickHandler(el_key, true)); tools.setOnUp(el_key, () => __clickHandler(el_key, false)); el_key.onmouseout = function() { @@ -34,7 +34,7 @@ function Keyboard() { }; }); - Array.prototype.forEach.call($$("modifier"), function(el_key) { + tools.forEach($$("modifier"), function(el_key) { tools.setOnDown(el_key, () => __toggleModifierHandler(el_key)); }); @@ -134,7 +134,7 @@ function Keyboard() { var __isPressed = function(el_key) { var is_pressed = false; - Array.prototype.forEach.call(__resolveKeys(el_key), function(el_key) { + tools.forEach(__resolveKeys(el_key), function(el_key) { is_pressed = (is_pressed || el_key.classList.contains("pressed")); }); return is_pressed; @@ -142,7 +142,7 @@ function Keyboard() { var __isHolded = function(el_key) { var is_holded = false; - Array.prototype.forEach.call(__resolveKeys(el_key), function(el_key) { + tools.forEach(__resolveKeys(el_key), function(el_key) { is_holded = (is_holded || el_key.classList.contains("holded")); }); return is_holded; @@ -150,20 +150,20 @@ function Keyboard() { var __isActive = function(el_key) { var is_active = false; - Array.prototype.forEach.call(__resolveKeys(el_key), function(el_key) { + tools.forEach(__resolveKeys(el_key), function(el_key) { is_active = (is_active || el_key.classList.contains("pressed") || el_key.classList.contains("holded")); }); return is_active; }; var __activate = function(el_key, cls) { - Array.prototype.forEach.call(__resolveKeys(el_key), function(el_key) { + tools.forEach(__resolveKeys(el_key), function(el_key) { el_key.classList.add(cls); }); }; var __deactivate = function(el_key) { - Array.prototype.forEach.call(__resolveKeys(el_key), function(el_key) { + tools.forEach(__resolveKeys(el_key), function(el_key) { el_key.classList.remove("pressed"); el_key.classList.remove("holded"); }); @@ -171,7 +171,7 @@ function Keyboard() { var __resolveKeys = function(el_key) { var code = el_key.getAttribute("data-key"); - return document.querySelectorAll(`[data-key='${code}']`); + return $$$(`[data-key='${code}']`); }; var __sendKey = function(el_key, state) { diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js index 58e46d15..59b3fc73 100644 --- a/web/share/js/kvm/mouse.js +++ b/web/share/js/kvm/mouse.js @@ -23,7 +23,7 @@ function Mouse() { $("stream-box").onwheel = __wheelHandler; $("stream-box").ontouchstart = (event) => __touchMoveHandler(event); - Array.prototype.forEach.call(document.querySelectorAll("[data-mouse-button]"), function(el_button) { + tools.forEach($$$("[data-mouse-button]"), function(el_button) { var button = el_button.getAttribute("data-mouse-button"); tools.setOnDown(el_button, () => __sendButton(button, true)); tools.setOnUp(el_button, () => __sendButton(button, false)); diff --git a/web/share/js/tools.js b/web/share/js/tools.js index 80b074ee..fbd5abc6 100644 --- a/web/share/js/tools.js +++ b/web/share/js/tools.js @@ -1,6 +1,8 @@ var tools = new function() { var __debug = (new URL(window.location.href)).searchParams.get("debug"); + this.forEach = (...args) => Array.prototype.forEach.call(...args); + this.makeRequest = function(method, url, callback, body=null, content_type=null) { var http = new XMLHttpRequest(); http.open(method, url, true); @@ -134,3 +136,4 @@ var tools = new function() { var $ = (id) => document.getElementById(id); var $$ = (cls) => document.getElementsByClassName(cls); +var $$$ = (selector) => document.querySelectorAll(selector); diff --git a/web/share/js/wm.js b/web/share/js/wm.js index 5dae326d..550c7a32 100644 --- a/web/share/js/wm.js +++ b/web/share/js/wm.js @@ -8,19 +8,19 @@ function WindowManager() { var __menu_items = []; var __init__ = function() { - Array.prototype.forEach.call(document.querySelectorAll("button"), function(el_button) { + tools.forEach($$$("button"), function(el_button) { // XXX: Workaround for iOS Safari: // https://stackoverflow.com/questions/3885018/active-pseudo-class-doesnt-work-in-mobile-safari el_button.ontouchstart = function() {}; }); - Array.prototype.forEach.call($$("menu-item"), function(el_item) { + tools.forEach($$("menu-item"), function(el_item) { el_item.parentElement.querySelector(".menu-item-content").setAttribute("tabindex", "-1"); tools.setOnDown(el_item, () => __toggleMenu(el_item)); __menu_items.push(el_item); }); - Array.prototype.forEach.call($$("window"), function(el_window) { + tools.forEach($$("window"), function(el_window) { el_window.setAttribute("tabindex", "-1"); __makeWindowMovable(el_window); __windows.push(el_window); @@ -258,7 +258,7 @@ function WindowManager() { var __organizeWindowsOnResize = function(orientation) { var view = self.getViewGeometry(); - Array.prototype.forEach.call($$("window"), function(el_window) { + tools.forEach($$("window"), function(el_window) { if (el_window.style.visibility === "visible" && (orientation || el_window.hasAttribute("data-centered"))) { var rect = el_window.getBoundingClientRect(); |