web/data/cubicweb.image.js
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 19 Apr 2013 16:25:45 +0200
branchstable
changeset 8914 e80dfffc2c2a
parent 6215 759cf097f5aa
permissions -rw-r--r--
[facet js] fix reordering of facet check boxes. Closes #2732947 Before this patch, when one select an element, it's moved to the top of the select content. Fine. But when it's later deselected, it stays there instead of moving back to its original location. This patch fixes that by introducing a facetCheckBoxReorder function which properly reorder the whole facet, instead of buggy attempt to locally reorder.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6004
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
jQuery.fn.autoResize = function() {
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
    // remove enforced with / height (by CSS and/or HTML attributes)
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
    this.css("width", "auto").css("height", "auto");
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
    this.removeAttr("width").removeAttr("height"); // Remove
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
    // compute image size / max allowed size to fit screen
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
    var imgHSize = this.width();
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
    var maxHSize = $(window).width() - ($(document).width() - imgHSize);
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
    var imgVSize = this.height();
6010
9d40ee3d0551 [image js] fix image fit screen function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6004
diff changeset
     9
    // we don't mind if content in [content]footer moved out of the screen
9d40ee3d0551 [image js] fix image fit screen function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6004
diff changeset
    10
    var maxVSize = $(window).height() - ($(document).height() - imgVSize) + $('#footer').height() + $('#contentfooter').height();
6004
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
    if (maxHSize > 0 && maxVSize > 0) {
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    12
        // if image don't fit screen, set width or height so that
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    13
        // browser keep img ratio, ensuring the other dimension will
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    14
        // also fit the screen
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    15
        if (imgHSize > maxHSize && ((imgVSize / imgHSize) * maxHSize) <= maxVSize) {
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    16
            this.css("width", maxHSize);
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    17
        } else if (imgVSize > maxVSize && ((imgHSize / imgVSize) * maxVSize) <= maxHSize) {
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    18
            this.css("height", maxVSize);
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    19
        }
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    20
        else {
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    21
            // image already fit in screen, don't scale it up
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    22
        }
6004
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
    } else {
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    24
        // can't fit image in, don't do anything
6004
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
    }
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
};
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
d17d3b34bc12 [image] more handy image resizing using javascript
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
$(document).ready(function() {
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    30
        $("img.contentimage").load(function() {$(this).autoResize()});
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6010
diff changeset
    31
});