strues/retinajs

Not possible to apply retinajs() to new images

IlyaSemenov opened this issue · 3 comments

It is not possible to cleanly apply retinajs() to new images (that have been dynamically inserted with javascript after window.load).

The module only exports a single function retinajs() without any parameter, which iterates over all images and tries to fetch the @2x image. For images that have been already processed by previous rethinkjs() call, it dumbly tries @2x@2x images.

It's either that rethinkjs() must mark previously processes images and ignore them on future runs, and/or accept optional parameter images (which could be element, NodeList or array of image elements to process).

Monkey patch

This temporarily overcomes the problem (uses jquery):

<script src="/static/bower/retina.js/dist/retina.min.js"></script>
<script>
    // Monkey patch to allow retinajs run twice
    // See https://github.com/imulus/retinajs/issues/249
    (retinajs = (function(retinajs) {
        return function() {
            retinajs();
            $("[data-rjs]").removeAttr("data-rjs");
        };
    })(retinajs))();
</script>

Ah, great catch! We'll fix this one.

Solved in 2.1.0