1// IE9+ support for Javascript forEach 2if (window.NodeList && !NodeList.prototype.forEach) { 3 NodeList.prototype.forEach = Array.prototype.forEach; 4} 5 6const mark_as_loaded = function ( image ) { 7 image.onload = null; 8 image.classList.replace( 'pmip-pending', 'pmip-loaded' ); 9}; 10 11const mark_as_failed = function ( image ) { 12 image.onerror = null; 13 image.removeAttribute( 'srcset' ); 14 image.removeAttribute( 'sizes' ); 15 image.classList.replace( 'pmip-pending', 'pmip-failed' ); 16 image.src = pei_mip_settings.placeholder; 17}; 18 19const replace_broken_images = function replace_broken_images() { 20 document.querySelectorAll('img').forEach( ( image, i ) => { 21 if ( 22 !image.classList.contains( 'pmip-loaded' ) 23 && !image.classList.contains( 'pmip-pending' ) 24 && !image.classList.contains( 'pmip-failed' ) 25 && !image.classList.contains( 'lazyload' ) 26 && image.src.indexOf('.svg') < 1 27 ) { 28 image.setAttribute( 'data-original-src', image.src ); 29 image.classList.add( 'pmip-pending' ); 30 if ( image.complete && image.naturalHeight !== 0 ) { 31 mark_as_loaded( image ); 32 } else { 33 image.src = image.getAttribute( 'data-original-src' ); 34 image.onerror = () => { 35 mark_as_failed( image ); 36 }; 37 image.onload = () => { 38 mark_as_loaded( image ); 39 }; 40 } 41 } 42 }); 43}; 44 45replace_broken_images(); 46document.addEventListener( 'DOMContentLoaded', () => { 47 window.setInterval( 48 () => { 49 replace_broken_images(); 50 }, 51 100 52 ); 53});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.