remove isInjected checks from Popup

This commit is contained in:
siikamiika 2020-02-13 15:04:10 +02:00
parent 8abab28c4d
commit 38a6433a46

View File

@ -27,8 +27,6 @@ class Popup {
this._child = null; this._child = null;
this._childrenSupported = true; this._childrenSupported = true;
this._injectPromise = null; this._injectPromise = null;
this._isInjected = false;
this._isInjectedAndLoaded = false;
this._visible = false; this._visible = false;
this._visibleOverride = null; this._visibleOverride = null;
this._options = null; this._options = null;
@ -119,17 +117,13 @@ class Popup {
} }
clearAutoPlayTimer() { clearAutoPlayTimer() {
if (this._isInjectedAndLoaded) {
this._invokeApi('clearAutoPlayTimer'); this._invokeApi('clearAutoPlayTimer');
} }
}
setContentScale(scale) { setContentScale(scale) {
this._contentScale = scale; this._contentScale = scale;
if (this._isInjectedAndLoaded) {
this._invokeApi('setContentScale', {scale}); this._invokeApi('setContentScale', {scale});
} }
}
onMessage(e) { onMessage(e) {
const action = e.data; const action = e.data;
@ -160,7 +154,7 @@ class Popup {
} }
isVisibleSync() { isVisibleSync() {
return this._isInjected && (this._visibleOverride !== null ? this._visibleOverride : this._visible); return (this._visibleOverride !== null ? this._visibleOverride : this._visible);
} }
updateTheme() { updateTheme() {
@ -239,7 +233,6 @@ 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._isInjectedAndLoaded = true;
this._invokeApi('initialize', { this._invokeApi('initialize', {
options: this._options, options: this._options,
popupInfo: { popupInfo: {
@ -256,7 +249,6 @@ class Popup {
this._observeFullscreen(); this._observeFullscreen();
this._onFullscreenChanged(); this._onFullscreenChanged();
this.setCustomOuterCss(this._options.general.customPopupOuterCss, false); this.setCustomOuterCss(this._options.general.customPopupOuterCss, false);
this._isInjected = true;
}); });
} }
@ -341,11 +333,10 @@ class Popup {
} }
_invokeApi(action, params={}) { _invokeApi(action, params={}) {
if (!this._isInjectedAndLoaded) { if (this._container.contentWindow) {
throw new Error('Frame not loaded');
}
this._container.contentWindow.postMessage({action, params}, '*'); this._container.contentWindow.postMessage({action, params}, '*');
} }
}
_observeFullscreen() { _observeFullscreen() {
const fullscreenEvents = [ const fullscreenEvents = [