web/data/cubicweb.image.js
author Julien Cristau <julien.cristau@logilab.fr>
Thu, 10 Dec 2015 16:58:45 +0100
changeset 10997 da712d3f0601
parent 6215 759cf097f5aa
permissions -rw-r--r--
Bring back the separate web-side entity cache Prior to changeset 635cfac73d28 "[repoapi] fold ClientConnection into Connection", we had two entity caches: one on the client/dbapi/web side, and one on the server/repo side. This is a waste, but it is actually needed as long as we have the magic _cw attribute on entities which must sometimes be a request and sometimes a cnx. Removing the duplication caused weird problems with entity._cw alternating between both types of objects, which is unexpected by both the repo and the web sides. We add an entity cache on ConnectionCubicWebRequestBase, separate from the Connection's, and bring back the _cw_update_attr_cache/dont-cache-attrs mechanism, to let the server/edition code let caches know which attributes have been modified Entity.as_rset can be cached again, as ResultSet no longer modifies the entity when fetching it from a cache. Contrary to the pre-3.21 code, _cw_update_attr_cache now handles web requests and connections in the same way (otherwise the cache ends up with wrong values if a hook modifies attributes), but dont-cache-attrs is never set for (inlined) relations. Closes #6863543
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
});