mirror of
https://github.com/hakimel/reveal.js.git
synced 2025-08-15 02:58:20 +02:00
accessibility improvements; announce img/video alt tags, punctuate screen reader text content (#3757, #3772)
This commit is contained in:
4
dist/reveal.esm.js
vendored
4
dist/reveal.esm.js
vendored
File diff suppressed because one or more lines are too long
2
dist/reveal.esm.js.map
vendored
2
dist/reveal.esm.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/reveal.js
vendored
4
dist/reveal.js
vendored
File diff suppressed because one or more lines are too long
2
dist/reveal.js.map
vendored
2
dist/reveal.js.map
vendored
File diff suppressed because one or more lines are too long
33
js/reveal.js
33
js/reveal.js
@@ -394,7 +394,7 @@ export default function( revealElement, options ) {
|
||||
|
||||
// Text node
|
||||
if( node.nodeType === 3 ) {
|
||||
text += node.textContent;
|
||||
text += node.textContent.trim();
|
||||
}
|
||||
// Element node
|
||||
else if( node.nodeType === 1 ) {
|
||||
@@ -403,10 +403,25 @@ export default function( revealElement, options ) {
|
||||
let isDisplayHidden = window.getComputedStyle( node )['display'] === 'none';
|
||||
if( isAriaHidden !== 'true' && !isDisplayHidden ) {
|
||||
|
||||
// Capture alt text from img and video elements
|
||||
if( node.tagName === 'IMG' || node.tagName === 'VIDEO' ) {
|
||||
let altText = node.getAttribute( 'alt' );
|
||||
if( altText ) {
|
||||
text += ensurePunctuation( altText );
|
||||
}
|
||||
}
|
||||
|
||||
Array.from( node.childNodes ).forEach( child => {
|
||||
text += getStatusText( child );
|
||||
} );
|
||||
|
||||
// Add period after block-level text elements to improve
|
||||
// screen reader experience
|
||||
const textElements = ['P', 'DIV', 'UL', 'OL', 'LI', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'BLOCKQUOTE'];
|
||||
if( textElements.includes( node.tagName ) && text.trim() !== '' ) {
|
||||
text = ensurePunctuation( text );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -417,6 +432,22 @@ export default function( revealElement, options ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures text ends with proper punctuation by adding a period
|
||||
* if it doesn't already end with punctuation.
|
||||
*/
|
||||
function ensurePunctuation( text ) {
|
||||
|
||||
const trimmedText = text.trim();
|
||||
|
||||
if( trimmedText === '' ) {
|
||||
return text;
|
||||
}
|
||||
|
||||
return !/[.!?]$/.test(trimmedText) ? trimmedText + '.' : trimmedText;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an unfortunate necessity. Some actions – such as
|
||||
* an input field being focused in an iframe or using the
|
||||
|
Reference in New Issue
Block a user