From 723488ea9466190b65db39cb4603aa6a86ea0dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Garc=C3=ADa=20G=C3=B3mez?= Date: Mon, 20 Oct 2014 15:46:31 -0300 Subject: [PATCH] Fixed 'unload' option: It was not unloading the loaded image when I scrolled beyond the viewport --- dist/echo.js | 2 +- dist/echo.min.js | 2 +- src/echo.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/echo.js b/dist/echo.js index 7a5efed..c4fa5b7 100644 --- a/dist/echo.js +++ b/dist/echo.js @@ -76,7 +76,7 @@ for (var i = 0; i < length; i++) { elem = nodes[i]; if (inView(elem, view)) { - if (unload) { + if (unload && !(src = elem.getAttribute('data-echo-placeholder'))) { elem.setAttribute('data-echo-placeholder', elem.src); } elem.src = elem.getAttribute('data-echo'); diff --git a/dist/echo.min.js b/dist/echo.min.js index d654ac5..17b94e0 100644 --- a/dist/echo.min.js +++ b/dist/echo.min.js @@ -1,2 +1,2 @@ /*! 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={},l=function(){},a=function(t,e){var n=t.getBoundingClientRect();return n.right>=e.l&&n.bottom>=e.t&&n.left<=e.r&&n.top<=e.b},d=function(){(r||!n)&&(clearTimeout(n),n=setTimeout(function(){i.render(),n=null},o))};return i.init=function(n){n=n||{};var a=n.offset||0,u=n.offsetVertical||a,f=n.offsetHorizontal||a,s=function(t,e){return parseInt(t||e,10)};e={t:s(n.offsetTop,u),b:s(n.offsetBottom,u),l:s(n.offsetLeft,f),r:s(n.offsetRight,f)},o=s(n.throttle,250),r=n.debounce!==!1,c=!!n.unload,l=n.callback||l,i.render(),document.addEventListener?(t.addEventListener("scroll",d,!1),t.addEventListener("load",d,!1)):(t.attachEvent("onscroll",d),t.attachEvent("onload",d))},i.render=function(){for(var n,o,r=document.querySelectorAll("img[data-echo]"),d=r.length,u={l:0-e.l,t:0-e.t,b:(t.innerHeight||document.documentElement.clientHeight)+e.b,r:(t.innerWidth||document.documentElement.clientWidth)+e.r},f=0;d>f;f++)o=r[f],a(o,u)?(c&&o.setAttribute("data-echo-placeholder",o.src),o.src=o.getAttribute("data-echo"),c||o.removeAttribute("data-echo"),l(o,"load")):c&&(n=o.getAttribute("data-echo-placeholder"))&&(o.src=n,o.removeAttribute("data-echo-placeholder"),l(o,"unload"));d||i.detach()},i.detach=function(){document.removeEventListener?t.removeEventListener("scroll",d):t.detachEvent("onscroll",d),clearTimeout(n)},i}); \ No newline at end of file +!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=function(){},l=function(t,e){var n=t.getBoundingClientRect();return n.right>=e.l&&n.bottom>=e.t&&n.left<=e.r&&n.top<=e.b},d=function(){(r||!n)&&(clearTimeout(n),n=setTimeout(function(){i.render(),n=null},o))};return i.init=function(n){n=n||{};var l=n.offset||0,u=n.offsetVertical||l,f=n.offsetHorizontal||l,s=function(t,e){return parseInt(t||e,10)};e={t:s(n.offsetTop,u),b:s(n.offsetBottom,u),l:s(n.offsetLeft,f),r:s(n.offsetRight,f)},o=s(n.throttle,250),r=n.debounce!==!1,c=!!n.unload,a=n.callback||a,i.render(),document.addEventListener?(t.addEventListener("scroll",d,!1),t.addEventListener("load",d,!1)):(t.attachEvent("onscroll",d),t.attachEvent("onload",d))},i.render=function(){for(var n,o,r=document.querySelectorAll("img[data-echo]"),d=r.length,u={l:0-e.l,t:0-e.t,b:(t.innerHeight||document.documentElement.clientHeight)+e.b,r:(t.innerWidth||document.documentElement.clientWidth)+e.r},f=0;d>f;f++)o=r[f],l(o,u)?(c&&!(n=o.getAttribute("data-echo-placeholder"))&&o.setAttribute("data-echo-placeholder",o.src),o.src=o.getAttribute("data-echo"),c||o.removeAttribute("data-echo"),a(o,"load")):c&&(n=o.getAttribute("data-echo-placeholder"))&&(o.src=n,o.removeAttribute("data-echo-placeholder"),a(o,"unload"));d||i.detach()},i.detach=function(){document.removeEventListener?t.removeEventListener("scroll",d):t.detachEvent("onscroll",d),clearTimeout(n)},i}); \ No newline at end of file diff --git a/src/echo.js b/src/echo.js index 5b14b29..60b81c2 100644 --- a/src/echo.js +++ b/src/echo.js @@ -75,7 +75,7 @@ for (var i = 0; i < length; i++) { elem = nodes[i]; if (inView(elem, view)) { - if (unload) { + if (unload && !(src = elem.getAttribute('data-echo-placeholder'))) { elem.setAttribute('data-echo-placeholder', elem.src); } elem.src = elem.getAttribute('data-echo');