Skip handling non-media elements

This commit is contained in:
Raymond Hill 2021-06-25 07:24:00 -04:00
parent 163035dc92
commit b41463d437
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 10 additions and 1 deletions

View File

@ -43,6 +43,12 @@ const largeMediaElementSelector =
/******************************************************************************/
const isMediaElement = function(elem) {
return /^(?:audio|img|picture|video)$/.test(elem.localName);
};
/******************************************************************************/
const mediaNotLoaded = function(elem) {
switch ( elem.localName ) {
case 'audio':
@ -231,7 +237,9 @@ document.addEventListener('loadeddata', onLoadedData);
/******************************************************************************/
const onLoad = function(ev) {
ev.target.removeAttribute(largeMediaElementAttribute);
const elem = ev.target;
if ( isMediaElement(elem) === false ) { return; }
elem.removeAttribute(largeMediaElementAttribute);
};
document.addEventListener('load', onLoad, true);
@ -240,6 +248,7 @@ document.addEventListener('load', onLoad, true);
const onLoadError = function(ev) {
const elem = ev.target;
if ( isMediaElement(elem) === false ) { return; }
if ( mediaNotLoaded(elem) ) {
elem.setAttribute(largeMediaElementAttribute, '');
}