diff options
author | Hakim El Hattab <hakim.elhattab@gmail.com> | 2015-05-04 20:22:32 -0400 |
---|---|---|
committer | Hakim El Hattab <hakim.elhattab@gmail.com> | 2015-05-04 20:22:32 -0400 |
commit | 152271efb26034c0fe8b898a5cad61939f542c99 (patch) | |
tree | 25847da0386d37b917f10ca98f5067729b0e6fa1 /js | |
parent | 80e52c08e9e57dfa782bdb83123ad85a694467c0 (diff) | |
download | fosdem-2018-presentation-152271efb26034c0fe8b898a5cad61939f542c99.tar fosdem-2018-presentation-152271efb26034c0fe8b898a5cad61939f542c99.tar.gz |
lazy loading fallback also considers iframes
Diffstat (limited to 'js')
-rw-r--r-- | js/reveal.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/js/reveal.js b/js/reveal.js index d9ba333..79c8bbb 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -238,14 +238,18 @@ if( !features.transforms2d && !features.transforms3d ) { document.body.setAttribute( 'class', 'no-transforms' ); - // Since JS won't be running any further, we need to load all - // images that were intended to lazy load now - var images = document.getElementsByTagName( 'img' ); - for( var i = 0, len = images.length; i < len; i++ ) { - var image = images[i]; - if( image.getAttribute( 'data-src' ) ) { - image.setAttribute( 'src', image.getAttribute( 'data-src' ) ); - image.removeAttribute( 'data-src' ); + // Since JS won't be running any further, we load all lazy + // loading elements upfront + var images = toArray( document.getElementsByTagName( 'img' ) ), + iframes = toArray( document.getElementsByTagName( 'iframe' ) ); + + var lazyLoadable = images.concat( iframes ); + + for( var i = 0, len = lazyLoadable.length; i < len; i++ ) { + var element = lazyLoadable[i]; + if( element.getAttribute( 'data-src' ) ) { + element.setAttribute( 'src', element.getAttribute( 'data-src' ) ); + element.removeAttribute( 'data-src' ); } } |