[image js] fix image fit screen function stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 26 Jul 2010 12:06:58 +0200
branchstable
changeset 6010 9d40ee3d0551
parent 6009 9633d2376687
child 6011 b5f15098f282
[image js] fix image fit screen function
web/data/cubicweb.image.js
--- a/web/data/cubicweb.image.js	Mon Jul 26 12:06:55 2010 +0200
+++ b/web/data/cubicweb.image.js	Mon Jul 26 12:06:58 2010 +0200
@@ -7,18 +7,22 @@
     var imgHSize = this.width();
     var maxHSize = $(window).width() - ($(document).width() - imgHSize);
     var imgVSize = this.height();
-    var maxVSize = $(window).height() - ($(document).height() - imgVSize);
+    // we don't mind if content in [content]footer moved out of the screen
+    var maxVSize = $(window).height() - ($(document).height() - imgVSize) + $('#footer').height() + $('#contentfooter').height();
     if (maxHSize > 0 && maxVSize > 0) {
 	// if image don't fit screen, set width or height so that
 	// browser keep img ratio, ensuring the other dimension will
 	// also fit the screen
-	if (imgHSize > maxHSize && ((maxHSize / maxVSize) * imgVSize) < maxVSize) {
+	if (imgHSize > maxHSize && ((imgVSize / imgHSize) * maxHSize) <= maxVSize) {
 	    this.css("width", maxHSize);
-	} else if (imgVSize > maxVSize && ((maxVSize / maxHSize) * imgHSize) < maxHSize) {
+	} else if (imgVSize > maxVSize && ((imgHSize / imgVSize) * maxVSize) <= maxHSize) {
 	    this.css("height", maxVSize);
-	} // else image already fit in screen, don't scale it up
+	}
+	else {
+	    // image already fit in screen, don't scale it up
+	}
     } else {
-	// XXX can't fit image, don't do anything
+	// can't fit image in, don't do anything
     }
 };