diff options
author | siikamiika <siikamiika@users.noreply.github.com> | 2019-11-03 18:03:35 +0200 |
---|---|---|
committer | siikamiika <siikamiika@users.noreply.github.com> | 2019-11-23 17:45:44 +0200 |
commit | 515345ba0a9844ff55518779f799e4cf2a003d62 (patch) | |
tree | eaad2ce23e37df6932ccde4dabfcc72a2799b424 /ext | |
parent | b0c924d4bdaa0a606a6b559701047283ec0ff1db (diff) |
remove code duplication
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/js/search-query-parser.js | 40 |
1 files changed, 5 insertions, 35 deletions
diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js index 60b94ca8..1cf00425 100644 --- a/ext/bg/js/search-query-parser.js +++ b/ext/bg/js/search-query-parser.js @@ -34,7 +34,7 @@ class QueryParser { } onMouseDown(e) { - if (QueryParser.isMouseButton('primary', e)) { + if (Frontend.isMouseButton('primary', e)) { this.clickScanPrevent = false; } } @@ -43,7 +43,7 @@ class QueryParser { if ( this.search.options.scanning.clickGlossary && !this.clickScanPrevent && - QueryParser.isMouseButton('primary', e) + Frontend.isMouseButton('primary', e) ) { const selectText = this.search.options.scanning.selectText; this.onTermLookup(e, {disableScroll: true, selectText}); @@ -51,18 +51,15 @@ class QueryParser { } onMouseMove(e) { - if ( - this.pendingLookup || - QueryParser.isMouseButton('primary', e) - ) { + if (this.pendingLookup || Frontend.isMouseButton('primary', e)) { return; } const scanningOptions = this.search.options.scanning; const scanningModifier = scanningOptions.modifier; if (!( - QueryParser.isScanningModifierPressed(scanningModifier, e) || - (scanningOptions.middleMouse && QueryParser.isMouseButton('auxiliary', e)) + Frontend.isScanningModifierPressed(scanningModifier, e) || + (scanningOptions.middleMouse && Frontend.isMouseButton('auxiliary', e)) )) { return; } @@ -162,31 +159,4 @@ class QueryParser { } return results; } - - static isScanningModifierPressed(scanningModifier, mouseEvent) { - switch (scanningModifier) { - case 'alt': return mouseEvent.altKey; - case 'ctrl': return mouseEvent.ctrlKey; - case 'shift': return mouseEvent.shiftKey; - case 'none': return true; - default: return false; - } - } - - static isMouseButton(button, mouseEvent) { - if (['mouseup', 'mousedown'].includes(mouseEvent.type)) { - switch (button) { - case 'primary': return mouseEvent.button === 0; - case 'secondary': return mouseEvent.button === 2; - case 'auxiliary': return mouseEvent.button === 1; - default: return false; - } - } - switch (button) { - case 'primary': return (mouseEvent.buttons & 0x1) !== 0x0; - case 'secondary': return (mouseEvent.buttons & 0x2) !== 0x0; - case 'auxiliary': return (mouseEvent.buttons & 0x4) !== 0x0; - default: return false; - } - } } |