1+function ($) { 2 "use strict"; 3 4 $(function () { 5 /** @type {{forEach: function(function(Element, number?, any?):void):void}} */ 6 var lazyloadBgImages = document.querySelectorAll('.section-lazy'); 7 if (!('forEach' in lazyloadBgImages)) { 8 // Have to convert nodeList to array because not all supported browsers have a 'forEach' on NodeLists 9 lazyloadBgImages = $.makeArray(lazyloadBgImages); 10 } 11 /** @type {function (Element, number?): void} */ 12 var nodeAction; 13 14 /** 15 * @param {Element} section 16 */ 17 function removeClass(section) { 18 section.classList.remove('section-lazy'); 19 } 20 21 if ('IntersectionObserver' in window) { 22 nodeAction = (function () { 23 var imageObserver = new IntersectionObserver(watcher, {rootMargin: '0px 0px 134% 0px'}); 24 function watcher(entries, observer) { 25 entries.forEach(function (entry) { 26 if (entry.isIntersecting || entry.intersectionRatio !== 0) { 27 var section = entry.target; 28 removeClass(section); 29 observer.unobserve(section); 30 } 31 }); 32 } 33 34 return function (image) { 35 imageObserver.observe(image); 36 }; 37 })(); 38 } else { 39 nodeAction = (function () { 40 var count = 0, autoLoadDistance = window.innerHeight * 2; 41 /** @type {function (Element?): boolean} */ 42 var isInView = function (el) { 43 var inView = autoLoadDistance >= el.getBoundingClientRect().top; 44 // Reduce Repaint calculations if out of view by caching result, since we are traversing linearly 45 if (!inView) isInView = alwaysFalse; 46 return inView; 47 }; 48 function alwaysFalse() { return false; } 49 50 return function (el) { 51 if (isInView(el)) { 52 removeClass(el); 53 } else { 54 setTimeout(function () {removeClass(el);}, (count += 1) * 300); 55 } 56 }; 57 })(); 58 } 59 60 lazyloadBgImages.forEach(nodeAction); 61 }) 62}(window.jQuery);
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.