From bcc5af2bfb556b693838a8a61f78549bd3a9946a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 12 Apr 2015 14:49:08 +0200 Subject: [PATCH] Work-around for Firefox returning bogus values for image dimensions --- wcfsetup/install/files/js/WCF.ImageViewer.js | 25 +++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.ImageViewer.js b/wcfsetup/install/files/js/WCF.ImageViewer.js index 42b72a0ac8..38e72bc292 100644 --- a/wcfsetup/install/files/js/WCF.ImageViewer.js +++ b/wcfsetup/install/files/js/WCF.ImageViewer.js @@ -738,13 +738,23 @@ $.widget('ui.wcfImageViewer', { } if (this.options.staticViewer && !imageData.image.height && $image[0].complete) { - $image.css({ - height: 'auto', - width: 'auto' - }); - - imageData.image.height = $image[0].height; - imageData.image.width = $image[0].width; + // Firefox returns bogus values if attempting to read the real dimensions + if ($.browser.mozilla) { + var $img = new Image(); + $img.src = imageData.image.url; + + imageData.image.height = $img.height; + imageData.image.width = $img.width; + } + else { + $image.css({ + height: 'auto', + width: 'auto' + }); + + imageData.image.height = $image[0].height; + imageData.image.width = $image[0].width; + } } var $height = imageData.image.height; @@ -766,7 +776,6 @@ $.widget('ui.wcfImageViewer', { } var $left = Math.floor((containerDimensions.width - $width) / 2); - this._ui.images[targetIndex].css({ height: $height + 'px', left: ($left + 10) + 'px', -- 2.20.1