collective / collective.lazysizes

Integration of lazysizes, a lightweight lazy loader, into Plone.
https://pypi.org/project/collective.lazysizes
6 stars 2 forks source link

no images in print layouts #50

Closed thet closed 6 years ago

thet commented 6 years ago

when printing a page, there are no images because the plone.transformchain transform removes all images from the src-tag and for print no javascript is adding it back.

@hvelarde do you have a solution to this problem?

thet commented 6 years ago

The print plugin is the answer: https://github.com/aFarkas/lazysizes/tree/gh-pages/plugins/print I'll integrate it, probably prepare a pull request and close this once I have it working and documented.

thet commented 6 years ago

For the records: the issue might be not solved with the print plugin: https://github.com/aFarkas/lazysizes/issues/308 I'm experiencing similar problems for a client project. However, at least we have a partial solution.

hvelarde commented 6 years ago

maybe the print plugin needs some love; seems that it doesn't work if you don't do the scroll.

snj commented 5 years ago

Not a smart way, but I was able to work around this problem by:

function sleep(waitSec, callbackFunc) {
  var spanedSec = 0;
  var waitFunc = function () {
      spanedSec++;
      if (spanedSec >= waitSec) {
          if (callbackFunc) callbackFunc();
          return;
      }

      clearTimeout(id);
      id = setTimeout(waitFunc, 1000);
  };
  var id = setTimeout(waitFunc, 1000);
}

function unveilAndPrint() {
  var ctr = 0;
  document.querySelectorAll('img.lazyload').forEach(function(v, k, array) {
    lazySizes.loader.unveil(v);
    ctr++;
    if (ctr === array.length) {
      sleep(1, function() {
        window.print();
        ctr = 0;
      });
    }
  });
}