vendor: 3,823 bytes, lines 1-135
1/*! echo-js v1.7.3 | (c) 2016 @toddmotto | https://github.com/toddmotto/echo */ 2(function (root, factory) { 3 if (typeof define === 'function' && define.amd) { 4 define(function() { 5 return factory(root); 6 }); 7 } else if (typeof exports === 'object') { 8 module.exports = factory; 9 } else { 10 root.echo = factory(root); 11 } 12})(this, function (root) { 13 14 'use strict'; 15 16 var echo = {}; 17 18 var callback = function () {}; 19 20 var offset, poll, delay, useDebounce, unload; 21 22 var isHidden = function (element) { 23 return (element.offsetParent === null); 24 }; 25 26 var inView = function (element, view) { 27 if (isHidden(element)) { 28 return false; 29 } 30 31 var box = element.getBoundingClientRect(); 32 return (box.right >= view.l && box.bottom >= view.t && box.left <= view.r && box.top <= view.b); 33 }; 34 35 var debounceOrThrottle = function () { 36 if(!useDebounce && !!poll) { 37 return; 38 } 39 clearTimeout(poll); 40 poll = setTimeout(function(){ 41 echo.render(); 42 poll = null; 43 }, delay); 44 }; 45 46 echo.init = function (opts) { 47 opts = opts || {}; 48 var offsetAll = opts.offset || 0; 49 var offsetVertical = opts.offsetVertical || offsetAll; 50 var offsetHorizontal = opts.offsetHorizontal || offsetAll; 51 var optionToInt = function (opt, fallback) { 52 return parseInt(opt || fallback, 10); 53 }; 54 offset = { 55 t: optionToInt(opts.offsetTop, offsetVertical), 56 b: optionToInt(opts.offsetBottom, offsetVertical), 57 l: optionToInt(opts.offsetLeft, offsetHorizontal), 58 r: optionToInt(opts.offsetRight, offsetHorizontal) 59 }; 60 delay = optionToInt(opts.throttle, 250); 61 useDebounce = opts.debounce !== false; 62 unload = !!opts.unload; 63 callback = opts.callback || callback; 64 echo.render(); 65 if (document.addEventListener) { 66 root.addEventListener('scroll', debounceOrThrottle, false); 67 root.addEventListener('load', debounceOrThrottle, false); 68 } else { 69 root.attachEvent('onscroll', debounceOrThrottle); 70 root.attachEvent('onload', debounceOrThrottle); 71 } 72 }; 73 74 echo.render = function (context) { 75 var nodes = (context || document).querySelectorAll('[data-echo], [data-echo-background]'); 76 var length = nodes.length; 77 var src, elem; 78 var view = { 79 l: 0 - offset.l, 80 t: 0 - offset.t, 81 b: (root.innerHeight || document.documentElement.clientHeight) + offset.b, 82 r: (root.innerWidth || document.documentElement.clientWidth) + offset.r 83 }; 84 for (var i = 0; i < length; i++) { 85 elem = nodes[i]; 86 if (inView(elem, view)) { 87 88 if (unload) { 89 elem.setAttribute('data-echo-placeholder', elem.src); 90 } 91 92 if (elem.getAttribute('data-echo-background') !== null) { 93 elem.style.backgroundImage = 'url(' + elem.getAttribute('data-echo-background') + ')'; 94 } 95 else if (elem.src !== (src = elem.getAttribute('data-echo'))) { 96 elem.src = src; 97 } 98 99 if (!unload) { 100 elem.removeAttribute('data-echo'); 101 elem.removeAttribute('data-echo-background'); 102 } 103 104 callback(elem, 'load'); 105 } 106 else if (unload && !!(src = elem.getAttribute('data-echo-placeholder'))) { 107 108 if (elem.getAttribute('data-echo-background') !== null) { 109 elem.style.backgroundImage = 'url(' + src + ')'; 110 } 111 else { 112 elem.src = src; 113 } 114 115 elem.removeAttribute('data-echo-placeholder'); 116 callback(elem, 'unload'); 117 } 118 } 119 if (!length) { 120 echo.detach(); 121 } 122 }; 123 124 echo.detach = function () { 125 if (document.removeEventListener) { 126 root.removeEventListener('scroll', debounceOrThrottle); 127 } else { 128 root.detachEvent('onscroll', debounceOrThrottle); 129 } 130 clearTimeout(poll); 131 }; 132 133 return echo; 134 135});
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.