Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessibility: Set iframe title attribute from child page <title> #1257

Merged
merged 6 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ <h2>Automagically resizing iFrame</h2>
src="../child/frame.content.html"
width="100%"
scrolling="no"
title="iframe-resizer content examples"
></iframe>
</div>
<p id="callback"></p>
Expand Down
7 changes: 7 additions & 0 deletions packages/child/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,17 @@ function init() {
startEventListeners()
inPageLinks = setupInPageLinks()
sendSize('init', 'Init message from host page', undefined, undefined, VERSION)
sendTitle()
onReady()
isInit = false
}

function sendTitle() {
if (document.title && document.title !== '') {
sendMsg(0, 0, 'title', document.title)
}
}

function checkVersion() {
if (!version || version === '' || version === 'false') {
advise(
Expand Down
20 changes: 18 additions & 2 deletions packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function iframeListener(event) {
height: height + getPaddingEnds(compStyle) + getBorderEnds(compStyle),
width: Number(data[2]),
type: data[3],
version: data[4],
msg: data[4],
}
}

Expand Down Expand Up @@ -480,6 +480,12 @@ See <u>https://iframe-resizer.com/setup/#child-page-setup</> for more details.
log(iframeId, `Version mismatch (Child: ${version} !== Parent: ${VERSION})`)
}

function setTitle(title, iframeId) {
if (!settings[iframeId]?.syncTitle) return
settings[iframeId].iframe.title = title
log(iframeId, `Set title attribute to: ${title}`)
}

function started() {
setup = true
}
Expand Down Expand Up @@ -538,14 +544,18 @@ See <u>https://iframe-resizer.com/setup/#child-page-setup</> for more details.
findTarget(getMsgBody(9))
break

case 'title':
setTitle(messageData.msg, iframeId)
break

case 'reset':
resetIFrame(messageData)
break

case 'init':
resizeIFrame()
checkSameDomain(iframeId)
checkVersion(messageData.version)
checkVersion(messageData.msg)
started()
on('onReady', messageData.iframe)
break
Expand Down Expand Up @@ -1035,6 +1045,11 @@ The <b>sizeWidth</>, <b>sizeHeight</> and <b>autoResize</> options have been rep
settings[iframeId].postMessageTarget = iframe.contentWindow
}

function chkTitle(iframeId) {
const { title } = document.getElementById(iframeId)
return title === ''
}

function processOptions(options) {
settings[iframeId] = {
iframe,
Expand All @@ -1043,6 +1058,7 @@ The <b>sizeWidth</>, <b>sizeHeight</> and <b>autoResize</> options have been rep
...defaults,
...checkOptions(options),
mode: setMode(options),
syncTitle: chkTitle(iframeId),
}

setDirection()
Expand Down
Loading