aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2019-11-05 19:04:13 -0800
committerAlex Yatskov <alex@foosoft.net>2019-11-05 19:04:13 -0800
commit08ad2779678cd447bd747c2b155ef9b5135fdf5d (patch)
treefaa54cbf9176989f9bd3c3b90ff3e032189adb20 /ext/mixed
parent438498435227cfa59cf9ed3430045b288cd2a7c0 (diff)
parent91c01e0a7eeeb851344a22ace8a5fa0b873a3e57 (diff)
Merge branch 'master' into testing
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/js/display.js23
-rw-r--r--ext/mixed/js/extension.js38
2 files changed, 60 insertions, 1 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index b40228b0..6d992897 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -35,6 +35,7 @@ class Display {
this.persistentEventListeners = [];
this.interactive = false;
this.eventListenersActive = false;
+ this.clickScanPrevent = false;
this.windowScroll = new WindowScroll();
@@ -81,6 +82,22 @@ class Display {
}
}
+ onGlossaryMouseDown(e) {
+ if (Frontend.isMouseButton('primary', e)) {
+ this.clickScanPrevent = false;
+ }
+ }
+
+ onGlossaryMouseMove(e) {
+ this.clickScanPrevent = true;
+ }
+
+ onGlossaryMouseUp(e) {
+ if (!this.clickScanPrevent && Frontend.isMouseButton('primary', e)) {
+ this.onTermLookup(e);
+ }
+ }
+
async onTermLookup(e) {
try {
e.preventDefault();
@@ -157,8 +174,10 @@ class Display {
const handler = handlers[key];
if (handler(this, e)) {
e.preventDefault();
+ return true;
}
}
+ return false;
}
onWheel(e) {
@@ -250,7 +269,9 @@ class Display {
this.addEventListeners('.kanji-link', 'click', this.onKanjiLookup.bind(this));
this.addEventListeners('.source-term', 'click', this.onSourceTermView.bind(this));
if (this.options.scanning.enablePopupSearch) {
- this.addEventListeners('.glossary-item', 'click', this.onTermLookup.bind(this));
+ this.addEventListeners('.glossary-item', 'mouseup', this.onGlossaryMouseUp.bind(this));
+ this.addEventListeners('.glossary-item', 'mousedown', this.onGlossaryMouseDown.bind(this));
+ this.addEventListeners('.glossary-item', 'mousemove', this.onGlossaryMouseMove.bind(this));
}
} else {
Display.clearEventListeners(this.eventListeners);
diff --git a/ext/mixed/js/extension.js b/ext/mixed/js/extension.js
index 861e52a5..54862e19 100644
--- a/ext/mixed/js/extension.js
+++ b/ext/mixed/js/extension.js
@@ -95,3 +95,41 @@ if (EXTENSION_IS_BROWSER_EDGE) {
// Edge does not have chrome defined.
chrome = browser;
}
+
+function promiseTimeout(delay, resolveValue) {
+ if (delay <= 0) {
+ return Promise.resolve(resolveValue);
+ }
+
+ let timer = null;
+ let promiseResolve = null;
+ let promiseReject = null;
+
+ const complete = (callback, value) => {
+ if (callback === null) { return; }
+ if (timer !== null) {
+ window.clearTimeout(timer);
+ timer = null;
+ }
+ promiseResolve = null;
+ promiseReject = null;
+ callback(value);
+ };
+
+ const resolve = (value) => complete(promiseResolve, value);
+ const reject = (value) => complete(promiseReject, value);
+
+ const promise = new Promise((resolve, reject) => {
+ promiseResolve = resolve;
+ promiseReject = reject;
+ });
+ timer = window.setTimeout(() => {
+ timer = null;
+ resolve(resolveValue);
+ }, delay);
+
+ promise.resolve = resolve;
+ promise.reject = reject;
+
+ return promise;
+}