mirror of https://github.com/toddmotto/echo.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
1.4 KiB
2 lines
1.4 KiB
/*! Echo v1.5.0 | (c) 2014 @toddmotto | MIT license | github.com/toddmotto/echo */ |
|
window.Echo=function(a,b){"use strict";var c,d,e,f,g,h=function(){},i=function(a,b){var c=a.getBoundingClientRect();return c.right>=b.l&&c.bottom>=b.t&&c.left<=b.r&&c.top<=b.b},j=function(){var a,d,g,j,k=b.querySelectorAll("img[data-echo]"),l=k.length;for(e=null,j={l:0-c.l,t:0-c.t,b:(window.innerHeight||b.documentElement.clientHeight)+c.b,r:(window.innerWidth||b.documentElement.clientWidth)+c.r},d=0;l>d;d++)g=k[d],i(g,j)?(f&&g.setAttribute("data-echo-placeholder",g.src),g.src=g.getAttribute("data-echo"),f||g.removeAttribute("data-echo"),h(g,"load")):f&&(a=g.getAttribute("data-echo-placeholder"))&&(g.src=a,g.removeAttribute("data-echo-placeholder"),h(g,"unload"));l||m()},k=function(){(g||!e)&&(clearTimeout(e),e=setTimeout(j,d))},l=function(e){function i(a,b){return parseInt(a||b,10)}e=e||{};var l=e.offset||0,m=e.offsetVertical||l,n=e.offsetHorizontal||l;c={t:i(e.offsetTop,m),b:i(e.offsetBottom,m),l:i(e.offsetLeft,n),r:i(e.offsetRight,n)},d=i(e.throttle,250),f=!!e.unload,g=e.debounce!==!1,h=e.callback||h,j(),b.addEventListener?(a.addEventListener("scroll",k,!1),a.addEventListener("load",k,!1)):(a.attachEvent("onscroll",k),a.attachEvent("onload",k))},m=function(){b.removeEventListener?a.removeEventListener("scroll",k):a.detachEvent("onscroll",k),clearTimeout(e)};return{init:l,detach:m,render:j}}(this,document); |