Remove redundant window resize handler
This commit is contained in:
parent
14e48cf854
commit
f725549330
@ -35,7 +35,6 @@ class SettingsPopupPreview {
|
|||||||
|
|
||||||
async prepare() {
|
async prepare() {
|
||||||
// Setup events
|
// Setup events
|
||||||
window.addEventListener('resize', (e) => this.onWindowResize(e), false);
|
|
||||||
window.addEventListener('message', (e) => this.onMessage(e), false);
|
window.addEventListener('message', (e) => this.onMessage(e), false);
|
||||||
|
|
||||||
const themeDarkCheckbox = document.querySelector('#theme-dark-checkbox');
|
const themeDarkCheckbox = document.querySelector('#theme-dark-checkbox');
|
||||||
@ -96,16 +95,6 @@ class SettingsPopupPreview {
|
|||||||
return result;
|
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) {
|
onMessage(e) {
|
||||||
const {action, params} = e.data;
|
const {action, params} = e.data;
|
||||||
const handler = SettingsPopupPreview._messageHandlers.get(action);
|
const handler = SettingsPopupPreview._messageHandlers.get(action);
|
||||||
@ -163,6 +152,7 @@ class SettingsPopupPreview {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await this.frontend.onSearchSource(source, 'script');
|
await this.frontend.onSearchSource(source, 'script');
|
||||||
|
this.frontend.setCurrentTextSource(source);
|
||||||
} finally {
|
} finally {
|
||||||
source.cleanup();
|
source.cleanup();
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,8 @@ class Frontend extends TextScanner {
|
|||||||
try {
|
try {
|
||||||
await this.updateOptions();
|
await this.updateOptions();
|
||||||
|
|
||||||
|
window.addEventListener('resize', this.onResize.bind(this), false);
|
||||||
|
|
||||||
yomichan.on('orphaned', () => this.onOrphaned());
|
yomichan.on('orphaned', () => this.onOrphaned());
|
||||||
yomichan.on('optionsUpdate', () => this.updateOptions());
|
yomichan.on('optionsUpdate', () => this.updateOptions());
|
||||||
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
|
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
|
||||||
@ -51,7 +53,7 @@ class Frontend extends TextScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onResize() {
|
async onResize() {
|
||||||
const textSource = this.textSourceCurrent;
|
const textSource = this.getCurrentTextSource();
|
||||||
if (textSource !== null && await this.popup.isVisible()) {
|
if (textSource !== null && await this.popup.isVisible()) {
|
||||||
this._showPopupContent(textSource);
|
this._showPopupContent(textSource);
|
||||||
}
|
}
|
||||||
@ -81,8 +83,7 @@ class Frontend extends TextScanner {
|
|||||||
getMouseEventListeners() {
|
getMouseEventListeners() {
|
||||||
return [
|
return [
|
||||||
...super.getMouseEventListeners(),
|
...super.getMouseEventListeners(),
|
||||||
[window, 'message', this.onWindowMessage.bind(this)],
|
[window, 'message', this.onWindowMessage.bind(this)]
|
||||||
[window, 'resize', this.onResize.bind(this)]
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user