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