Skip to content

Commit

Permalink
Tidy core more
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjbradshaw committed Sep 11, 2024
1 parent d465f61 commit 1dbb2e9
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ function iframeListener(event) {
}

function getPaddingEnds(compStyle) {
if (compStyle.boxSizing !== 'border-box') {
return 0
}
if (compStyle.boxSizing !== 'border-box') return 0

const top = compStyle.paddingTop ? parseInt(compStyle.paddingTop, 10) : 0
const bot = compStyle.paddingBottom
Expand All @@ -45,9 +43,7 @@ function iframeListener(event) {
}

function getBorderEnds(compStyle) {
if (compStyle.boxSizing !== 'border-box') {
return 0
}
if (compStyle.boxSizing !== 'border-box') return 0

const top = compStyle.borderTopWidth
? parseInt(compStyle.borderTopWidth, 10)
Expand Down Expand Up @@ -108,9 +104,7 @@ function iframeListener(event) {

const { origin, sameDomain } = event

if (sameDomain) {
return true
}
if (sameDomain) return true

let checkOrigin = settings[iframeId]?.checkOrigin

Expand All @@ -132,9 +126,7 @@ function iframeListener(event) {
// the message format would break backwards compatibility.
const retCode = messageData.type in { true: 1, false: 1, undefined: 1 }

if (retCode) {
log(iframeId, 'Ignoring init message from meta parent page')
}
if (retCode) log(iframeId, 'Ignoring init message from meta parent page')

return retCode
}
Expand All @@ -153,7 +145,7 @@ function iframeListener(event) {
message: JSON.parse(msgBody),
})

log(iframeId, '--')
log(iframeId, '---')
}

function getPageInfo() {
Expand Down Expand Up @@ -260,11 +252,13 @@ function iframeListener(event) {

function start() {
setListener('Add ', addEventListener)

pageObserver.observe(document.body, {
attributes: true,
childList: true,
subtree: true,
})

iframeObserver.observe(settings[id].iframe, {
attributes: true,
childList: false,
Expand Down Expand Up @@ -688,24 +682,26 @@ function removeIframeListeners(iframe) {
}

function closeIFrame(iframe) {
const iframeId = iframe.id
if (chkEvent(iframeId, 'onClose', iframeId) === false) {
log(iframeId, 'Close iframe cancelled by onClose event')
const { id } = iframe

if (chkEvent(id, 'onClose', id) === false) {
log(id, 'Close iframe cancelled by onClose event')
return
}
log(iframeId, `Removing iFrame: ${iframeId}`)

log(id, `Removing iFrame: ${id}`)

try {
// Catch race condition error with React
if (iframe.parentNode) {
iframe.remove()
}
} catch (error) {
warn(iframeId, error)
warn(id, error)
}

chkEvent(iframeId, 'onClosed', iframeId)
log(iframeId, '--')
chkEvent(id, 'onClosed', id)
log(id, '---')
removeIframeListeners(iframe)
}

Expand Down

0 comments on commit 1dbb2e9

Please sign in to comment.