send embed postmessage to top window (#821)

main
Michael Fix 5 years ago committed by GitHub
parent 89097b936f
commit 1cdaa6f13a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,7 +2,6 @@
import React from 'react' import React from 'react'
import Head from 'next/head' import Head from 'next/head'
import { withRouter } from 'next/router' import { withRouter } from 'next/router'
import morph from 'morphmorph'
// Ours // Ours
import ApiContext from '../components/ApiContext' import ApiContext from '../components/ApiContext'
@ -11,17 +10,6 @@ import Carbon from '../components/Carbon'
import { DEFAULT_CODE, DEFAULT_SETTINGS } from '../lib/constants' import { DEFAULT_CODE, DEFAULT_SETTINGS } from '../lib/constants'
import { getRouteState } from '../lib/routing' import { getRouteState } from '../lib/routing'
const isInIFrame = morph.get('parent.window.parent')
const getParent = win => {
const iFrame = isInIFrame(win)
if (iFrame) {
return iFrame
}
return win.parent
}
const Page = props => ( const Page = props => (
<React.Fragment> <React.Fragment>
<Head> <Head>
@ -80,7 +68,7 @@ class Embed extends React.Component {
postMessage = () => { postMessage = () => {
setTimeout( setTimeout(
() => () =>
getParent(window).postMessage( window.top.postMessage(
JSON.stringify({ JSON.stringify({
// Used by embed provider // Used by embed provider
src: window.location.toString(), src: window.location.toString(),
@ -96,7 +84,7 @@ class Embed extends React.Component {
updateCode = code => { updateCode = code => {
this.setState({ code }, this.postMessage) this.setState({ code }, this.postMessage)
getParent(window).postMessage( window.top.postMessage(
{ {
id: this.state.id ? `carbon:${this.state.id}` : 'carbon', id: this.state.id ? `carbon:${this.state.id}` : 'carbon',
code code

Loading…
Cancel
Save