From 1b8fb79fad09488c8f644db88aed125efa7e0ab3 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Fri, 20 Feb 2015 12:15:20 -0500 Subject: [PATCH] Improve slightly error handling for images [#116] --- src/featherlight.gallery.js | 2 +- src/featherlight.js | 8 ++++---- test/featherlight_test.js | 10 ++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/featherlight.gallery.js b/src/featherlight.gallery.js index b812b601..9dbf75a4 100644 --- a/src/featherlight.gallery.js +++ b/src/featherlight.gallery.js @@ -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); diff --git a/src/featherlight.js b/src/featherlight.js index 6abafb94..54e12ab5 100644 --- a/src/featherlight.js +++ b/src/featherlight.js @@ -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 */ @@ -313,14 +313,14 @@ process: function(url) { var self = this, deferred = $.Deferred(), - img = new Image(); + img = new Image(), + $img = $(''); img.onload = function() { - var $img = $(''); /* 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(); } diff --git a/test/featherlight_test.js b/test/featherlight_test.js index 261f1c3d..8dd3a77a 100644 --- a/test/featherlight_test.js +++ b/test/featherlight_test.js @@ -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() { $('