Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Display refactor #643

Merged
merged 9 commits into from
Jul 3, 2020
18 changes: 8 additions & 10 deletions ext/bg/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class DisplaySearch extends Display {

this._isPrepared = false;

this.optionsContext = {
this.setOptionsContext({
depth: 0,
url: window.location.href
};
});

this.queryParser = new QueryParser({
getOptionsContext: this.getOptionsContext.bind(this),
Expand Down Expand Up @@ -80,12 +80,13 @@ class DisplaySearch extends Display {
await this.updateOptions();
yomichan.on('optionsUpdated', () => this.updateOptions());
await this.queryParser.prepare();
const options = this.getOptions();

const {queryParams: {query='', mode=''}} = parseUrl(window.location.href);

document.documentElement.dataset.searchMode = mode;

if (this.options.general.enableWanakana === true) {
if (options.general.enableWanakana === true) {
this.wanakanaEnable.checked = true;
wanakana.bind(this.query);
} else {
Expand All @@ -96,7 +97,7 @@ class DisplaySearch extends Display {
this.onSearchQueryUpdated(this.query.value, false);

if (mode !== 'popup') {
if (this.options.general.enableClipboardMonitor === true) {
if (options.general.enableClipboardMonitor === true) {
this.clipboardMonitorEnable.checked = true;
this.clipboardMonitor.start();
} else {
Expand All @@ -121,10 +122,6 @@ class DisplaySearch extends Display {
this._isPrepared = true;
}

onError(error) {
yomichan.logError(error);
}

onEscape() {
if (this.query === null) {
return;
Expand Down Expand Up @@ -241,7 +238,7 @@ class DisplaySearch extends Display {
url: window.location.href
}});
} else {
this.container.textContent = '';
this.clearContent();
}
this.setTitleText(query);
window.parent.postMessage('popupClose', '*');
Expand Down Expand Up @@ -299,7 +296,8 @@ class DisplaySearch extends Display {

async updateOptions() {
await super.updateOptions();
this.queryParser.setOptions(this.options);
const options = this.getOptions();
this.queryParser.setOptions(options);
if (!this._isPrepared) { return; }
const query = this.query.value;
if (query) {
Expand Down
20 changes: 3 additions & 17 deletions ext/fg/js/float.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class DisplayFloat extends Display {
this._secret = yomichan.generateId(16);
this._token = null;

this._orphaned = false;
this._nestedPopupsPrepared = false;

this._onKeyDownHandlers = new Map([
Expand Down Expand Up @@ -59,24 +58,11 @@ class DisplayFloat extends Display {
async prepare() {
await super.prepare();

yomichan.on('orphaned', this.onOrphaned.bind(this));
window.addEventListener('message', this.onMessage.bind(this), false);

api.broadcastTab('popupPrepared', {secret: this._secret});
}

onError(error) {
if (this._orphaned) {
this.setContent('orphaned');
} else {
yomichan.logError(error);
}
}

onOrphaned() {
this._orphaned = true;
}

onEscape() {
window.parent.postMessage('popupClose', '*');
}
Expand Down Expand Up @@ -126,7 +112,7 @@ class DisplayFloat extends Display {
}

async setOptionsContext(optionsContext) {
this.optionsContext = optionsContext;
super.setOptionsContext(optionsContext);
await this.updateOptions();
}

Expand Down Expand Up @@ -181,7 +167,7 @@ class DisplayFloat extends Display {
}

async _configure({messageId, frameId, popupId, optionsContext, childrenSupported, scale}) {
this.optionsContext = optionsContext;
this.setOptionsContext(optionsContext);

await this.updateOptions();

Expand All @@ -208,7 +194,7 @@ class DisplayFloat extends Display {
let complete = false;

const onOptionsUpdated = async () => {
const optionsContext = this.optionsContext;
const optionsContext = this.getOptionsContext();
const options = await api.optionsGet(optionsContext);
const maxPopupDepthExceeded = !(typeof depth === 'number' && depth < options.scanning.popupNestingMaxDepth);
if (maxPopupDepthExceeded || complete) { return; }
Expand Down
Loading