|
1 | 1 | import loadingAttributePolyfill from '../dist/loading-attribute-polyfill.module.js'; |
2 | 2 |
|
| 3 | +// Test for dynamically inserted images and iframes |
| 4 | +let addDynamicContent = (event) => { |
| 5 | + let divElement = document.createElement('div'), |
| 6 | + imageElement = document.createElement('img'), |
| 7 | + iframeElement = document.createElement('iframe'); |
| 8 | + |
| 9 | + imageElement.setAttribute( |
| 10 | + 'src', |
| 11 | + 'img/lazyimg-src-loadinglazy.250x150.guetzli.jpg?loading=lazy&image-width=250&image-height=150' |
| 12 | + ); |
| 13 | + imageElement.setAttribute('loading', 'lazy'); |
| 14 | + imageElement.setAttribute('alt', '..'); |
| 15 | + imageElement.setAttribute('width', '250'); |
| 16 | + imageElement.setAttribute('height', '150'); |
| 17 | + |
| 18 | + iframeElement.setAttribute('src', 'iframe.html?loading=lazy'); |
| 19 | + iframeElement.setAttribute('loading', 'lazy'); |
| 20 | + iframeElement.setAttribute('title', '..'); |
| 21 | + iframeElement.setAttribute('width', '320'); |
| 22 | + iframeElement.setAttribute('height', '180'); |
| 23 | + |
| 24 | + divElement.appendChild(imageElement); |
| 25 | + divElement.appendChild(iframeElement); |
| 26 | + |
| 27 | + document.querySelector('main').insertAdjacentElement('beforeend', divElement); |
| 28 | + |
| 29 | + // Call for preparing the sample image element included the latest |
| 30 | + loadingAttributePolyfill.prepareElement(divElement.querySelector('img')); |
| 31 | + loadingAttributePolyfill.prepareElement(divElement.querySelector('iframe')); |
| 32 | + |
| 33 | + event.preventDefault(); |
| 34 | +}; |
| 35 | + |
| 36 | +document |
| 37 | + .querySelector('button.add-dynamic-content') |
| 38 | + .addEventListener('click', addDynamicContent); |
0 commit comments