diff options
author | Samuel Mannehed <samuel@cendio.se> | 2020-05-01 19:53:36 +0200 |
---|---|---|
committer | Samuel Mannehed <samuel@cendio.se> | 2020-05-01 20:37:48 +0200 |
commit | 0f81407c641243df89aa57e23b2e16d7d020c425 (patch) | |
tree | 6d096daad5d37b441cd52d1345b653259468dc11 | |
parent | f477469fb5162c18177a0809682096ebf2e5fda2 (diff) | |
download | novnc-0f81407c641243df89aa57e23b2e16d7d020c425.tar.gz |
Shorten rows to max 80 chars in mouse.js
-rw-r--r-- | core/input/mouse.js | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/core/input/mouse.js b/core/input/mouse.js index 15a54ee..d479d5c 100644 --- a/core/input/mouse.js +++ b/core/input/mouse.js @@ -37,7 +37,8 @@ export default class Mouse { // ===== PROPERTIES ===== - this.touchButton = 1; // Button mask (1, 2, 4) for touch devices (0 means ignore clicks) + this.touchButton = 1; // Button mask (1, 2, 4) for touch devices + // (0 means ignore clicks) // ===== EVENT HANDLERS ===== @@ -75,14 +76,16 @@ export default class Mouse { const ys = this._lastTouchPos.y - pos.y; const d = Math.sqrt((xs * xs) + (ys * ys)); - // The goal is to trigger on a certain physical width, the - // devicePixelRatio brings us a bit closer but is not optimal. + // The goal is to trigger on a certain physical width, + // the devicePixelRatio brings us a bit closer but is + // not optimal. const threshold = 20 * (window.devicePixelRatio || 1); if (d < threshold) { pos = this._lastTouchPos; } } - this._doubleClickTimer = setTimeout(this._resetDoubleClickTimer.bind(this), 500); + this._doubleClickTimer = + setTimeout(this._resetDoubleClickTimer.bind(this), 500); } bmask = this.touchButton; // If bmask is set @@ -252,39 +255,42 @@ export default class Mouse { // ===== PUBLIC METHODS ===== grab() { + const t = this._target; if (isTouchDevice) { - this._target.addEventListener('touchstart', this._eventHandlers.mousedown); - this._target.addEventListener('touchend', this._eventHandlers.mouseup); - this._target.addEventListener('touchmove', this._eventHandlers.mousemove); + t.addEventListener('touchstart', this._eventHandlers.mousedown); + t.addEventListener('touchend', this._eventHandlers.mouseup); + t.addEventListener('touchmove', this._eventHandlers.mousemove); } - this._target.addEventListener('mousedown', this._eventHandlers.mousedown); - this._target.addEventListener('mouseup', this._eventHandlers.mouseup); - this._target.addEventListener('mousemove', this._eventHandlers.mousemove); - this._target.addEventListener('wheel', this._eventHandlers.mousewheel); + t.addEventListener('mousedown', this._eventHandlers.mousedown); + t.addEventListener('mouseup', this._eventHandlers.mouseup); + t.addEventListener('mousemove', this._eventHandlers.mousemove); + t.addEventListener('wheel', this._eventHandlers.mousewheel); - /* Prevent middle-click pasting (see above for why we bind to document) */ + // Prevent middle-click pasting (see above for why we bind to document) document.addEventListener('click', this._eventHandlers.mousedisable); - /* preventDefault() on mousedown doesn't stop this event for some - reason so we have to explicitly block it */ - this._target.addEventListener('contextmenu', this._eventHandlers.mousedisable); + // preventDefault() on mousedown doesn't stop this event for some + // reason so we have to explicitly block it + t.addEventListener('contextmenu', this._eventHandlers.mousedisable); } ungrab() { + const t = this._target; + this._resetWheelStepTimers(); if (isTouchDevice) { - this._target.removeEventListener('touchstart', this._eventHandlers.mousedown); - this._target.removeEventListener('touchend', this._eventHandlers.mouseup); - this._target.removeEventListener('touchmove', this._eventHandlers.mousemove); + t.removeEventListener('touchstart', this._eventHandlers.mousedown); + t.removeEventListener('touchend', this._eventHandlers.mouseup); + t.removeEventListener('touchmove', this._eventHandlers.mousemove); } - this._target.removeEventListener('mousedown', this._eventHandlers.mousedown); - this._target.removeEventListener('mouseup', this._eventHandlers.mouseup); - this._target.removeEventListener('mousemove', this._eventHandlers.mousemove); - this._target.removeEventListener('wheel', this._eventHandlers.mousewheel); + t.removeEventListener('mousedown', this._eventHandlers.mousedown); + t.removeEventListener('mouseup', this._eventHandlers.mouseup); + t.removeEventListener('mousemove', this._eventHandlers.mousemove); + t.removeEventListener('wheel', this._eventHandlers.mousewheel); document.removeEventListener('click', this._eventHandlers.mousedisable); - this._target.removeEventListener('contextmenu', this._eventHandlers.mousedisable); + t.removeEventListener('contextmenu', this._eventHandlers.mousedisable); } } |