web/data/cubicweb.image.js
branchstable
changeset 6004 d17d3b34bc12
child 6010 9d40ee3d0551
equal deleted inserted replaced
6003:5fbc1c4c13ff 6004:d17d3b34bc12
       
     1 
       
     2 jQuery.fn.autoResize = function() {
       
     3     // remove enforced with / height (by CSS and/or HTML attributes)
       
     4     this.css("width", "auto").css("height", "auto");
       
     5     this.removeAttr("width").removeAttr("height"); // Remove
       
     6     // compute image size / max allowed size to fit screen
       
     7     var imgHSize = this.width();
       
     8     var maxHSize = $(window).width() - ($(document).width() - imgHSize);
       
     9     var imgVSize = this.height();
       
    10     var maxVSize = $(window).height() - ($(document).height() - imgVSize);
       
    11     if (maxHSize > 0 && maxVSize > 0) {
       
    12 	// if image don't fit screen, set width or height so that
       
    13 	// browser keep img ratio, ensuring the other dimension will
       
    14 	// also fit the screen
       
    15 	if (imgHSize > maxHSize && ((maxHSize / maxVSize) * imgVSize) < maxVSize) {
       
    16 	    this.css("width", maxHSize);
       
    17 	} else if (imgVSize > maxVSize && ((maxVSize / maxHSize) * imgHSize) < maxHSize) {
       
    18 	    this.css("height", maxVSize);
       
    19 	} // else image already fit in screen, don't scale it up
       
    20     } else {
       
    21 	// XXX can't fit image, don't do anything
       
    22     }
       
    23 };
       
    24 
       
    25 
       
    26 $(document).ready(function() {
       
    27 	$("img.contentimage").load(function() {$(this).autoResize()});
       
    28     });