Skip to content

Commit 5175f88

Browse files
authored
Merge pull request #1148 from equalizedigital/william/pro-218-missing-transcript-not-detected-when-using-lazyload-iframes
Missing transcript not detecting correctly when using lazyload iframes
2 parents cb5f430 + 0977d37 commit 5175f88

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

src/pageScanner/checks/has-transcript.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
const videoEmbedKeywords = [ 'youtube.com', 'youtu.be', 'vimeo.com' ];
99
const mediaExtensions = /\.(3gp|asf|asx|avi|flv|m4a|m4p|mov|mp3|mp4|mpeg|mpeg2|mpg|mpv|ogg|oga|ogv|qtl|smi|smil|wav|wax|webm|wmv|wmp|wmx)(\?.*)?$/i;
1010

11+
const MAX_SIBLINGS_TO_CHECK = 5;
12+
const PARENT_SIBLING_LIMIT = 3;
13+
1114
export default {
1215
id: 'has_transcript',
1316
evaluate: ( node ) => {
@@ -49,14 +52,37 @@ export default {
4952
},
5053
};
5154

55+
/**
56+
* Helper function to collect text content from a series of sibling elements
57+
* @param {Element} startSibling - The first sibling element to start from
58+
* @param {number} maxCount - Maximum number of siblings to check
59+
* @return {string} - Concatenated text content from siblings
60+
*/
61+
function collectSiblingText( startSibling, maxCount ) {
62+
let text = '';
63+
let currentSibling = startSibling;
64+
let siblingCount = 0;
65+
66+
while ( currentSibling && siblingCount < maxCount ) {
67+
const siblingText = currentSibling.textContent?.trim();
68+
if ( siblingText ) {
69+
text += siblingText + ' ';
70+
}
71+
currentSibling = currentSibling.nextElementSibling;
72+
siblingCount++;
73+
}
74+
75+
return text;
76+
}
77+
5278
function getSurroundingText( node, radius = 250 ) {
5379
let text = '';
5480

55-
// Include immediate next and previous siblings
56-
if ( node.previousElementSibling ) {
81+
// Include immediate next and previous siblings (but skip noscript elements)
82+
if ( node.previousElementSibling && node.previousElementSibling.nodeName.toLowerCase() !== 'noscript' ) {
5783
text += node.previousElementSibling.textContent.trim() + ' ';
5884
}
59-
if ( node.nextElementSibling ) {
85+
if ( node.nextElementSibling && node.nextElementSibling.nodeName.toLowerCase() !== 'noscript' ) {
6086
text += node.nextElementSibling.textContent.trim() + ' ';
6187
}
6288

@@ -67,11 +93,17 @@ function getSurroundingText( node, radius = 250 ) {
6793
if ( figcaption ) {
6894
text += figcaption.textContent.trim() + ' ';
6995
}
96+
97+
// Check siblings of the figure element for transcript links
98+
text += collectSiblingText( figure.nextElementSibling, MAX_SIBLINGS_TO_CHECK );
7099
}
71100

72101
// Walk limited DOM subtree (media-wrapper, section, article, etc.)
73102
const parent = node.closest( '.media-wrapper, figure, section, article' );
74103
if ( parent ) {
104+
// Also check parent's siblings for transcript text
105+
text += collectSiblingText( parent.nextElementSibling, PARENT_SIBLING_LIMIT );
106+
75107
const nodeFilter = {
76108
acceptNode( textNode ) {
77109
const style = window.getComputedStyle( textNode.parentElement );

tests/jest/rules/missingTranscript.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ describe( 'Missing Transcript Rule', () => {
8585
`,
8686
shouldPass: true,
8787
},
88+
{
89+
name: 'passes YouTube iframe with transcript link nearby',
90+
html: `
91+
<figure>
92+
<div class="wp-block-embed__wrapper">
93+
<iframe src="https://www.youtube.com/embed/ABC123?feature=oembed&amp;enablejsapi=1&amp;origin=https://example.com" title="Sample Video Title" width="980" height="551" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" class="_iub_cs_activate perfmatters-lazy entered pmloaded _iub_cs_activate-activated" data-iub-purposes="3" data-src="//cdn.iubenda.com/cookie_solution/empty.html" data-ll-status="loaded" data-cmp-ab="2" data-cmp-info="8" async="false"></iframe>
94+
<noscript>
95+
<iframe title="Sample Video Title" width="980" height="551" src="//cdn.iubenda.com/cookie_solution/empty.html" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen suppressedsrc="https://www.youtube.com/embed/ABC123?feature=oembed&amp;enablejsapi=1&amp;origin=https://example.com" class=" _iub_cs_activate" data-iub-purposes="3"></iframe>
96+
</noscript>
97+
</div>
98+
</figure>
99+
<h3 class="wp-block-heading"><a href="https://example.com/transcript-sample-video/">(Access a full transcript of the above video.)</a></h3>
100+
`,
101+
shouldPass: true,
102+
},
88103

89104
// ✅ Negative (non-relevant) elements — no violation
90105
{

0 commit comments

Comments
 (0)