diff --git a/jquery.imagesloaded.js b/jquery.imagesloaded.js index e879492..081cd40 100644 --- a/jquery.imagesloaded.js +++ b/jquery.imagesloaded.js @@ -50,6 +50,10 @@ $.fn.imagesLoaded = function( callback ) { callback.call( $this, $images, $proper, $broken ); } } + + function imgLoadedHandler( event ) { + imgLoaded( event.target, event.type === 'error' ); + } function imgLoaded( img, isBroken ) { // don't proceed if BLANK image, or image is already loaded @@ -76,9 +80,9 @@ $.fn.imagesLoaded = function( callback ) { } // call doneLoading and clean listeners if all images are loaded - if ( $images.length === loaded.length ){ + if ( $images.length === loaded.length ) { setTimeout( doneLoading ); - $images.unbind( '.imagesLoaded' ); + $images.unbind( '.imagesLoaded', imgLoadedHandler ); } } @@ -86,10 +90,8 @@ $.fn.imagesLoaded = function( callback ) { if ( !$images.length ) { doneLoading(); } else { - $images.bind( 'load.imagesLoaded error.imagesLoaded', function( event ){ - // trigger imgLoaded - imgLoaded( event.target, event.type === 'error' ); - }).each( function( i, el ) { + $images.bind( 'load.imagesLoaded error.imagesLoaded', imgLoadedHandler ) + .each( function( i, el ) { var src = el.src; // find out if this image has been already checked for status