summaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
authorAlex Yatskov <FooSoft@users.noreply.github.com>2019-09-12 19:47:37 -0700
committerGitHub <noreply@github.com>2019-09-12 19:47:37 -0700
commit1fea1184bd66ed250f8bed8218c08498a7ea81c0 (patch)
tree8374573a36784ce12abb7b490ccd9791aea3f2e3 /ext/fg/js
parentcc53510883b5c5f75069655df6a6733ff1bd002a (diff)
parent84bd9ff93b15f419ce1076b7545aeb406917f9b5 (diff)
Merge pull request #205 from toasted-nutbread/settings-improvements2
Settings improvements part 2
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/api.js20
-rw-r--r--ext/fg/js/float.js5
-rw-r--r--ext/fg/js/frontend.js28
-rw-r--r--ext/fg/js/popup-nested.js3
-rw-r--r--ext/fg/js/popup-proxy.js4
5 files changed, 37 insertions, 23 deletions
diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js
index aa3b2629..d0ac649a 100644
--- a/ext/fg/js/api.js
+++ b/ext/fg/js/api.js
@@ -17,24 +17,24 @@
*/
-function apiOptionsGet() {
- return utilInvoke('optionsGet');
+function apiOptionsGet(optionsContext) {
+ return utilInvoke('optionsGet', {optionsContext});
}
-function apiTermsFind(text) {
- return utilInvoke('termsFind', {text});
+function apiTermsFind(text, optionsContext) {
+ return utilInvoke('termsFind', {text, optionsContext});
}
-function apiKanjiFind(text) {
- return utilInvoke('kanjiFind', {text});
+function apiKanjiFind(text, optionsContext) {
+ return utilInvoke('kanjiFind', {text, optionsContext});
}
-function apiDefinitionAdd(definition, mode, context) {
- return utilInvoke('definitionAdd', {definition, mode, context});
+function apiDefinitionAdd(definition, mode, context, optionsContext) {
+ return utilInvoke('definitionAdd', {definition, mode, context, optionsContext});
}
-function apiDefinitionsAddable(definitions, modes) {
- return utilInvoke('definitionsAddable', {definitions, modes}).catch(() => null);
+function apiDefinitionsAddable(definitions, modes, optionsContext) {
+ return utilInvoke('definitionsAddable', {definitions, modes, optionsContext}).catch(() => null);
}
function apiNoteView(noteId) {
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 3c521714..348c114e 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -23,6 +23,10 @@ class DisplayFloat extends Display {
this.autoPlayAudioTimer = null;
this.styleNode = null;
+ this.optionsContext = {
+ depth: 0
+ };
+
this.dependencies = Object.assign({}, this.dependencies, {docRangeFromPoint, docSentenceExtract});
$(window).on('message', utilAsync(this.onMessage.bind(this)));
@@ -75,6 +79,7 @@ class DisplayFloat extends Display {
},
popupNestedInitialize: ({id, depth, parentFrameId}) => {
+ this.optionsContext.depth = depth;
popupNestedInitialize(id, depth, parentFrameId);
}
};
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 52620933..0b60aa2b 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -28,6 +28,10 @@ class Frontend {
this.options = null;
this.ignoreNodes = (Array.isArray(ignoreNodes) && ignoreNodes.length > 0 ? ignoreNodes.join(',') : null);
+ this.optionsContext = {
+ depth: popup.depth
+ };
+
this.primaryTouchIdentifier = null;
this.contextMenuChecking = false;
this.contextMenuPrevent = false;
@@ -40,9 +44,9 @@ class Frontend {
static create() {
const initializationData = window.frontendInitializationData;
const isNested = (initializationData !== null && typeof initializationData === 'object');
- const {id, parentFrameId, ignoreNodes} = isNested ? initializationData : {};
+ const {id, depth, parentFrameId, ignoreNodes} = isNested ? initializationData : {};
- const popup = isNested ? new PopupProxy(id, parentFrameId) : PopupProxyHost.instance.createPopup(null);
+ const popup = isNested ? new PopupProxy(depth + 1, id, parentFrameId) : PopupProxyHost.instance.createPopup(null);
const frontend = new Frontend(popup, ignoreNodes);
frontend.prepare();
return frontend;
@@ -50,7 +54,7 @@ class Frontend {
async prepare() {
try {
- this.options = await apiOptionsGet();
+ this.options = await apiOptionsGet(this.optionsContext);
window.addEventListener('message', this.onFrameMessage.bind(this));
window.addEventListener('mousedown', this.onMouseDown.bind(this));
@@ -261,11 +265,8 @@ class Frontend {
onBgMessage({action, params}, sender, callback) {
const handlers = {
- optionsSet: ({options}) => {
- this.options = options;
- if (!this.options.enable) {
- this.searchClear();
- }
+ optionsUpdate: () => {
+ this.updateOptions();
},
popupSetVisible: ({visible}) => {
@@ -284,6 +285,13 @@ class Frontend {
console.log(error);
}
+ async updateOptions() {
+ this.options = await apiOptionsGet(this.optionsContext);
+ if (!this.options.enable) {
+ this.searchClear();
+ }
+ }
+
popupTimerSet(callback) {
this.popupTimerClear();
this.popupTimer = window.setTimeout(callback, this.options.scanning.delay);
@@ -347,7 +355,7 @@ class Frontend {
return;
}
- const {definitions, length} = await apiTermsFind(searchText);
+ const {definitions, length} = await apiTermsFind(searchText, this.optionsContext);
if (definitions.length === 0) {
return false;
}
@@ -380,7 +388,7 @@ class Frontend {
return;
}
- const definitions = await apiKanjiFind(searchText);
+ const definitions = await apiKanjiFind(searchText, this.optionsContext);
if (definitions.length === 0) {
return false;
}
diff --git a/ext/fg/js/popup-nested.js b/ext/fg/js/popup-nested.js
index e0376bb2..de2acccc 100644
--- a/ext/fg/js/popup-nested.js
+++ b/ext/fg/js/popup-nested.js
@@ -25,7 +25,8 @@ async function popupNestedInitialize(id, depth, parentFrameId) {
}
popupNestedInitialized = true;
- const options = await apiOptionsGet();
+ const optionsContext = {depth};
+ const options = await apiOptionsGet(optionsContext);
const popupNestingMaxDepth = options.scanning.popupNestingMaxDepth;
if (!(typeof popupNestingMaxDepth === 'number' && typeof depth === 'number' && depth < popupNestingMaxDepth)) {
diff --git a/ext/fg/js/popup-proxy.js b/ext/fg/js/popup-proxy.js
index f6295079..56e710eb 100644
--- a/ext/fg/js/popup-proxy.js
+++ b/ext/fg/js/popup-proxy.js
@@ -18,14 +18,14 @@
class PopupProxy {
- constructor(parentId, parentFrameId) {
+ constructor(depth, parentId, parentFrameId) {
this.parentId = parentId;
this.parentFrameId = parentFrameId;
this.id = null;
this.idPromise = null;
this.parent = null;
this.child = null;
- this.depth = 0;
+ this.depth = depth;
this.container = null;