Skip to content

Commit

Permalink
This update is based upon issue GalleriaJS#213
Browse files Browse the repository at this point in the history
Quote:
"If an image is taking longer to download than usual, then the "could not extract height/width" error was being displayed. It couldn't be extracted because the image wasn't done downloading yet."

I've added a comment into that issue's thread and would've wanted to update Michael's code itself but was unable to find out how to do so - I'm a noobie to GitHub... So please forgive me if I'm doing this the wrong way and point me in the right direction if you know how to modify a user-submitted "pull request".

I've commented the code as best as I know how and if you wish to see the full reasoning for why I'm submitting this, please visit the original issue:

GalleriaJS#213 (comment)

Many thanks for your kind patience!

Best regards,

Anand
  • Loading branch information
anandkkpr committed Dec 3, 2011
1 parent cd07497 commit 21e0454
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/galleria.js
Original file line number Diff line number Diff line change
Expand Up @@ -4785,24 +4785,41 @@ Galleria.Picture.prototype = {
}
};

// Delay the callback to "fix" the Adblock Bug
// http://code.google.com/p/adblockforchrome/issues/detail?id=3701
if ( ( !this.width || !this.height ) ) {
window.setTimeout( (function( img ) {
return function() {
if ( img.width && img.height ) {
// create an element which will be offscreen but will be visible to the browser as having dimensions
var dummyContainer = $('<div />').appendTo('body').css({'position':'relative','left':'-9999px'});
// keep track of the element of the Galleria Stage to which this <img /> belongs
var orgParent = $(this).parent();
// keep track of the image that is being scrutinised for its dimensions
var img = $(this).appendTo(dummyContainer);

// create a timer that wil wait 20ms for the image to load (e.g. bad net connection)
var timer = window.setInterval( (function( img, dummyContainer, orgParent ) {
// will either return an error - cause the image did not load or will
// pass the downloaded image to the complete() function
return function() {
// confirming that the image downloaded and dimensions could be discerned
if ( img.width() && img.height() ) {
// put it back to where we took it from
img.appendTo(orgParent);
// we don't want excess elements building up in memory for no reason - perform cleanup
dummyContainer.remove();
// more cleanup, clear the timer for use later if need be
clearInterval(timer);
// pass the image to where it needs to go
complete.call( img );
} else {
Galleria.raise('Could not extract width/height from image: ' + img.src +
'. Traced measures: width:' + img.width + 'px, height: ' + img.height + 'px.');
}
};
}( this )), 2);
// updated the self-executing lambda to receive the needed stuff for correct checking
})( img, dummyContainer, orgParent ), 20);
} else {
complete.call( this );
}
};
}( this, callback, src ));
})( this, callback, src );

// remove any previous images
$container.find( 'img' ).remove();
Expand Down

0 comments on commit 21e0454

Please sign in to comment.