web/data/cubicweb.image.js
author Julien Jehannet <julien.jehannet@logilab.fr>
Fri, 28 Jan 2011 16:08:40 +0100
branchstable
changeset 6919 8fd6921f3e7c
parent 6215 759cf097f5aa
permissions -rw-r--r--
[selectors] modify workflow selectors: is_in_state, on_transition - factorize `is_on_state` selector - add new `on_transition` selector Especially useful to match pending transitions to enable notifications when your workflow allows several transition to the same states. Note that if workflow `change_state` adapter method is used, this selector will not be triggered. In debug mode: These both selectors will check against the entity current workflow if expected values given in selector argument are valid. ValueError exception will be raised for unmatching state/transition names against the current workflow (generic etype workflow). (check against custom workflow is not implemented)
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
});