From 347805d4d0ecc9a488dc7ab42ce647346d063414 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Mon, 24 May 2021 18:12:08 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Added=20firing=20of=20`portal-ready?= =?UTF-8?q?`=20post=20message=20for=20preview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no refs This adds a way for top level site/admin to detect when Portal is loaded on the site and is ready to render, which allows dynamic UI handling specially in Preview mode in Admin. --- ghost/portal/src/App.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ghost/portal/src/App.js b/ghost/portal/src/App.js index e5de7e988d..23f27f9ac2 100644 --- a/ghost/portal/src/App.js +++ b/ghost/portal/src/App.js @@ -57,6 +57,7 @@ export default class App extends React.Component { if (this.state.initStatus === 'success' && prevState.initStatus !== this.state.initStatus) { const {siteUrl} = this.props; const contextState = this.getContextFromState(); + this.sendPortalReadyEvent(siteUrl); handleDataAttributes({ siteUrl, site: contextState.site, @@ -73,6 +74,14 @@ export default class App extends React.Component { }); } + sendPortalReadyEvent(siteUrl) { + const siteOrigin = ((new URL(siteUrl)).origin).replace(/\/$/, ''); + + if (window.self !== window.parent) { + window.parent.postMessage('portal-ready', siteOrigin); + } + } + /** Setup custom trigger buttons handling on page */ setupCustomTriggerButton() { // Handler for custom buttons