Prefer const/let over var

This commit is contained in:
Juanjo Diaz
2018-05-24 00:27:09 +03:00
parent cdb860ad84
commit 2b5f94fa6a
42 changed files with 1091 additions and 1131 deletions

View File

@@ -13,7 +13,7 @@ import KeyTable from "./keysym.js";
* See https://www.w3.org/TR/uievents-key/ for possible values.
*/
var DOMKeyTable = {};
const DOMKeyTable = {};
function addStandard(key, standard)
{

View File

@@ -57,7 +57,7 @@ Keyboard.prototype = {
},
_getKeyCode: function (e) {
var code = KeyboardUtil.getKeycode(e);
const code = KeyboardUtil.getKeycode(e);
if (code !== 'Unidentified') {
return code;
}
@@ -80,10 +80,8 @@ Keyboard.prototype = {
return e.keyIdentifier;
}
var codepoint = parseInt(e.keyIdentifier.substr(2), 16);
var char = String.fromCharCode(codepoint);
// Some implementations fail to uppercase the symbols
char = char.toUpperCase();
const codepoint = parseInt(e.keyIdentifier.substr(2), 16);
const char = String.fromCharCode(codepoint).toUpperCase();
return 'Platform' + char.charCodeAt();
}
@@ -92,8 +90,8 @@ Keyboard.prototype = {
},
_handleKeyDown: function (e) {
var code = this._getKeyCode(e);
var keysym = KeyboardUtil.getKeysym(e);
const code = this._getKeyCode(e);
let keysym = KeyboardUtil.getKeysym(e);
// Windows doesn't have a proper AltGr, but handles it using
// fake Ctrl+Alt. However the remote end might not be Windows,
@@ -211,8 +209,8 @@ Keyboard.prototype = {
return;
}
var code = this._getKeyCode(e);
var keysym = KeyboardUtil.getKeysym(e);
let code = this._getKeyCode(e);
const keysym = KeyboardUtil.getKeysym(e);
// The key we were waiting for?
if ((code !== 'Unidentified') && (code != this._pendingKey)) {
@@ -235,9 +233,9 @@ Keyboard.prototype = {
return;
}
var code, keysym;
let keysym;
code = this._pendingKey;
const code = this._pendingKey;
this._pendingKey = null;
// We have no way of knowing the proper keysym with the
@@ -248,7 +246,7 @@ Keyboard.prototype = {
keysym = e.keyCode;
} else if ((e.keyCode >= 0x41) && (e.keyCode <= 0x5a)) {
// Character (A-Z)
var char = String.fromCharCode(e.keyCode);
let char = String.fromCharCode(e.keyCode);
// A feeble attempt at the correct case
if (e.shiftKey)
char = char.toUpperCase();
@@ -266,7 +264,7 @@ Keyboard.prototype = {
_handleKeyUp: function (e) {
stopEvent(e);
var code = this._getKeyCode(e);
const code = this._getKeyCode(e);
// We can't get a release in the middle of an AltGr sequence, so
// abort that detection
@@ -294,7 +292,7 @@ Keyboard.prototype = {
_allKeysUp: function () {
Log.Debug(">> Keyboard.allKeysUp");
for (var code in this._keyDownList) {
for (let code in this._keyDownList) {
this._sendKeyEvent(this._keyDownList[code], code, false);
}
Log.Debug("<< Keyboard.allKeysUp");
@@ -306,14 +304,14 @@ Keyboard.prototype = {
return;
}
let target = this._target;
let downList = this._keyDownList;
const target = this._target;
const downList = this._keyDownList;
['AltLeft', 'AltRight'].forEach(function (code) {
if (!(code in downList)) {
return;
}
let event = new KeyboardEvent('keyup',
const event = new KeyboardEvent('keyup',
{ key: downList[code],
code: code });
target.dispatchEvent(event);
@@ -324,11 +322,10 @@ Keyboard.prototype = {
grab: function () {
//Log.Debug(">> Keyboard.grab");
var c = this._target;
c.addEventListener('keydown', this._eventHandlers.keydown);
c.addEventListener('keyup', this._eventHandlers.keyup);
c.addEventListener('keypress', this._eventHandlers.keypress);
this._target.addEventListener('keydown', this._eventHandlers.keydown);
this._target.addEventListener('keyup', this._eventHandlers.keyup);
this._target.addEventListener('keypress', this._eventHandlers.keypress);
// Release (key up) if window loses focus
window.addEventListener('blur', this._eventHandlers.blur);
@@ -337,7 +334,7 @@ Keyboard.prototype = {
// best we can for releases (still doesn't prevent the menu
// from popping up though as we can't call preventDefault())
if (browser.isWindows() && browser.isFirefox()) {
let handler = this._eventHandlers.checkalt;
const handler = this._eventHandlers.checkalt;
['mousedown', 'mouseup', 'mousemove', 'wheel',
'touchstart', 'touchend', 'touchmove',
'keydown', 'keyup'].forEach(function (type) {
@@ -352,10 +349,9 @@ Keyboard.prototype = {
ungrab: function () {
//Log.Debug(">> Keyboard.ungrab");
var c = this._target;
if (browser.isWindows() && browser.isFirefox()) {
let handler = this._eventHandlers.checkalt;
const handler = this._eventHandlers.checkalt;
['mousedown', 'mouseup', 'mousemove', 'wheel',
'touchstart', 'touchend', 'touchmove',
'keydown', 'keyup'].forEach(function (type) {
@@ -363,9 +359,9 @@ Keyboard.prototype = {
});
}
c.removeEventListener('keydown', this._eventHandlers.keydown);
c.removeEventListener('keyup', this._eventHandlers.keyup);
c.removeEventListener('keypress', this._eventHandlers.keypress);
this._target.removeEventListener('keydown', this._eventHandlers.keydown);
this._target.removeEventListener('keyup', this._eventHandlers.keyup);
this._target.removeEventListener('keypress', this._eventHandlers.keypress);
window.removeEventListener('blur', this._eventHandlers.blur);
// Release (key up) all keys that are in a down state

View File

@@ -7,7 +7,7 @@
/* Functions at the bottom */
var codepoints = {
const codepoints = {
0x0100: 0x03c0, // XK_Amacron
0x0101: 0x03e0, // XK_amacron
0x0102: 0x01c3, // XK_Abreve
@@ -677,7 +677,7 @@ export default {
}
// Lookup table (fairly random)
var keysym = codepoints[u];
const keysym = codepoints[u];
if (keysym !== undefined) {
return keysym;
}

View File

@@ -9,9 +9,9 @@ import * as Log from '../util/logging.js';
import { isTouchDevice } from '../util/browser.js';
import { setCapture, stopEvent, getPointerEvent } from '../util/events.js';
var WHEEL_STEP = 10; // Delta threshold for a mouse wheel step
var WHEEL_STEP_TIMEOUT = 50; // ms
var WHEEL_LINE_HEIGHT = 19;
const WHEEL_STEP = 10; // Delta threshold for a mouse wheel step
const WHEEL_STEP_TIMEOUT = 50; // ms
const WHEEL_LINE_HEIGHT = 19;
export default function Mouse(target) {
this._target = target || document;
@@ -52,9 +52,9 @@ Mouse.prototype = {
_handleMouseButton: function (e, down) {
this._updateMousePosition(e);
var pos = this._pos;
let pos = this._pos;
var bmask;
let bmask;
if (e.touches || e.changedTouches) {
// Touch device
@@ -70,13 +70,13 @@ Mouse.prototype = {
// force the position of the latter touch to the position of
// the first.
var xs = this._lastTouchPos.x - pos.x;
var ys = this._lastTouchPos.y - pos.y;
var d = Math.sqrt((xs * xs) + (ys * ys));
const xs = this._lastTouchPos.x - pos.x;
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.
var threshold = 20 * (window.devicePixelRatio || 1);
const threshold = 20 * (window.devicePixelRatio || 1);
if (d < threshold) {
pos = this._lastTouchPos;
}
@@ -156,8 +156,8 @@ Mouse.prototype = {
this._updateMousePosition(e);
var dX = e.deltaX;
var dY = e.deltaY;
let dX = e.deltaX;
let dY = e.deltaY;
// Pixel units unless it's non-zero.
// Note that if deltamode is line or page won't matter since we aren't
@@ -215,8 +215,9 @@ Mouse.prototype = {
// Update coordinates relative to target
_updateMousePosition: function(e) {
e = getPointerEvent(e);
var bounds = this._target.getBoundingClientRect();
var x, y;
const bounds = this._target.getBoundingClientRect();
let x;
let y;
// Clip to target bounds
if (e.clientX < bounds.left) {
x = 0;
@@ -238,7 +239,7 @@ Mouse.prototype = {
// ===== PUBLIC METHODS =====
grab: function () {
var c = this._target;
const c = this._target;
if (isTouchDevice) {
c.addEventListener('touchstart', this._eventHandlers.mousedown);
@@ -259,7 +260,7 @@ Mouse.prototype = {
},
ungrab: function () {
var c = this._target;
const c = this._target;
this._resetWheelStepTimers();

View File

@@ -24,7 +24,7 @@ export function getKeycode(evt){
// in the 'keyCode' field for non-printable characters. However
// Webkit sets it to the same as charCode in 'keypress' events.
if ((evt.type !== 'keypress') && (evt.keyCode in vkeys)) {
var code = vkeys[evt.keyCode];
let code = vkeys[evt.keyCode];
// macOS has messed up this code for some reason
if (browser.isMac() && (code === 'ContextMenu')) {
@@ -110,7 +110,7 @@ export function getKey(evt) {
}
// Try to deduce it based on the physical key
var code = getKeycode(evt);
const code = getKeycode(evt);
if (code in fixedkeys) {
return fixedkeys[code];
}
@@ -126,7 +126,7 @@ export function getKey(evt) {
// Get the most reliable keysym value we can get from a key event
export function getKeysym(evt){
var key = getKey(evt);
const key = getKey(evt);
if (key === 'Unidentified') {
return null;
@@ -134,7 +134,7 @@ export function getKeysym(evt){
// First look up special keys
if (key in DOMKeyTable) {
var location = evt.location;
let location = evt.location;
// Safari screws up location for the right cmd key
if ((key === 'Meta') && (location === 0)) {
@@ -150,14 +150,12 @@ export function getKeysym(evt){
// Now we need to look at the Unicode symbol instead
var codepoint;
// Special key? (FIXME: Should have been caught earlier)
if (key.length !== 1) {
return null;
}
codepoint = key.charCodeAt();
const codepoint = key.charCodeAt();
if (codepoint) {
return keysyms.lookup(codepoint);
}