Work-around for Firefox returning bogus values for image dimensions
authorAlexander Ebert <ebert@woltlab.com>
Sun, 12 Apr 2015 12:49:08 +0000 (14:49 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 12 Apr 2015 12:49:08 +0000 (14:49 +0200)
wcfsetup/install/files/js/WCF.ImageViewer.js

index 42b72a0ac8de8f4f927d9fe0b2889acf1c5be6fb..38e72bc292f581dd4123ae042d30413458d8bc7e 100644 (file)
@@ -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',