0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Fixed offer screen portal preview height

refs https://github.com/TryGhost/Team/issues/1137

- adds dynamic height calculation based on portal events for offer portal preview
This commit is contained in:
Rishabh 2021-10-18 17:54:22 +05:30
parent 0619b10720
commit b8d1dc8deb

View file

@ -183,10 +183,29 @@ export default class OffersController extends Controller {
}
@action
portalPreviewInserted() {}
portalPreviewInserted(iframe) {
this.portalPreviewIframe = iframe;
if (!this.portalMessageListener) {
this.portalMessageListener = (event) => {
const resizeEvents = ['portal-ready', 'portal-preview-updated'];
if (resizeEvents.includes(event.data.type) && event.data.payload?.height) {
this.portalPreviewIframe.parentNode.style.height = `${event.data.payload.height}px`;
}
};
window.addEventListener('message', this.portalMessageListener, true);
}
}
@action
portalPreviewDestroyed() {}
portalPreviewDestroyed() {
this.portalPreviewIframe = null;
if (this.portalMessageListener) {
window.removeEventListener('message', this.portalMessageListener);
}
}
@action
updatePortalPreview({forceRefresh} = {forceRefresh: false}) {