[image js] fix image fit screen function

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changeset9d40ee3d0551
branchstable
phasepublic
hiddenno
parent revision#9633d2376687 [idownloadable primary view] when file is an image, display attributes below the image
child revision#b5f15098f282 [debug] when a loop is detected in a tree, log the entity involved in it to ease repair
files modified by this revision
web/data/cubicweb.image.js
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1280138818 -7200
# Mon Jul 26 12:06:58 2010 +0200
# Branch stable
# Node ID 9d40ee3d0551f4a7dea8c6c17e310dbe2ffe618c
# Parent 9633d2376687adcb5bb15c214ddce94051920634
[image js] fix image fit screen function

diff --git a/web/data/cubicweb.image.js b/web/data/cubicweb.image.js
@@ -5,22 +5,26 @@
1      this.removeAttr("width").removeAttr("height"); // Remove
2      // compute image size / max allowed size to fit screen
3      var imgHSize = this.width();
4      var maxHSize = $(window).width() - ($(document).width() - imgHSize);
5      var imgVSize = this.height();
6 -    var maxVSize = $(window).height() - ($(document).height() - imgVSize);
7 +    // we don't mind if content in [content]footer moved out of the screen
8 +    var maxVSize = $(window).height() - ($(document).height() - imgVSize) + $('#footer').height() + $('#contentfooter').height();
9      if (maxHSize > 0 && maxVSize > 0) {
10  	// if image don't fit screen, set width or height so that
11  	// browser keep img ratio, ensuring the other dimension will
12  	// also fit the screen
13 -	if (imgHSize > maxHSize && ((maxHSize / maxVSize) * imgVSize) < maxVSize) {
14 +	if (imgHSize > maxHSize && ((imgVSize / imgHSize) * maxHSize) <= maxVSize) {
15  	    this.css("width", maxHSize);
16 -	} else if (imgVSize > maxVSize && ((maxVSize / maxHSize) * imgHSize) < maxHSize) {
17 +	} else if (imgVSize > maxVSize && ((imgHSize / imgVSize) * maxVSize) <= maxHSize) {
18  	    this.css("height", maxVSize);
19 -	} // else image already fit in screen, don't scale it up
20 +	}
21 +	else {
22 +	    // image already fit in screen, don't scale it up
23 +	}
24      } else {
25 -	// XXX can't fit image, don't do anything
26 +	// can't fit image in, don't do anything
27      }
28  };
29 
30 
31  $(document).ready(function() {