1(function() { 2 "use strict"; 3 4 var lazyReadyAttribute = "data-jzl-lazy-ready"; 5 var intersectAttribute = "data-jzl-intersect"; 6 7 function JazelIntersectionObserver(onLoadHandler) { 8 9 this._io = undefined; 10 this._loadCallback = function() {}; 11 12 if (!('IntersectionObserver' in window) || onLoadHandler == null) { 13 this._io = null; 14 } else { 15 var config = { 16 rootMargin: '50px 50px', 17 threshold: 0.01 18 }; 19 this._loadCallback = onLoadHandler; 20 var _this = this; 21 this._io = new IntersectionObserver(function(entries) { 22 _this.onIntersection(entries); 23 }, config); 24 } 25 26 } 27 28 Object.assign(JazelIntersectionObserver.prototype, { 29 getInstance: function() { 30 return this._io; 31 }, 32 observe: function(node) { 33 this._io.observe(node); 34 }, 35 unobserve: function(node) { 36 this._io.unobserve(node); 37 }, 38 onIntersection: function(entries) { 39 // Loop through the entries 40 for (var i = 0; i < entries.length; i++) { 41 var entry = entries[i]; 42 // Are we in viewport? 43 if (entry.intersectionRatio > 0) { 44 entry.target.setAttribute(intersectAttribute, "true"); 45 var readyAttributeValue = entry.target.getAttribute(lazyReadyAttribute); 46 var isReady; 47 if (readyAttributeValue != null && readyAttributeValue !== "") { 48 49 if (readyAttributeValue === "true") { 50 isReady = true; 51 } else if (readyAttributeValue === "false") { 52 isReady = false; 53 } else { 54 console.warn("Unexpected value of " + lazyReadyAttribute + " attribute"); 55 isReady = true; 56 } 57 58 } else { 59 // Default is true 60 isReady = true; 61 } 62 63 if (isReady) { 64 // Stop watching and load the image 65 console.debug("Ready, Loading"); 66 this.unobserveAndLoad(entry.target); 67 } else { 68 console.debug("Not ready, not loading"); 69 } 70 } else { 71 entry.target.removeAttribute(intersectAttribute); 72 } 73 } 74 }, 75 unobserveAndLoad: function(node) { 76 node.removeAttribute(lazyReadyAttribute); 77 node.removeAttribute(intersectAttribute); 78 this._io.unobserve(node); 79 this._loadCallback(node); 80 }, 81 }); 82 83 window.JazelIntersectionObserver = JazelIntersectionObserver; 84 85})();
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.