aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-23 13:58:33 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-22 20:38:21 -0500
commit14e48cf85478da1d3817be244fcdf1a28835f99b (patch)
treebfdf2b3ee7b20cb9d86aade9729a215a6c17bc0b
parent8ef57936d7ab25c723d4da2d655b742cdcf8c84a (diff)
Create single function for how the frontend shows popup content
-rw-r--r--ext/fg/js/frontend.js26
1 files changed, 14 insertions, 12 deletions
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 9621ed2b..2543b52c 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -53,10 +53,7 @@ class Frontend extends TextScanner {
async onResize() {
const textSource = this.textSourceCurrent;
if (textSource !== null && await this.popup.isVisible()) {
- this._lastShowPromise = this.popup.showContent(
- textSource.getRect(),
- textSource.getWritingMode()
- );
+ this._showPopupContent(textSource);
}
}
@@ -111,11 +108,7 @@ class Frontend extends TextScanner {
} catch (e) {
if (this._orphaned) {
if (textSource !== null && this.options.scanning.modifier !== 'none') {
- this._lastShowPromise = this.popup.showContent(
- textSource.getRect(),
- textSource.getWritingMode(),
- 'orphaned'
- );
+ this._showPopupContent(textSource, 'orphaned');
}
} else {
this.onError(e);
@@ -132,9 +125,8 @@ class Frontend extends TextScanner {
showContent(textSource, focus, definitions, type) {
const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
const url = window.location.href;
- this._lastShowPromise = this.popup.showContent(
- textSource.getRect(),
- textSource.getWritingMode(),
+ this._showPopupContent(
+ textSource,
type,
{definitions, context: {sentence, url, focus, disableHistory: true}}
);
@@ -180,6 +172,16 @@ class Frontend extends TextScanner {
this.optionsContext.url = this.popup.url;
return this.optionsContext;
}
+
+ _showPopupContent(textSource, type=null, details=null) {
+ this._lastShowPromise = this.popup.showContent(
+ textSource.getRect(),
+ textSource.getWritingMode(),
+ type,
+ details
+ );
+ return this._lastShowPromise;
+ }
}
Frontend._windowMessageHandlers = new Map([