aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-23 14:09:41 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-22 20:38:21 -0500
commitf725549330e851ededad3c97c4517f8a23168e4a (patch)
tree48496d6e61b3053c33bfe560c7d370af7429acac /ext
parent14e48cf85478da1d3817be244fcdf1a28835f99b (diff)
Remove redundant window resize handler
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/settings/popup-preview-frame.js12
-rw-r--r--ext/fg/js/frontend.js7
2 files changed, 5 insertions, 14 deletions
diff --git a/ext/bg/js/settings/popup-preview-frame.js b/ext/bg/js/settings/popup-preview-frame.js
index 2b727cbd..54f246e3 100644
--- a/ext/bg/js/settings/popup-preview-frame.js
+++ b/ext/bg/js/settings/popup-preview-frame.js
@@ -35,7 +35,6 @@ class SettingsPopupPreview {
async prepare() {
// Setup events
- window.addEventListener('resize', (e) => this.onWindowResize(e), false);
window.addEventListener('message', (e) => this.onMessage(e), false);
const themeDarkCheckbox = document.querySelector('#theme-dark-checkbox');
@@ -96,16 +95,6 @@ class SettingsPopupPreview {
return result;
}
- onWindowResize() {
- if (this.frontend === null) { return; }
- const textSource = this.textSource;
- if (textSource === null) { return; }
-
- const elementRect = textSource.getRect();
- const writingMode = textSource.getWritingMode();
- this.frontend.popup.showContent(elementRect, writingMode);
- }
-
onMessage(e) {
const {action, params} = e.data;
const handler = SettingsPopupPreview._messageHandlers.get(action);
@@ -163,6 +152,7 @@ class SettingsPopupPreview {
try {
await this.frontend.onSearchSource(source, 'script');
+ this.frontend.setCurrentTextSource(source);
} finally {
source.cleanup();
}
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 2543b52c..85f1f373 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -42,6 +42,8 @@ class Frontend extends TextScanner {
try {
await this.updateOptions();
+ window.addEventListener('resize', this.onResize.bind(this), false);
+
yomichan.on('orphaned', () => this.onOrphaned());
yomichan.on('optionsUpdate', () => this.updateOptions());
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
@@ -51,7 +53,7 @@ class Frontend extends TextScanner {
}
async onResize() {
- const textSource = this.textSourceCurrent;
+ const textSource = this.getCurrentTextSource();
if (textSource !== null && await this.popup.isVisible()) {
this._showPopupContent(textSource);
}
@@ -81,8 +83,7 @@ class Frontend extends TextScanner {
getMouseEventListeners() {
return [
...super.getMouseEventListeners(),
- [window, 'message', this.onWindowMessage.bind(this)],
- [window, 'resize', this.onResize.bind(this)]
+ [window, 'message', this.onWindowMessage.bind(this)]
];
}