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.5 KiB
2 lines
1.5 KiB
/*! echo.js v1.6.0 | (c) 2014 @toddmotto | https://github.com/toddmotto/echo */ |
|
!function(t,e){"function"==typeof define&&define.amd?define(function(){return e(t)}):"object"==typeof exports?module.exports=e:t.echo=e(t)}(this,function(t){"use strict";var e,n,o,r,c,i,a={},l=function(){},d=function(t,e){var n=t.getBoundingClientRect();return n.right>=e.l&&n.bottom>=e.t&&n.left<=e.r&&n.top<=e.b},u=function(){(r||!n)&&(clearTimeout(n),n=setTimeout(function(){a.render(),n=null},o))};return a.init=function(n){n=n||{};var d=n.offset||0,f=n.offsetVertical||d,s=n.offsetHorizontal||d,h=function(t,e){return parseInt(t||e,10)};e={t:h(n.offsetTop,f),b:h(n.offsetBottom,f),l:h(n.offsetLeft,s),r:h(n.offsetRight,s)},o=h(n.throttle,250),r=n.debounce!==!1,c=!!n.unload,l=n.callback||l,i=n.container||t,a.render(),document.addEventListener?(t.addEventListener("scroll",u,!1),t.addEventListener("load",u,!1)):(t.attachEvent("onscroll",u),t.attachEvent("onload",u))},a.render=function(){for(var t,n,o=document.querySelectorAll("img[data-echo]"),r=o.length,u={l:0-e.l,t:0-e.t,b:(i.innerHeight||i.clientHeight)+e.b,r:(i.innerWidth||i.clientWidth)+e.r},f=0;r>f;f++)n=o[f],d(n,u)?(c&&n.setAttribute("data-echo-placeholder",n.src),n.src=n.getAttribute("data-echo"),c||n.removeAttribute("data-echo"),l(n,"load")):c&&(t=n.getAttribute("data-echo-placeholder"))&&(n.src=t,n.removeAttribute("data-echo-placeholder"),l(n,"unload"));r||a.detach()},a.detach=function(){document.removeEventListener?t.removeEventListener("scroll",u):t.detachEvent("onscroll",u),clearTimeout(n)},a}); |