File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed
Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1+ if ( "forEach" in NodeList . prototype ) {
2+ function iframeSwitch ( el ) {
3+ if ( ! ( "fetch" in window ) || "connection" in navigator && navigator . connection . saveData === true ) {
4+ return ;
5+ }
6+
7+ let iframe = document . createElement ( "iframe" ) ;
8+ iframe . setAttribute ( "loading" , "lazy" ) ;
9+ for ( let attr of el . attributes ) {
10+ iframe . setAttribute ( attr . name , attr . nodeValue ) ;
11+ }
12+ el . replaceWith ( iframe ) ;
13+ }
14+
15+ if ( typeof IntersectionObserver !== "undefined" ) {
16+ var observer = new IntersectionObserver ( function ( changes ) {
17+ changes . forEach ( function ( change ) {
18+ if ( change . isIntersecting ) {
19+ iframeSwitch ( change . target ) ;
20+ observer . unobserve ( change . target ) ;
21+ }
22+ } ) ;
23+ } ) ;
24+ }
25+
26+ document . querySelectorAll ( "div[data-lazyiframe]" ) . forEach ( function ( element ) {
27+ if ( typeof IntersectionObserver !== "undefined" ) {
28+ observer . observe ( element ) ;
29+ } else {
30+ iframeSwitch ( element ) ;
31+ }
32+ } ) ;
33+ }
Original file line number Diff line number Diff line change @@ -94,5 +94,6 @@ ogimage: "/img/og/default-og-image.png"
9494 <script type =" module" src =" /js/details-force-state.js" ></script >
9595 <script type =" module" src =" /js/filter-container.js" ></script >
9696 <script type =" module" src =" /js/sort-container.js" ></script >
97+ <script type =" module" src =" /js/lazyiframe.js" ></script >
9798 </body >
9899</html >
Original file line number Diff line number Diff line change @@ -73,7 +73,9 @@ layout: layouts/base.njk
7373 <a href =" https://www.netlify.com/authors/matt-biilmann/" >Matt Biilmann</a > took the concept of Jamstack mainstream with his presentation at Smashing Conf 2016. Watch the quintessential introduction to the Jamstack.
7474 </p >
7575 <div class =" videowrapper mb-8" >
76- {# <iframe loading="lazy" src="https://player.vimeo.com/video/163522126?title=0&byline=0&portrait=0" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen title="Mathias Biilmann Smashing Conf 2016 talk video: The New Front-End Stack"></iframe> #}
76+ <div data-lazyiframe src =" https://player.vimeo.com/video/163522126?title=0&byline=0&portrait=0" width =" 640" height =" 360" frameborder =" 0" allow =" autoplay; fullscreen" allowfullscreen title =" Mathias Biilmann Smashing Conf 2016 talk video: The New Front-End Stack" >
77+ <a href =" https://vimeo.com/163522126" >Watch <em >Mathias Biilmann Smashing Conf 2016 talk video: The New Front-End Stack</em > on Vimeo</a >
78+ </div >
7779 </div >
7880 <a href =" /resources/" class =" cta" >See more videos and resources</a >
7981 </div >
You can’t perform that action at this time.
0 commit comments