From 4110a848f5107c697e09c014d3488360fc8219ef Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 18:52:05 -0500 Subject: Move additional utility functions to DOM --- ext/mixed/js/display.js | 4 ++-- ext/mixed/js/dom.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'ext/mixed') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index cbf8efb7..854418f4 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -85,7 +85,7 @@ class Display { } onGlossaryMouseDown(e) { - if (Frontend.isMouseButtonPressed('primary', e)) { + if (DOM.isMouseButtonPressed(e, 'primary')) { this.clickScanPrevent = false; } } @@ -95,7 +95,7 @@ class Display { } onGlossaryMouseUp(e) { - if (!this.clickScanPrevent && Frontend.isMouseButtonPressed('primary', e)) { + if (!this.clickScanPrevent && DOM.isMouseButtonPressed(e, 'primary')) { this.onTermLookup(e); } } diff --git a/ext/mixed/js/dom.js b/ext/mixed/js/dom.js index 4525dace..4e4d49e3 100644 --- a/ext/mixed/js/dom.js +++ b/ext/mixed/js/dom.js @@ -43,4 +43,24 @@ class DOM { } return false; } + + static isMouseButtonPressed(mouseEvent, button) { + const mouseEventButton = mouseEvent.button; + switch (button) { + case 'primary': return mouseEventButton === 0; + case 'secondary': return mouseEventButton === 2; + case 'auxiliary': return mouseEventButton === 1; + default: return false; + } + } + + static isMouseButtonDown(mouseEvent, button) { + const mouseEventButtons = mouseEvent.buttons; + switch (button) { + case 'primary': return (mouseEventButtons & 0x1) !== 0x0; + case 'secondary': return (mouseEventButtons & 0x2) !== 0x0; + case 'auxiliary': return (mouseEventButtons & 0x4) !== 0x0; + default: return false; + } + } } -- cgit v1.2.3