|
265 | 265 | // Hide most UI elements in preparation for the animated resizing of the lightbox.
|
266 | 266 | Lightbox.prototype.changeImage = function(imageNumber) {
|
267 | 267 | var self = this;
|
| 268 | + var filename = this.album[imageNumber].link; |
| 269 | + var filetype = filename.split('.').slice(-1)[0]; |
268 | 270 |
|
269 | 271 | this.disableKeyboardNav();
|
270 | 272 | var $image = this.$lightbox.find('.lb-image');
|
|
289 | 291 |
|
290 | 292 | $image.attr({
|
291 | 293 | 'alt': self.album[imageNumber].alt,
|
292 |
| - 'src': self.album[imageNumber].link |
| 294 | + 'src': filename |
293 | 295 | });
|
294 | 296 |
|
295 | 297 | $preloader = $(preloader);
|
296 | 298 |
|
297 | 299 | $image.width(preloader.width);
|
298 | 300 | $image.height(preloader.height);
|
| 301 | + windowWidth = $(window).width(); |
| 302 | + windowHeight = $(window).height(); |
299 | 303 |
|
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. |
303 | 312 |
|
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) { |
308 | 325 |
|
309 | 326 | // Check if image size is larger then maxWidth|maxHeight in settings
|
310 | 327 | if (self.options.maxWidth && self.options.maxWidth < maxImageWidth) {
|
|
0 commit comments