]> git.proxmox.com Git - mirror_novnc.git/blobdiff - core/util/events.js
Use fat arrow functions `const foo = () => { ... };` for callbacks
[mirror_novnc.git] / core / util / events.js
index c1afb48a3100bf527fb1d1ef6da7b3a5e6abd72e..a0eddc71f2a2148c7f906bfb003b0a1654070ae9 100644 (file)
  * Cross-browser event and position routines
  */
 
-import * as Log from './logging.js';
-
 export function getPointerEvent (e) {
     return e.changedTouches ? e.changedTouches[0] : e.touches ? e.touches[0] : e;
-};
+}
 
 export function stopEvent (e) {
     e.stopPropagation();
     e.preventDefault();
-};
+}
 
 // Emulate Element.setCapture() when not supported
-var _captureRecursion = false;
-var _captureElem = null;
+let _captureRecursion = false;
+let _captureElem = null;
 function _captureProxy(e) {
     // Recursion protection as we'll see our own event
     if (_captureRecursion) return;
 
     // Clone the event as we cannot dispatch an already dispatched event
-    var newEv = new e.constructor(e.type, e);
+    const newEv = new e.constructor(e.type, e);
 
     _captureRecursion = true;
     _captureElem.dispatchEvent(newEv);
@@ -47,16 +45,17 @@ function _captureProxy(e) {
     if (e.type === "mouseup") {
         releaseCapture();
     }
-};
+}
 
 // Follow cursor style of target element
 function _captureElemChanged() {
-    var captureElem = document.getElementById("noVNC_mouse_capture_elem");
+    const captureElem = document.getElementById("noVNC_mouse_capture_elem");
     captureElem.style.cursor = window.getComputedStyle(_captureElem).cursor;
-};
-var _captureObserver = new MutationObserver(_captureElemChanged);
+}
+
+const _captureObserver = new MutationObserver(_captureElemChanged);
 
-var _captureIndex = 0;
+let _captureIndex = 0;
 
 export function setCapture (elem) {
     if (elem.setCapture) {
@@ -71,7 +70,7 @@ export function setCapture (elem) {
         // called multiple times without coordination
         releaseCapture();
 
-        var captureElem = document.getElementById("noVNC_mouse_capture_elem");
+        let captureElem = document.getElementById("noVNC_mouse_capture_elem");
 
         if (captureElem === null) {
             captureElem = document.createElement("div");
@@ -107,7 +106,7 @@ export function setCapture (elem) {
         window.addEventListener('mousemove', _captureProxy);
         window.addEventListener('mouseup', _captureProxy);
     }
-};
+}
 
 export function releaseCapture () {
     if (document.releaseCapture) {
@@ -121,7 +120,7 @@ export function releaseCapture () {
 
         // There might be events already queued, so we need to wait for
         // them to flush. E.g. contextmenu in Microsoft Edge
-        window.setTimeout(function(expected) {
+        window.setTimeout((expected) => {
             // Only clear it if it's the expected grab (i.e. no one
             // else has initiated a new grab)
             if (_captureIndex === expected) {
@@ -131,10 +130,10 @@ export function releaseCapture () {
 
         _captureObserver.disconnect();
 
-        var captureElem = document.getElementById("noVNC_mouse_capture_elem");
+        const captureElem = document.getElementById("noVNC_mouse_capture_elem");
         captureElem.style.display = "none";
 
         window.removeEventListener('mousemove', _captureProxy);
         window.removeEventListener('mouseup', _captureProxy);
     }
-};
+}