use setters instead of EventDispatcher
This commit is contained in:
parent
275f455e73
commit
d93e3e1a67
@ -73,8 +73,6 @@ async function main() {
|
|||||||
|
|
||||||
const isIframe = !proxy && (window !== window.parent);
|
const isIframe = !proxy && (window !== window.parent);
|
||||||
|
|
||||||
const initEventDispatcher = new EventDispatcher();
|
|
||||||
|
|
||||||
const popups = {
|
const popups = {
|
||||||
iframe: null,
|
iframe: null,
|
||||||
proxy: null,
|
proxy: null,
|
||||||
@ -99,18 +97,18 @@ async function main() {
|
|||||||
popups.normal = popup;
|
popups.normal = popup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSearchPage) {
|
|
||||||
const disabled = !options.scanning.enableOnSearchPage;
|
|
||||||
initEventDispatcher.trigger('setDisabledOverride', {disabled});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isIframe) {
|
|
||||||
initEventDispatcher.trigger('popupChange', {popup});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (frontend === null) {
|
if (frontend === null) {
|
||||||
frontend = new Frontend(popup, initEventDispatcher);
|
frontend = new Frontend(popup);
|
||||||
await frontend.prepare();
|
await frontend.prepare();
|
||||||
|
} else {
|
||||||
|
if (isSearchPage) {
|
||||||
|
const disabled = !options.scanning.enableOnSearchPage;
|
||||||
|
frontend.setDisabledOverride(disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isIframe) {
|
||||||
|
await frontend.setPopup(popup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class Frontend extends TextScanner {
|
class Frontend extends TextScanner {
|
||||||
constructor(popup, initEventDispatcher=null) {
|
constructor(popup) {
|
||||||
super(
|
super(
|
||||||
window,
|
window,
|
||||||
() => this.popup.isProxy() ? [] : [this.popup.getContainer()],
|
() => this.popup.isProxy() ? [] : [this.popup.getContainer()],
|
||||||
@ -35,7 +35,6 @@ class Frontend extends TextScanner {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.popup = popup;
|
this.popup = popup;
|
||||||
this.initEventDispatcher = initEventDispatcher;
|
|
||||||
|
|
||||||
this._disabledOverride = false;
|
this._disabledOverride = false;
|
||||||
|
|
||||||
@ -77,11 +76,6 @@ class Frontend extends TextScanner {
|
|||||||
window.visualViewport.addEventListener('resize', this.onVisualViewportResize.bind(this));
|
window.visualViewport.addEventListener('resize', this.onVisualViewportResize.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.initEventDispatcher !== null) {
|
|
||||||
this.initEventDispatcher.on('setDisabledOverride', this.onSetDisabledOverride.bind(this));
|
|
||||||
this.initEventDispatcher.on('popupChange', this.onPopupChange.bind(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
yomichan.on('orphaned', this.onOrphaned.bind(this));
|
yomichan.on('orphaned', this.onOrphaned.bind(this));
|
||||||
yomichan.on('optionsUpdated', this.updateOptions.bind(this));
|
yomichan.on('optionsUpdated', this.updateOptions.bind(this));
|
||||||
yomichan.on('zoomChanged', this.onZoomChanged.bind(this));
|
yomichan.on('zoomChanged', this.onZoomChanged.bind(this));
|
||||||
@ -142,6 +136,20 @@ class Frontend extends TextScanner {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setDisabledOverride(disabled) {
|
||||||
|
this._disabledOverride = disabled;
|
||||||
|
// other cases handed by regular options update
|
||||||
|
if (disabled && this.enabled) {
|
||||||
|
this.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async setPopup(popup) {
|
||||||
|
this.onSearchClear(true);
|
||||||
|
this.popup = popup;
|
||||||
|
await popup.setOptions(this.options);
|
||||||
|
}
|
||||||
|
|
||||||
async updateOptions() {
|
async updateOptions() {
|
||||||
this.setOptions(await apiOptionsGet(this.getOptionsContext()));
|
this.setOptions(await apiOptionsGet(this.getOptionsContext()));
|
||||||
|
|
||||||
@ -237,20 +245,6 @@ class Frontend extends TextScanner {
|
|||||||
super.onSearchClear(changeFocus);
|
super.onSearchClear(changeFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
onSetDisabledOverride({disabled}) {
|
|
||||||
this._disabledOverride = disabled;
|
|
||||||
// other cases handed by regular options update
|
|
||||||
if (disabled && this.enabled) {
|
|
||||||
this.setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async onPopupChange({popup}) {
|
|
||||||
this.onSearchClear(true);
|
|
||||||
this.popup = popup;
|
|
||||||
await popup.setOptions(this.options);
|
|
||||||
}
|
|
||||||
|
|
||||||
getOptionsContext() {
|
getOptionsContext() {
|
||||||
this.optionsContext.url = this.popup.url;
|
this.optionsContext.url = this.popup.url;
|
||||||
return this.optionsContext;
|
return this.optionsContext;
|
||||||
|
Loading…
Reference in New Issue
Block a user