Skip to content

Commit

Permalink
Refactor readData from page
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjbradshaw committed Aug 30, 2024
1 parent 21f11db commit 0afea2e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion example/html/child/frame.animate.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ <h4>Data returned by parentIFrame.getParentProps()</h4>
const rowParent = ([key, info]) =>
`<tr><th>${key}</th><td><table>${Object.entries(info).map(row).join('\n')}</table></td></tr>`

window.iFrameResizer = {
window.iframeResizer = {
// We cheat a little here, as the iframe resize can be one
// frame behind the actual content height in the iframe if
// we're having to use postMessage due to operating cross
Expand Down
2 changes: 1 addition & 1 deletion example/html/child/frame.content.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
</script>
<script>
window.iFrameResizer = {
window.iframeResizer = {
onMessage(message) {
alert(message, parentIFrame.getId())
},
Expand Down
23 changes: 7 additions & 16 deletions packages/child/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ Parent page: ${version} - Child page: ${VERSION}.

function readDataFromPage() {
// eslint-disable-next-line sonarjs/cognitive-complexity
function readData() {
const data = window.iframeResizer || window.iFrameResizer

function readData(data) {
log(`Reading data from page: ${JSON.stringify(data)}`)

onMessage = data?.onMessage || onMessage
Expand Down Expand Up @@ -291,20 +289,13 @@ Parent page: ${version} - Child page: ${VERSION}.

if (mode === 1) return

log(
'Read Data From Page:',
'iframeResizer' in window || 'iFrameResizer' in window,
)
const data = window.iframeResizer || window.iFrameResizer

if (
('iFrameResizer' in window &&
Object === window.iFrameResizer.constructor) ||
('iframeResizer' in window && Object === window.iframeResizer.constructor)
) {
readData()
heightCalcMode = setupCustomCalcMethods(heightCalcMode, 'height')
widthCalcMode = setupCustomCalcMethods(widthCalcMode, 'width')
}
if (typeof data !== 'object') return

readData(data)
heightCalcMode = setupCustomCalcMethods(heightCalcMode, 'height')
widthCalcMode = setupCustomCalcMethods(widthCalcMode, 'width')

log(`TargetOrigin for parent set to: ${targetOriginDefault}`)
}
Expand Down

0 comments on commit 0afea2e

Please sign in to comment.