(function (d, w) { var lazyPictures = [].slice.call(d.querySelectorAll("picture.lazy")); var manageLaziness = function (lazyPicture) { var lazyImage = lazyPicture.querySelector("img"); lazyImage.src = lazyImage.getAttribute("data-src"); var lazySources = lazyPicture.querySelectorAll("source"); for (var j = 0; j < lazySources.length; j++) { var lazySource = lazySources[j]; lazySource.srcset = lazySource.getAttribute("data-srcset"); } if (w.addEventListener) { var fallbackTimeout = setTimeout(function () { lazyPicture.className = lazyPicture.className.replace("lazy", ""); }, 500); lazyImage.addEventListener("load", function () { lazyPicture.className = lazyPicture.className.replace("lazy", ""); clearTimeout(fallbackTimeout); }); return; } lazyPicture.className = lazyPicture.className.replace("lazy", ""); }; if ("IntersectionObserver" in w) { var lazyImageObserver = new IntersectionObserver(function (entries, observer) { for (var i = 0; i < entries.length; i++) { var entry = entries[i]; if (!entry.isIntersecting) { continue; } var lazyPicture = entry.target; manageLaziness(lazyPicture); lazyImageObserver.unobserve(lazyPicture); } }); for (var i = 0; i < lazyPictures.length; i++) { var lazyPicture = lazyPictures[i]; lazyImageObserver.observe(lazyPicture); } } else { var lazyFallback = function () { for (var x = 0; x < lazyPictures.length; x++) { var lazyPicture = lazyPictures[x]; if ((lazyPicture.getBoundingClientRect().top <= w.innerHeight && lazyPicture.getBoundingClientRect().bottom >= 0) && getComputedStyle(lazyPicture).display !== "none") { manageLaziness(lazyPicture); } } if (d.querySelectorAll("picture.lazy").length) { requestAnimationFrame(lazyFallback); } }; requestAnimationFrame(lazyFallback); } }(document, window));