Simplify float initialization

This commit is contained in:
toasted-nutbread 2019-10-02 21:11:06 -04:00
parent 7380ada1f1
commit fa7ee468c0
2 changed files with 28 additions and 37 deletions

View File

@ -96,6 +96,18 @@ class DisplayFloat extends Display {
} }
} }
initialize(options, popupInfo, url) {
const css = options.general.customPopupCss;
if (css) {
this.setStyle(css);
}
const {id, depth, parentFrameId} = popupInfo;
this.optionsContext.depth = depth;
this.optionsContext.url = url;
popupNestedInitialize(id, depth, parentFrameId, url);
}
setStyle(css) { setStyle(css) {
const parent = document.head; const parent = document.head;
@ -122,34 +134,11 @@ DisplayFloat.onKeyDownHandlers = {
}; };
DisplayFloat.messageHandlers = { DisplayFloat.messageHandlers = {
termsShow: (self, {definitions, options, context}) => { termsShow: (self, {definitions, options, context}) => self.termsShow(definitions, options, context),
self.termsShow(definitions, options, context); kanjiShow: (self, {definitions, options, context}) => self.kanjiShow(definitions, options, context),
}, clearAutoPlayTimer: (self) => self.clearAutoPlayTimer(),
orphaned: (self) => self.onOrphaned(),
kanjiShow: (self, {definitions, options, context}) => { initialize: (self, {options, popupInfo, url}) => self.initialize(options, popupInfo, url)
self.kanjiShow(definitions, options, context);
},
clearAutoPlayTimer: (self) => {
self.clearAutoPlayTimer();
},
orphaned: (self) => {
self.onOrphaned();
},
setOptions: (self, options) => {
const css = options.general.customPopupCss;
if (css) {
self.setStyle(css);
}
},
popupNestedInitialize: (self, {id, depth, parentFrameId, url}) => {
self.optionsContext.depth = depth;
self.optionsContext.url = url;
popupNestedInitialize(id, depth, parentFrameId, url);
}
}; };
window.yomichan_display = new DisplayFloat(); window.yomichan_display = new DisplayFloat();

View File

@ -56,17 +56,19 @@ class Popup {
return new Promise((resolve) => { return new Promise((resolve) => {
const parentFrameId = (typeof this.frameId === 'number' ? this.frameId : null); const parentFrameId = (typeof this.frameId === 'number' ? this.frameId : null);
this.container.addEventListener('load', () => { this.container.addEventListener('load', () => {
this.invokeApi('popupNestedInitialize', { this.invokeApi('initialize', {
id: this.id, options: {
depth: this.depth, general: {
parentFrameId, customPopupCss: options.general.customPopupCss
}
},
popupInfo: {
id: this.id,
depth: this.depth,
parentFrameId
},
url: this.url url: this.url
}); });
this.invokeApi('setOptions', {
general: {
customPopupCss: options.general.customPopupCss
}
});
resolve(); resolve();
}); });
this.observeFullscreen(); this.observeFullscreen();