function loadImage ( imgElement , src , srcset , checkForComplete , callback ) { let image ; const onReady = ( ) => { if ( callback ) { callback ( ) ; } } ; if ( ! imgElement . complete || ! checkForComplete ) { if ( src ) { image = new Image ( ) ; image . onload = onReady ; image . onerror = onReady ; if ( srcset ) { image . srcset = srcset ; } if ( src ) { image . src = src ; } } else { onReady ( ) ; } } else { onReady ( ) ; } } function preloadImages ( container , imagesLoaded , callback , onLoad ? ) { const imagesToLoad = container . find ( 'img' ) ; function _onReady ( ) { if ( imagesLoaded !== undefined ) { imagesLoaded ++ ; if ( onLoad ) { onLoad ( imagesLoaded ) ; } } if ( imagesLoaded === imagesToLoad . length ) { callback ( ) ; } } let i = 0 ; for ( const image of imagesToLoad ) { loadImage ( image , ( image . currentSrc || image . getAttribute ( 'src' ) ) , ( image . srcset || image . getAttribute ( 'srcset' ) ) , true , _onReady ) ; i ++ ; } } export { loadImage , preloadImages } ;