Skip to content

Commit

Permalink
Improve slightly error handling for images [#116]
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Feb 20, 2015
1 parent 9368302 commit 1b8fb79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/featherlight.gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
return $.when(
self.getContent(),
$inner.fadeTo(self.galleryFadeOut,0.2)
).done(function($newContent) {
).always(function($newContent) {
self.setContent($newContent);
self.afterContent();
$newContent.fadeTo(self.galleryFadeIn,1);
Expand Down
8 changes: 4 additions & 4 deletions src/featherlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
self.beforeContent(event);

/* Set content and show */
$.when($content).done(function($content){
$.when($content).always(function($content){
self.setContent($content);
self.afterContent(event);
/* Call afterOpen after fadeIn is done */
Expand Down Expand Up @@ -313,14 +313,14 @@
process: function(url) {
var self = this,
deferred = $.Deferred(),
img = new Image();
img = new Image(),
$img = $('<img src="'+url+'" alt="" class="'+self.namespace+'-image" />');
img.onload = function() {
var $img = $('<img src="'+url+'" alt="" class="'+self.namespace+'-image" />');
/* Store naturalWidth & height for IE8 */
$img.naturalWidth = img.width; $img.naturalHeight = img.height;
deferred.resolve( $img );
};
img.onerror = function() { deferred.reject(); };
img.onerror = function() { deferred.reject($img); };
img.src = url;
return deferred.promise();
}
Expand Down
10 changes: 10 additions & 0 deletions test/featherlight_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ var stubAjaxLoad = function(content) {

});

describe('error handling', function() {
it('is quite basic', function(done) {
$.featherlight('does_not_exist.jpg');
patiently(done, function() {
expect($('.featherlight-image')).to.have.attr('src').equal('does_not_exist.jpg');
expect($('.featherlight')).not.to.have.class('featherlight-loading');
});
});
});

describe('iframe content filter', function() {
it('generates an iframe with the right attributes', function() {
$('<a data-featherlight-iframe="http://www.apple.com" '+
Expand Down

0 comments on commit 1b8fb79

Please # to comment.