From b41463d43726521d9d6678b68bbbb0893645a09c Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 25 Jun 2021 07:24:00 -0400 Subject: [PATCH] Skip handling non-media elements --- src/js/scriptlets/load-large-media-interactive.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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, ''); }