italia2024
Version:
Italia 2024 assets
1 lines • 984 B
JavaScript
function getSourceForBreakpoint(e){const t=window.innerWidth;let o="SOURCE"===e.tagName?"srcset":"src";for(let e=BREAKPOINTS.length-1;e>=0;e--)if(t>BREAKPOINTS[e]){o=`${o}${BREAKPOINTS[e]}`;break}return e.dataset[o]||e.getAttribute(o)}function updateVideoSources(e,t){let o=e.querySelector("source");o||(o=document.createElement("source"),e.appendChild(o)),o.src=t}const BREAKPOINTS=[0,432,744,768,960,1200].sort((e,t)=>e-t);document.addEventListener("DOMContentLoaded",function(){const e=[].slice.call(document.querySelectorAll("img.lazy, iframe.lazy, embed.lazy, object.lazy, video.lazy"));if("IntersectionObserver"in window){const t=new IntersectionObserver(function(e){e.forEach(function(e){if(e.isIntersecting){const o=e.target,r=getSourceForBreakpoint(o);r?("VIDEO"===o.tagName?(updateVideoSources(o,r),o.load()):o.src=r,o.classList.remove("lazy"),t.unobserve(o)):console.warn("No source found for element:",o)}})},{rootMargin:"0px",threshold:.1});e.forEach(e=>t.observe(e))}});