Browse Source

add a placeholder param

pull/39/head
RaphaelEidus 11 years ago
parent
commit
9792c08351
  1. 10
      dist/echo.js
  2. 2
      dist/echo.min.js
  3. 10
      src/echo.js

10
dist/echo.js vendored

@ -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]);

2
dist/echo.min.js vendored

@ -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<i.length;n++)h.push(i[n]);k(),b.addEventListener?(a.addEventListener("scroll",l,!1),a.addEventListener("load",l,!1)):(a.attachEvent("onscroll",l),a.attachEvent("onload",l))},n=function(){b.removeEventListener?a.removeEventListener("scroll",l):a.detachEvent("onscroll",l),clearTimeout(f)};return{init:m,detach:n,render:k}}(this,document);
window.Echo=function(a,b){"use strict";var c,d,e,f,g,h,i=[],j=[],k=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},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<j.length;o++)i.push(j[o]);l(),b.addEventListener?(a.addEventListener("scroll",m,!1),a.addEventListener("load",m,!1)):(a.attachEvent("onscroll",m),a.attachEvent("onload",m))},o=function(){b.removeEventListener?a.removeEventListener("scroll",m):a.detachEvent("onscroll",m),clearTimeout(f)};return{init:n,detach:o,render:l}}(this,document);

10
src/echo.js

@ -15,9 +15,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
@ -50,7 +50,7 @@ window.Echo = (function (global, document, undefined) {
toBeLoaded.splice(i, 1);
loadingLength = toBeLoaded.length;
i--;
if(unload) {
if(unload && !!placeholder) {
toBeUnloaded.push(self);
}
}
@ -61,7 +61,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--;
@ -91,6 +91,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) {
@ -101,6 +102,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]);

Loading…
Cancel
Save