1(function (global, factory) { 2 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 3 typeof define === 'function' && define.amd ? define(factory) : 4 (global.lozad = factory()); 5}(this, (function () { 'use strict'; 6 7 var isIE = typeof document !== 'undefined' && document.documentMode; 8 9 var defaultConfig = { 10 rootMargin: '0px', 11 threshold: 0, 12 load: function load(element) { 13 if (element.nodeName.toLowerCase() === 'picture') { 14 var img = document.createElement('img'); 15 if (isIE && element.getAttribute('data-iesrc')) { 16 img.src = element.getAttribute('data-iesrc'); 17 } 18 19 if (element.getAttribute('data-alt')) { 20 img.alt = element.getAttribute('data-alt'); 21 } 22 23 element.append(img); 24 } 25 26 if (element.nodeName.toLowerCase() === 'video' && !element.getAttribute('data-src')) { 27 if (element.children) { 28 var childs = element.children; 29 var childSrc = void 0; 30 for (var i = 0; i <= childs.length - 1; i++) { 31 childSrc = childs[i].getAttribute('data-src'); 32 if (childSrc) { 33 childs[i].src = childSrc; 34 } 35 } 36 37 element.load(); 38 } 39 } 40 41 if (element.getAttribute('data-poster')) { 42 element.poster = element.getAttribute('data-poster'); 43 } 44 45 if (element.getAttribute('data-src')) { 46 element.src = element.getAttribute('data-src'); 47 } 48 49 if (element.getAttribute('data-srcset')) { 50 element.setAttribute('srcset', element.getAttribute('data-srcset')); 51 } 52 53 if (element.getAttribute('data-background-image')) { 54 element.style.backgroundImage = 'url(\'' + element.getAttribute('data-background-image').split(',').join('\'),url(\'') + '\')'; 55 } else if (element.getAttribute('data-background-image-set')) { 56 var imageSetLinks = element.getAttribute('data-background-image-set').split(','); 57 var firstUrlLink = imageSetLinks[0].substr(0, imageSetLinks[0].indexOf(' ')) || imageSetLinks[0]; // Substring before ... 1x
vendor: 3,115 bytes, lines 58-167
58 firstUrlLink = firstUrlLink.indexOf('url(') === -1 ? 'url(' + firstUrlLink + ')' : firstUrlLink; 59 if (imageSetLinks.length === 1) { 60 element.style.backgroundImage = firstUrlLink; 61 } else { 62 element.setAttribute('style', (element.getAttribute('style') || '') + ('background-image: ' + firstUrlLink + '; background-image: -webkit-image-set(' + imageSetLinks + '); background-image: image-set(' + imageSetLinks + ')')); 63 } 64 } 65 66 if (element.getAttribute('data-toggle-class')) { 67 element.classList.toggle(element.getAttribute('data-toggle-class')); 68 } 69 }, 70 loaded: function loaded() {} 71 }; 72 73 function markAsLoaded(element) { 74 element.setAttribute('data-loaded', true); 75 } 76 77 var isLoaded = function isLoaded(element) { 78 return element.getAttribute('data-loaded') === 'true'; 79 }; 80 81 var onIntersection = function onIntersection(load, loaded) { 82 return function (entries, observer) { 83 entries.forEach(function (entry) { 84 if (entry.intersectionRatio > 0 || entry.isIntersecting) { 85 observer.unobserve(entry.target); 86 87 if (!isLoaded(entry.target)) { 88 load(entry.target); 89 markAsLoaded(entry.target); 90 loaded(entry.target); 91 } 92 } 93 }); 94 }; 95 }; 96 97 var getElements = function getElements(selector) { 98 var root = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document; 99 100 if (selector instanceof Element) { 101 return [selector]; 102 } 103 104 if (selector instanceof NodeList) { 105 return selector; 106 } 107 108 return root.querySelectorAll(selector); 109 }; 110 111 function lozad () { 112 var selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.lozad'; 113 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 114 115 var _Object$assign = Object.assign({}, defaultConfig, options), 116 root = _Object$assign.root, 117 rootMargin = _Object$assign.rootMargin, 118 threshold = _Object$assign.threshold, 119 load = _Object$assign.load, 120 loaded = _Object$assign.loaded; 121 122 var observer = void 0; 123 124 if (typeof window !== 'undefined' && window.IntersectionObserver) { 125 observer = new IntersectionObserver(onIntersection(load, loaded), { 126 root: root, 127 rootMargin: rootMargin, 128 threshold: threshold 129 }); 130 } 131 132 return { 133 observe: function observe() { 134 var elements = getElements(selector, root); 135 136 for (var i = 0; i < elements.length; i++) { 137 if (isLoaded(elements[i])) { 138 continue; 139 } 140 141 if (observer) { 142 observer.observe(elements[i]); 143 continue; 144 } 145 146 load(elements[i]); 147 markAsLoaded(elements[i]); 148 loaded(elements[i]); 149 } 150 }, 151 triggerLoad: function triggerLoad(element) { 152 if (isLoaded(element)) { 153 return; 154 } 155 156 load(element); 157 markAsLoaded(element); 158 loaded(element); 159 }, 160 161 observer: observer 162 }; 163 } 164 165 return lozad; 166 167})));
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.