From 9792c083519b577f9429cbd85abe26557a85eb2c Mon Sep 17 00:00:00 2001 From: RaphaelEidus Date: Wed, 26 Mar 2014 12:00:09 -0400 Subject: [PATCH] add a placeholder param --- dist/echo.js | 10 ++++++---- dist/echo.min.js | 2 +- src/echo.js | 10 ++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/dist/echo.js b/dist/echo.js index 4a4a0df..f461f96 100644 --- a/dist/echo.js +++ b/dist/echo.js @@ -16,9 +16,9 @@ window.Echo = (function (global, document, undefined) { var toBeUnloaded = []; /** - * offsetBot, offsetTop throttle, poll, unload vars + * offsetBot, offsetTop throttle, poll, unload, placeholder vars */ - var offsetBot, offsetTop, throttle, poll, unload; + var offsetBot, offsetTop, throttle, poll, unload, placeholder; /** * _inView @@ -51,7 +51,7 @@ window.Echo = (function (global, document, undefined) { toBeLoaded.splice(i, 1); loadingLength = toBeLoaded.length; i--; - if(unload) { + if(unload && !!placeholder) { toBeUnloaded.push(self); } } @@ -62,7 +62,7 @@ window.Echo = (function (global, document, undefined) { for(i = 0; i < unloadingLength; i++) { self = toBeUnloaded[i]; if (self && !_inView(self)) { - self.src = self.getAttribute('data-echo-holder'); + self.src = placeholder; toBeUnloaded.splice(i, 1); unloadingLength = toBeUnloaded.length; i--; @@ -92,6 +92,7 @@ window.Echo = (function (global, document, undefined) { * @param {Number|String} [obj.offsetBot] * @param {Number|String} [obj.offsetTop] * @param {Boolean} [obj.unload] + * @param {String} [obj.placeholder] */ var init = function (obj) { @@ -102,6 +103,7 @@ window.Echo = (function (global, document, undefined) { offsetTop = parseInt(opts.offsetTop || offset); throttle = parseInt(opts.throttle || 250); unload = !!opts.unload; + placeholder = opts.placeholder; for (var i = 0; i < nodes.length; i++) { toBeLoaded.push(nodes[i]); diff --git a/dist/echo.min.js b/dist/echo.min.js index 79e446c..cdf8bb9 100644 --- a/dist/echo.min.js +++ b/dist/echo.min.js @@ -1,2 +1,2 @@ /*! 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=[],i=[],j=function(a){var e=a.getBoundingClientRect(),f=e.top>=0&&e.left>=0&&e.top<=(window.innerHeight||b.documentElement.clientHeight)+c&&e.top>=-1*d,g=e.bottom>=-1*d&&e.left>=0&&e.bottom<=(window.innerHeight||b.documentElement.clientHeight)+c;return f||g},k=function(){var a,b,c,d=h.length;if(d>0)for(b=0;d>b;b++)c=h[b],c&&j(c)&&(c.src=c.getAttribute("data-echo"),h.splice(b,1),d=h.length,b--,g&&i.push(c));if(a=i.length,a>0)for(b=0;a>b;b++)c=i[b],c&&!j(c)&&(c.src=c.getAttribute("data-echo-holder"),i.splice(b,1),a=i.length,b--,h.push(c));0===a&&0===d&&n()},l=function(){clearTimeout(f),f=setTimeout(k,e)},m=function(f){var i=b.querySelectorAll("[data-echo]"),j=f||{},m=parseInt(j.offset||0);c=parseInt(j.offsetBot||m),d=parseInt(j.offsetTop||m),e=parseInt(j.throttle||250),g=!!j.unload;for(var n=0;n=0&&e.left>=0&&e.top<=(window.innerHeight||b.documentElement.clientHeight)+c&&e.top>=-1*d,g=e.bottom>=-1*d&&e.left>=0&&e.bottom<=(window.innerHeight||b.documentElement.clientHeight)+c;return f||g},l=function(){var a,b,c,d=i.length;if(d>0)for(b=0;d>b;b++)c=i[b],c&&k(c)&&(c.src=c.getAttribute("data-echo"),i.splice(b,1),d=i.length,b--,g&&h&&j.push(c));if(a=j.length,a>0)for(b=0;a>b;b++)c=j[b],c&&!k(c)&&(c.src=h,j.splice(b,1),a=j.length,b--,i.push(c));0===a&&0===d&&o()},m=function(){clearTimeout(f),f=setTimeout(l,e)},n=function(f){var j=b.querySelectorAll("[data-echo]"),k=f||{},n=parseInt(k.offset||0);c=parseInt(k.offsetBot||n),d=parseInt(k.offsetTop||n),e=parseInt(k.throttle||250),g=!!k.unload,h=k.placeholder;for(var o=0;o