Display refactor (#643)
* Remove statics * Move orphan detection and error handling to Display * Add clearContent function * Add/use public get/set functions for optionsContext * Add public getOptions * Move interactive assignment * Mark fields as private * Mark functions as private * Change stray getter into a function
This commit is contained in:
parent
6ede83f293
commit
e36bc8771f
@ -33,10 +33,10 @@ class DisplaySearch extends Display {
|
|||||||
|
|
||||||
this._isPrepared = false;
|
this._isPrepared = false;
|
||||||
|
|
||||||
this.optionsContext = {
|
this.setOptionsContext({
|
||||||
depth: 0,
|
depth: 0,
|
||||||
url: window.location.href
|
url: window.location.href
|
||||||
};
|
});
|
||||||
|
|
||||||
this.queryParser = new QueryParser({
|
this.queryParser = new QueryParser({
|
||||||
getOptionsContext: this.getOptionsContext.bind(this),
|
getOptionsContext: this.getOptionsContext.bind(this),
|
||||||
@ -80,12 +80,13 @@ class DisplaySearch extends Display {
|
|||||||
await this.updateOptions();
|
await this.updateOptions();
|
||||||
yomichan.on('optionsUpdated', () => this.updateOptions());
|
yomichan.on('optionsUpdated', () => this.updateOptions());
|
||||||
await this.queryParser.prepare();
|
await this.queryParser.prepare();
|
||||||
|
const options = this.getOptions();
|
||||||
|
|
||||||
const {queryParams: {query='', mode=''}} = parseUrl(window.location.href);
|
const {queryParams: {query='', mode=''}} = parseUrl(window.location.href);
|
||||||
|
|
||||||
document.documentElement.dataset.searchMode = mode;
|
document.documentElement.dataset.searchMode = mode;
|
||||||
|
|
||||||
if (this.options.general.enableWanakana === true) {
|
if (options.general.enableWanakana === true) {
|
||||||
this.wanakanaEnable.checked = true;
|
this.wanakanaEnable.checked = true;
|
||||||
wanakana.bind(this.query);
|
wanakana.bind(this.query);
|
||||||
} else {
|
} else {
|
||||||
@ -96,7 +97,7 @@ class DisplaySearch extends Display {
|
|||||||
this.onSearchQueryUpdated(this.query.value, false);
|
this.onSearchQueryUpdated(this.query.value, false);
|
||||||
|
|
||||||
if (mode !== 'popup') {
|
if (mode !== 'popup') {
|
||||||
if (this.options.general.enableClipboardMonitor === true) {
|
if (options.general.enableClipboardMonitor === true) {
|
||||||
this.clipboardMonitorEnable.checked = true;
|
this.clipboardMonitorEnable.checked = true;
|
||||||
this.clipboardMonitor.start();
|
this.clipboardMonitor.start();
|
||||||
} else {
|
} else {
|
||||||
@ -121,10 +122,6 @@ class DisplaySearch extends Display {
|
|||||||
this._isPrepared = true;
|
this._isPrepared = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onError(error) {
|
|
||||||
yomichan.logError(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
onEscape() {
|
onEscape() {
|
||||||
if (this.query === null) {
|
if (this.query === null) {
|
||||||
return;
|
return;
|
||||||
@ -241,7 +238,7 @@ class DisplaySearch extends Display {
|
|||||||
url: window.location.href
|
url: window.location.href
|
||||||
}});
|
}});
|
||||||
} else {
|
} else {
|
||||||
this.container.textContent = '';
|
this.clearContent();
|
||||||
}
|
}
|
||||||
this.setTitleText(query);
|
this.setTitleText(query);
|
||||||
window.parent.postMessage('popupClose', '*');
|
window.parent.postMessage('popupClose', '*');
|
||||||
@ -299,7 +296,8 @@ class DisplaySearch extends Display {
|
|||||||
|
|
||||||
async updateOptions() {
|
async updateOptions() {
|
||||||
await super.updateOptions();
|
await super.updateOptions();
|
||||||
this.queryParser.setOptions(this.options);
|
const options = this.getOptions();
|
||||||
|
this.queryParser.setOptions(options);
|
||||||
if (!this._isPrepared) { return; }
|
if (!this._isPrepared) { return; }
|
||||||
const query = this.query.value;
|
const query = this.query.value;
|
||||||
if (query) {
|
if (query) {
|
||||||
|
@ -31,7 +31,6 @@ class DisplayFloat extends Display {
|
|||||||
this._secret = yomichan.generateId(16);
|
this._secret = yomichan.generateId(16);
|
||||||
this._token = null;
|
this._token = null;
|
||||||
|
|
||||||
this._orphaned = false;
|
|
||||||
this._nestedPopupsPrepared = false;
|
this._nestedPopupsPrepared = false;
|
||||||
|
|
||||||
this._onKeyDownHandlers = new Map([
|
this._onKeyDownHandlers = new Map([
|
||||||
@ -59,24 +58,11 @@ class DisplayFloat extends Display {
|
|||||||
async prepare() {
|
async prepare() {
|
||||||
await super.prepare();
|
await super.prepare();
|
||||||
|
|
||||||
yomichan.on('orphaned', this.onOrphaned.bind(this));
|
|
||||||
window.addEventListener('message', this.onMessage.bind(this), false);
|
window.addEventListener('message', this.onMessage.bind(this), false);
|
||||||
|
|
||||||
api.broadcastTab('popupPrepared', {secret: this._secret});
|
api.broadcastTab('popupPrepared', {secret: this._secret});
|
||||||
}
|
}
|
||||||
|
|
||||||
onError(error) {
|
|
||||||
if (this._orphaned) {
|
|
||||||
this.setContent('orphaned');
|
|
||||||
} else {
|
|
||||||
yomichan.logError(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onOrphaned() {
|
|
||||||
this._orphaned = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
onEscape() {
|
onEscape() {
|
||||||
window.parent.postMessage('popupClose', '*');
|
window.parent.postMessage('popupClose', '*');
|
||||||
}
|
}
|
||||||
@ -126,7 +112,7 @@ class DisplayFloat extends Display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setOptionsContext(optionsContext) {
|
async setOptionsContext(optionsContext) {
|
||||||
this.optionsContext = optionsContext;
|
super.setOptionsContext(optionsContext);
|
||||||
await this.updateOptions();
|
await this.updateOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +167,7 @@ class DisplayFloat extends Display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _configure({messageId, frameId, popupId, optionsContext, childrenSupported, scale}) {
|
async _configure({messageId, frameId, popupId, optionsContext, childrenSupported, scale}) {
|
||||||
this.optionsContext = optionsContext;
|
this.setOptionsContext(optionsContext);
|
||||||
|
|
||||||
await this.updateOptions();
|
await this.updateOptions();
|
||||||
|
|
||||||
@ -208,7 +194,7 @@ class DisplayFloat extends Display {
|
|||||||
let complete = false;
|
let complete = false;
|
||||||
|
|
||||||
const onOptionsUpdated = async () => {
|
const onOptionsUpdated = async () => {
|
||||||
const optionsContext = this.optionsContext;
|
const optionsContext = this.getOptionsContext();
|
||||||
const options = await api.optionsGet(optionsContext);
|
const options = await api.optionsGet(optionsContext);
|
||||||
const maxPopupDepthExceeded = !(typeof depth === 'number' && depth < options.scanning.popupNestingMaxDepth);
|
const maxPopupDepthExceeded = !(typeof depth === 'number' && depth < options.scanning.popupNestingMaxDepth);
|
||||||
if (maxPopupDepthExceeded || complete) { return; }
|
if (maxPopupDepthExceeded || complete) { return; }
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user