Browse Source

added onRender event to allow users to get a callback before the image source is set

pull/34/head
Erez Mazor 11 years ago
parent
commit
57f776c74f
  1. 6
      dist/echo.js
  2. 2
      dist/echo.min.js
  3. 6
      src/echo.js

6
dist/echo.js vendored

@ -14,6 +14,8 @@ window.Echo = (function (global, document, undefined) {
*/
var offset, throttle, poll;
var onRender;
/**
* _inView
* @private
@ -36,6 +38,9 @@ window.Echo = (function (global, document, undefined) {
for (var i = 0; i < length; i++) {
var self = store[i];
if (self && _inView(self)) {
if(onRender){
onRender(self);
}
self.src = self.getAttribute('data-echo');
store.splice(i, 1);
length = store.length;
@ -73,6 +78,7 @@ window.Echo = (function (global, document, undefined) {
var opts = obj || {};
offset = parseInt(opts.offset || 0);
throttle = parseInt(opts.throttle || 250);
onRender = opts.onRender;
for (var i = 0; i < nodes.length; i++) {
store.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=function(a){var d=a.getBoundingClientRect();return(d.top>=0&&d.left>=0&&d.top)<=(window.innerHeight||b.documentElement.clientHeight)+c},h=function(){var c=f.length;if(c>0)for(var d=0;c>d;d++){var h=f[d];h&&g(h)&&(h.src=h.getAttribute("data-echo"),f.splice(d,1),c=f.length,d--)}else b.removeEventListener?a.removeEventListener("scroll",i):a.detachEvent("onscroll",i),clearTimeout(e)},i=function(){clearTimeout(e),e=setTimeout(h,d)},j=function(e){var g=b.querySelectorAll("[data-echo]"),j=e||{};c=parseInt(j.offset||0),d=parseInt(j.throttle||250);for(var k=0;k<g.length;k++)f.push(g[k]);h(),b.addEventListener?(a.addEventListener("scroll",i,!1),a.addEventListener("load",i,!1)):(a.attachEvent("onscroll",i),a.attachEvent("onload",i))};return{init:j,render:h}}(this,document);
window.Echo=function(a,b){"use strict";var c,d,e,f,g=[],h=function(a){var d=a.getBoundingClientRect();return(d.top>=0&&d.left>=0&&d.top)<=(window.innerHeight||b.documentElement.clientHeight)+c},i=function(){var c=g.length;if(c>0)for(var d=0;c>d;d++){var i=g[d];i&&h(i)&&(f&&f(i),i.src=i.getAttribute("data-echo"),g.splice(d,1),c=g.length,d--)}else b.removeEventListener?a.removeEventListener("scroll",j):a.detachEvent("onscroll",j),clearTimeout(e)},j=function(){clearTimeout(e),e=setTimeout(i,d)},k=function(e){var h=b.querySelectorAll("[data-echo]"),k=e||{};c=parseInt(k.offset||0),d=parseInt(k.throttle||250),f=k.onRender;for(var l=0;l<h.length;l++)g.push(h[l]);i(),b.addEventListener?(a.addEventListener("scroll",j,!1),a.addEventListener("load",j,!1)):(a.attachEvent("onscroll",j),a.attachEvent("onload",j))};return{init:k,render:i}}(this,document);

6
src/echo.js

@ -13,6 +13,8 @@ window.Echo = (function (global, document, undefined) {
*/
var offset, throttle, poll;
var onRender;
/**
* _inView
* @private
@ -35,6 +37,9 @@ window.Echo = (function (global, document, undefined) {
for (var i = 0; i < length; i++) {
var self = store[i];
if (self && _inView(self)) {
if(onRender){
onRender(self);
}
self.src = self.getAttribute('data-echo');
store.splice(i, 1);
length = store.length;
@ -72,6 +77,7 @@ window.Echo = (function (global, document, undefined) {
var opts = obj || {};
offset = parseInt(opts.offset || 0);
throttle = parseInt(opts.throttle || 250);
onRender = opts.onRender;
for (var i = 0; i < nodes.length; i++) {
store.push(nodes[i]);

Loading…
Cancel
Save