@@ -6,16 +6,18 @@ let addDynamicContent = (event) => {
66 imageElement = document . createElement ( 'img' ) ,
77 iframeElement = document . createElement ( 'iframe' ) ;
88
9+ imageElement . setAttribute ( 'is' , 'loading-image' ) ;
910 imageElement . setAttribute (
1011 'src' ,
11- 'img/lazyimg-src-loadinglazy.250x150.guetzli.jpg?loading=lazy&image-width=250&image-height=150'
12+ 'img/lazyimg-src-loadinglazy.250x150.guetzli.jpg?loading=lazy&image-width=250&image-height=150&dynamic '
1213 ) ;
1314 imageElement . setAttribute ( 'loading' , 'lazy' ) ;
1415 imageElement . setAttribute ( 'alt' , '..' ) ;
1516 imageElement . setAttribute ( 'width' , '250' ) ;
1617 imageElement . setAttribute ( 'height' , '150' ) ;
1718
18- iframeElement . setAttribute ( 'src' , 'iframe.html?loading=lazy' ) ;
19+ iframeElement . setAttribute ( 'is' , 'loading-iframe' ) ;
20+ iframeElement . setAttribute ( 'src' , 'iframe.html?loading=lazy&dynamic' ) ;
1921 iframeElement . setAttribute ( 'loading' , 'lazy' ) ;
2022 iframeElement . setAttribute ( 'title' , '..' ) ;
2123 iframeElement . setAttribute ( 'width' , '320' ) ;
@@ -26,13 +28,35 @@ let addDynamicContent = (event) => {
2628
2729 document . querySelector ( 'main' ) . insertAdjacentElement ( 'beforeend' , divElement ) ;
2830
29- // Call for preparing the sample image element included the latest
30- loadingAttributePolyfill . prepareElement ( divElement . querySelector ( 'img' ) ) ;
31- loadingAttributePolyfill . prepareElement ( divElement . querySelector ( 'iframe' ) ) ;
32-
3331 event . preventDefault ( ) ;
3432} ;
3533
3634document
3735 . querySelector ( 'button.add-dynamic-content' )
3836 . addEventListener ( 'click' , addDynamicContent ) ;
37+
38+ // See https://html.spec.whatwg.org/multipage/indices.html#element-interfaces
39+ // for the list of other DOM interfaces.
40+ class LoadingImages extends HTMLImageElement {
41+ constructor ( ) {
42+ super ( ) ; // Always call super() first in the constructor.
43+ // Call for preparing the sample image element included the latest
44+ console . log ( 'preparing image' , this ) ;
45+ loadingAttributePolyfill . prepareElement ( this ) ;
46+ }
47+ }
48+
49+ customElements . define ( 'loading-image' , LoadingImages , { extends : 'img' } ) ;
50+
51+ // See https://html.spec.whatwg.org/multipage/indices.html#element-interfaces
52+ // for the list of other DOM interfaces.
53+ class LoadingIframes extends HTMLIFrameElement {
54+ constructor ( ) {
55+ super ( ) ; // Always call super() first in the constructor.
56+ // Call for preparing the sample iframe element included the latest
57+ console . log ( 'preparing iframe' , this ) ;
58+ loadingAttributePolyfill . prepareElement ( this ) ;
59+ }
60+ }
61+
62+ customElements . define ( 'loading-iframe' , LoadingIframes , { extends : 'iframe' } ) ;
0 commit comments