Skip to content

Commit 9ea5e60

Browse files
committed
+fix: SVG misrendering in IE11 and old FIrefox on Windows when no width and height attrs
1 parent c9b76ff commit 9ea5e60

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

src/js/lightbox.js

+25-8
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@
265265
// Hide most UI elements in preparation for the animated resizing of the lightbox.
266266
Lightbox.prototype.changeImage = function(imageNumber) {
267267
var self = this;
268+
var filename = this.album[imageNumber].link;
269+
var filetype = filename.split('.').slice(-1)[0];
268270

269271
this.disableKeyboardNav();
270272
var $image = this.$lightbox.find('.lb-image');
@@ -289,22 +291,37 @@
289291

290292
$image.attr({
291293
'alt': self.album[imageNumber].alt,
292-
'src': self.album[imageNumber].link
294+
'src': filename
293295
});
294296

295297
$preloader = $(preloader);
296298

297299
$image.width(preloader.width);
298300
$image.height(preloader.height);
301+
windowWidth = $(window).width();
302+
windowHeight = $(window).height();
299303

300-
if (self.options.fitImagesInViewport) {
301-
// Fit image inside the viewport.
302-
// Take into account the border around the image and an additional 10px gutter on each side.
304+
// Calculate the max image dimensions for the current viewport.
305+
// Take into account the border around the image and an additional 10px gutter on each side.
306+
maxImageWidth = windowWidth - self.containerPadding.left - self.containerPadding.right - self.imageBorderWidth.left - self.imageBorderWidth.right - 20;
307+
maxImageHeight = windowHeight - self.containerPadding.top - self.containerPadding.bottom - self.imageBorderWidth.top - self.imageBorderWidth.bottom - 120;
308+
309+
/* SVGs that don't have width and height attributes specified are reporting width and height
310+
values of 0 in Firefox 47 and IE11 on Windows. To fix, we set the width and height to the max
311+
dimensions for the viewport rather than 0 x 0.
303312
304-
windowWidth = $(window).width();
305-
windowHeight = $(window).height();
306-
maxImageWidth = windowWidth - self.containerPadding.left - self.containerPadding.right - self.imageBorderWidth.left - self.imageBorderWidth.right - 20;
307-
maxImageHeight = windowHeight - self.containerPadding.top - self.containerPadding.bottom - self.imageBorderWidth.top - self.imageBorderWidth.bottom - 120;
313+
- https://github.com/lokesh/lightbox2/issues/552
314+
*/
315+
316+
if (filetype === 'svg') {
317+
if ((preloader.width === 0) || preloader.height === 0) {
318+
$image.width(maxImageWidth);
319+
$image.height(maxImageHeight);
320+
}
321+
}
322+
323+
// Fit image inside the viewport.
324+
if (self.options.fitImagesInViewport) {
308325

309326
// Check if image size is larger then maxWidth|maxHeight in settings
310327
if (self.options.maxWidth && self.options.maxWidth < maxImageWidth) {

0 commit comments

Comments
 (0)