Skip to content

Commit

Permalink
bind load & error to img; for Firefox fix #191
Browse files Browse the repository at this point in the history
  • Loading branch information
desandro committed Oct 27, 2015
1 parent fcf5e58 commit bcbb8ca
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions imagesloaded.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,13 @@ function makeArray( obj ) {
}

// If none of the checks above matched, simulate loading on detached element.
var proxyImage = new Image();
eventie.bind( proxyImage, 'load', this );
eventie.bind( proxyImage, 'error', this );
proxyImage.src = this.img.src;
this.proxyImage = new Image();
eventie.bind( this.proxyImage, 'load', this );
eventie.bind( this.proxyImage, 'error', this );
// bind to image as well for Firefox. #191
eventie.bind( this.img, 'load', this );
eventie.bind( this.img, 'error', this );
this.proxyImage.src = this.img.src;
};

LoadingImage.prototype.confirm = function( isLoaded, message ) {
Expand All @@ -268,18 +271,19 @@ function makeArray( obj ) {

LoadingImage.prototype.onload = function( event ) {
this.confirm( true, 'onload' );
this.unbindProxyEvents( event );
this.unbindEvents();
};

LoadingImage.prototype.onerror = function( event ) {
debugger;
this.confirm( false, 'onerror' );
this.unbindProxyEvents( event );
this.unbindEvents();
};

LoadingImage.prototype.unbindProxyEvents = function( event ) {
eventie.unbind( event.target, 'load', this );
eventie.unbind( event.target, 'error', this );
LoadingImage.prototype.unbindEvents = function() {
eventie.unbind( this.proxyImage, 'load', this );
eventie.unbind( this.proxyImage, 'error', this );
eventie.unbind( this.img, 'load', this );
eventie.unbind( this.img, 'error', this );
};

// ----- ----- //
Expand Down

0 comments on commit bcbb8ca

Please sign in to comment.