main/ImageAccessibility.js

/**
 * Some 3rd party tracker images render without an 'alt' attribute
 * For accessibility, we are adding 'alt' to them on our end
 *
 * @module ImageAccessibility
 */
const ImageAccessibility = {
	/**
	 * Find images and check if they have 'alt' attribute.
	 * If 'alt' is not set, add an empty alt.
	 *
	 * @method init
	 */
	init() {
		setTimeout( () => {
			const $images = document.querySelectorAll( 'img' );
			Object.keys( $images ).forEach( ( key ) => {
				const $image = $images[key];
				const alt = $image.getAttribute( 'alt' );
				if ( null === alt ) {
					$image.setAttribute( 'alt', '' );
				}
			});
		}, 5000 );
	},
};

export default ImageAccessibility;