1// Passive event listeners 2 jQuery.event.special.touchstart = { 3 setup: function( _, ns, handle ) { 4 this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") }); 5 } 6 }; 7 jQuery.event.special.touchmove = { 8 setup: function( _, ns, handle ) { 9 this.addEventListener("touchmove", handle, { passive: !ns.includes("noPreventDefault") }); 10 } 11 }; 12 13( function() { 'use strict'; 14 let images = document.querySelectorAll('img[data-src]'); 15 16 document.addEventListener('DOMContentLoaded', onReady); 17 function onReady() { 18 // Show above-the-fold images first 19 showImagesOnView(); 20 21 // scroll listener 22 window.addEventListener( 'scroll', showImagesOnView, false ); 23 } 24 25 // Show the image if reached on viewport 26 function showImagesOnView( e ) { 27 28 for( let i of images ) { 29 if( i.getAttribute('src') ) { continue; } // SKIP if already displayed 30 31 // Compare the position of image and scroll 32 let bounding = i.getBoundingClientRect(); 33 let isOnView = bounding.top >= 0 && 34 bounding.left >= 0 && 35 bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) && 36 bounding.right <= (window.innerWidth || document.documentElement.clientWidth); 37 38 if( isOnView ) { 39 i.setAttribute( 'src', i.dataset.src ); 40 if( i.getAttribute('data-srcset') ) { 41 i.setAttribute( 'srcset', i.dataset.srcset ); 42 } 43 } 44 } 45 } 46 47})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.