Skip to content

Commit e63e798

Browse files
committed
fix Firefox rendering of empty images
1 parent 7325c37 commit e63e798

File tree

4 files changed

+54
-42
lines changed

4 files changed

+54
-42
lines changed

dist/angular-bootstrap-lightbox.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ angular.module('bootstrapLightbox').provider('Lightbox', function () {
419419
success();
420420
}, function () {
421421
success({
422-
'imageUrl': '//:0', // blank image
422+
'imageUrl': '#', // blank image
423423
// use the caption to show the user an error
424424
'imageCaption': 'Failed to load image'
425425
});
@@ -675,29 +675,39 @@ angular.module('bootstrapLightbox').directive('lightboxSrc', ['$window',
675675
scope.$watch(function () {
676676
return attrs.lightboxSrc;
677677
}, function (src) {
678-
if (!Lightbox.isVideo(Lightbox.image)) { // image
679-
// blank the image before resizing the element; see
680-
// http://stackoverflow.com/questions/5775469
681-
element[0].src = '//:0';
682-
683-
ImageLoader.load(src).then(function (image) {
684-
// these variables must be set before resize(), as they are used in
685-
// it
686-
imageWidth = image.naturalWidth;
687-
imageHeight = image.naturalHeight;
678+
// do nothing if there's no image
679+
if (!Lightbox.image) {
680+
return;
681+
}
688682

689-
// resize the img element and the containing modal
690-
resize();
683+
if (!Lightbox.isVideo(Lightbox.image)) { // image
684+
// blank the image before resizing the element
685+
element[0].src = '#';
691686

692-
// show the image
693-
element[0].src = src;
694-
}, function () {
687+
// handle failure to load the image
688+
var failure = function () {
695689
imageWidth = 0;
696690
imageHeight = 0;
697691

698-
// resize the img element even if loading fails
699692
resize();
700-
});
693+
};
694+
695+
if (src) {
696+
ImageLoader.load(src).then(function (image) {
697+
// these variables must be set before resize(), as they are used
698+
// in it
699+
imageWidth = image.naturalWidth;
700+
imageHeight = image.naturalHeight;
701+
702+
// resize the img element and the containing modal
703+
resize();
704+
705+
// show the image
706+
element[0].src = src;
707+
}, failure);
708+
} else {
709+
failure();
710+
}
701711
} else { // video
702712
// default dimensions
703713
imageWidth = 1280;

dist/angular-bootstrap-lightbox.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lightbox-service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ angular.module('bootstrapLightbox').provider('Lightbox', function () {
346346
success();
347347
}, function () {
348348
success({
349-
'imageUrl': '//:0', // blank image
349+
'imageUrl': '#', // blank image
350350
// use the caption to show the user an error
351351
'imageCaption': 'Failed to load image'
352352
});

src/lightbox-src-directive.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -153,36 +153,38 @@ angular.module('bootstrapLightbox').directive('lightboxSrc', ['$window',
153153
scope.$watch(function () {
154154
return attrs.lightboxSrc;
155155
}, function (src) {
156+
// do nothing if there's no image
157+
if (!Lightbox.image) {
158+
return;
159+
}
160+
156161
if (!Lightbox.isVideo(Lightbox.image)) { // image
157-
// blank the image before resizing the element; see
158-
// http://stackoverflow.com/questions/5775469
159-
element[0].src = '//:0';
162+
// blank the image before resizing the element
163+
element[0].src = '#';
160164

161-
if(src){
162-
ImageLoader.load(src).then(function (image) {
163-
// these variables must be set before resize(), as they are used in
164-
// it
165-
imageWidth = image.naturalWidth;
166-
imageHeight = image.naturalHeight;
165+
// handle failure to load the image
166+
var failure = function () {
167+
imageWidth = 0;
168+
imageHeight = 0;
167169

168-
// resize the img element and the containing modal
169170
resize();
171+
};
170172

171-
// show the image
172-
element[0].src = src;
173-
}, function () {
174-
imageWidth = 0;
175-
imageHeight = 0;
173+
if (src) {
174+
ImageLoader.load(src).then(function (image) {
175+
// these variables must be set before resize(), as they are used
176+
// in it
177+
imageWidth = image.naturalWidth;
178+
imageHeight = image.naturalHeight;
176179

177-
// resize the img element even if loading fails
180+
// resize the img element and the containing modal
178181
resize();
179-
});
180-
} else {
181-
imageWidth = 0;
182-
imageHeight = 0;
183182

184-
// resize the empty img element
185-
resize();
183+
// show the image
184+
element[0].src = src;
185+
}, failure);
186+
} else {
187+
failure();
186188
}
187189
} else { // video
188190
// default dimensions

0 commit comments

Comments
 (0)