diff --git a/src/js/scriptlets/load-large-media-interactive.js b/src/js/scriptlets/load-large-media-interactive.js index d5ed30847..12fa3432b 100644 --- a/src/js/scriptlets/load-large-media-interactive.js +++ b/src/js/scriptlets/load-large-media-interactive.js @@ -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, ''); }