X-Git-Url: https://scm.cri.minesparis.psl.eu/git/Portfolio.git/blobdiff_plain/2e2f4ddd5166f4ddc77c688040cc697f84dbfcf1..8ead6f1e3deb946c8ff614793f1637fe0e26efa0:/skins/photo_film_viewer.js?ds=sidebyside

diff --git a/skins/photo_film_viewer.js b/skins/photo_film_viewer.js
index b86e94d..fa929b2 100644
--- a/skins/photo_film_viewer.js
+++ b/skins/photo_film_viewer.js
@@ -5,7 +5,6 @@ Licence Creative Commons http://creativecommons.org/licenses/by-nc/2.0/
 */
 
 var FilmSlider;
-
 (function(){
 
 var keyLeft = 37, keyRight = 39;
@@ -186,6 +185,7 @@ FilmSlider.prototype._fitToScreen = function(evt) {
 		var src = this.image.src.replace(imgRequestedSize, 'size=' + bestFitSize);
 		this.pendingImage.src = src;
 	}
+	this.adjustImage(this.image);
 };
 
 FilmSlider.prototype.getBestFitSize = function(ratio) {
@@ -210,6 +210,27 @@ FilmSlider.prototype.getBestFitSize = function(ratio) {
 	return DEFAULT_IMAGE_SIZES[i];
 };
 
+FilmSlider.prototype.adjustImage = function(img) {
+	var dispWidth = parseInt(this.stretchable.style.width, 10);
+	var imgWidth = img.naturalWidth;
+	var dispHeight = parseInt(this.stretchable.style.height, 10);
+	var imgHeight = img.naturalHeight;
+	var ratio;
+
+	if (imgHeight > dispHeight) {
+		ratio = dispHeight / imgHeight;
+		imgWidth = imgWidth * ratio;
+		imgHeight = dispHeight;
+	}
+	if (imgWidth > dispWidth) {
+		ratio = dispWidth / imgWidth;
+		imgHeight = imgHeight * ratio;
+		imgWidth = dispWidth;
+	}
+	img.width = imgWidth;
+	img.height = imgHeight;
+};
+
 if (!browser.isMobile) {
 	FilmSlider.prototype.centerSlide = function(slideIndex) {
 		if (this.sliderRatio > 1) { return; }
@@ -721,6 +742,7 @@ FilmSlider.prototype.populateViewer = function(req) {
 };
 
 FilmSlider.prototype.refreshImage = function() {
+	this.adjustImage(this.pendingImage);
 	this.image.style.visibility = 'hidden';
 	this.image.src = this.pendingImage.src;
 	this.image.width = this.pendingImage.width;