Move additional utility functions to DOM

This commit is contained in:
toasted-nutbread 2019-11-26 18:52:05 -05:00
parent 96aad50340
commit 4110a848f5
4 changed files with 28 additions and 39 deletions

View File

@ -38,7 +38,7 @@ class QueryParser {
}
onMouseDown(e) {
if (Frontend.isMouseButton('primary', e)) {
if (DOM.isMouseButtonPressed(e, 'primary')) {
this.clickScanPrevent = false;
}
}
@ -47,7 +47,7 @@ class QueryParser {
if (
this.search.options.scanning.clickGlossary &&
!this.clickScanPrevent &&
Frontend.isMouseButton('primary', e)
DOM.isMouseButtonPressed(e, 'primary')
) {
const selectText = this.search.options.scanning.selectText;
this.onTermLookup(e, {disableScroll: true, selectText});
@ -55,7 +55,7 @@ class QueryParser {
}
onMouseMove(e) {
if (this.pendingLookup || Frontend.isMouseButton('primary', e)) {
if (this.pendingLookup || DOM.isMouseButtonDown(e, 'primary')) {
return;
}
@ -63,7 +63,7 @@ class QueryParser {
const scanningModifier = scanningOptions.modifier;
if (!(
Frontend.isScanningModifierPressed(scanningModifier, e) ||
(scanningOptions.middleMouse && Frontend.isMouseButton('auxiliary', e))
(scanningOptions.middleMouse && DOM.isMouseButtonDown(e, 'auxiliary'))
)) {
return;
}

View File

@ -80,7 +80,7 @@ class Frontend {
onMouseMove(e) {
this.popupTimerClear();
if (this.pendingLookup || Frontend.isMouseButtonDown('primary', e)) {
if (this.pendingLookup || DOM.isMouseButtonDown(e, 'primary')) {
return;
}
@ -88,7 +88,7 @@ class Frontend {
const scanningModifier = scanningOptions.modifier;
if (!(
Frontend.isScanningModifierPressed(scanningModifier, e) ||
(scanningOptions.middleMouse && Frontend.isMouseButtonDown('auxiliary', e))
(scanningOptions.middleMouse && DOM.isMouseButtonDown(e, 'auxiliary'))
)) {
return;
}
@ -487,37 +487,6 @@ class Frontend {
default: return false;
}
}
static isMouseButton(button, mouseEvent) {
switch (mouseEvent.type) {
case 'mouseup':
case 'mousedown':
case 'click':
return Frontend.isMouseButtonPressed(button, mouseEvent);
default:
return Frontend.isMouseButtonDown(button, mouseEvent);
}
}
static isMouseButtonPressed(button, mouseEvent) {
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(button, mouseEvent) {
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;
}
}
}
Frontend.windowMessageHandlers = {

View File

@ -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);
}
}

View File

@ -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;
}
}
}