Browse Source

Echo v1.1.0, minor event bind enhancement

pull/4/head v1.1.0
Todd Motto 12 years ago
parent
commit
4f173e6fda
  1. 28
      dist/echo.js
  2. 4
      dist/echo.min.js
  3. 4
      package.json
  4. 26
      src/echo.js

28
dist/echo.js vendored

@ -1,6 +1,6 @@
/*! /*!
* Echo * Echo
* @version 1.0.0 * @version 1.1.0
* @author Todd Motto http://toddmotto.com * @author Todd Motto http://toddmotto.com
* Project: https://github.com/toddmotto/echo * Project: https://github.com/toddmotto/echo
* *
@ -16,15 +16,13 @@ window.echo = (function (window, document) {
*/ */
var Echo = function (elem) { var Echo = function (elem) {
this.elem = elem; this.elem = elem;
this.render();
this.listen();
}; };
/* /*
* Images for echoing * Images for echoing
*/ */
var echoStore = []; var echoStore = [];
/* /*
* Element in viewport logic * Element in viewport logic
*/ */
@ -70,16 +68,6 @@ window.echo = (function (window, document) {
Echo.prototype = { Echo.prototype = {
init : function () { init : function () {
echoStore.push(this.elem); echoStore.push(this.elem);
},
render : function () {
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', echoImages, false);
} else {
window.onload = echoImages;
}
},
listen : function () {
window.onscroll = echoImages;
} }
}; };
@ -91,4 +79,14 @@ window.echo = (function (window, document) {
new Echo(lazyImgs[i]).init(); new Echo(lazyImgs[i]).init();
} }
})(window, document); /*
* Bind the events
*/
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', echoImages, false);
} else {
window.onload = echoImages;
}
window.onscroll = echoImages;
})(window, document);

4
dist/echo.min.js vendored

@ -1,10 +1,10 @@
/*! /*!
* Echo * Echo
* @version 1.0.0 * @version 1.1.0
* @author Todd Motto http://toddmotto.com * @author Todd Motto http://toddmotto.com
* Project: https://github.com/toddmotto/echo * Project: https://github.com/toddmotto/echo
* *
* Raw JavaScript lazy-loading images with HTML5 data-* attributes. * Raw JavaScript lazy-loading images with HTML5 data-* attributes.
* Copyright 2013. MIT licensed. * Copyright 2013. MIT licensed.
*/ */
window.echo=function(a,b){"use strict";var c=function(a){this.elem=a,this.render(),this.listen()},d=[],e=function(c){var d=c.getBoundingClientRect();return(d.top>=0&&d.left>=0&&d.top)<=(a.innerHeight||b.documentElement.clientHeight)},f=function(a,b){a.src=a.getAttribute("data-echo"),b&&b()},g=function(a,b){-1!==d.indexOf(a)&&d.splice(b,1)},h=function(){for(var a=0;a<d.length;a++){var b=d[a];e(b)&&f(b,g(b,a))}};c.prototype={init:function(){d.push(this.elem)},render:function(){b.addEventListener?b.addEventListener("DOMContentLoaded",h,!1):a.onload=h},listen:function(){a.onscroll=h}};for(var i=b.querySelectorAll("img[data-echo]"),j=0;j<i.length;j++)new c(i[j]).init()}(window,document); window.echo=function(a,b){"use strict";var c=function(a){this.elem=a},d=[],e=function(c){var d=c.getBoundingClientRect();return(d.top>=0&&d.left>=0&&d.top)<=(a.innerHeight||b.documentElement.clientHeight)},f=function(a,b){a.src=a.getAttribute("data-echo"),b&&b()},g=function(a,b){-1!==d.indexOf(a)&&d.splice(b,1)},h=function(){for(var a=0;a<d.length;a++){var b=d[a];e(b)&&f(b,g(b,a))}};c.prototype={init:function(){d.push(this.elem)}};for(var i=b.querySelectorAll("img[data-echo]"),j=0;j<i.length;j++)new c(i[j]).init();b.addEventListener?b.addEventListener("DOMContentLoaded",h,!1):a.onload=h,a.onscroll=h}(window,document);

4
package.json

@ -11,7 +11,7 @@
{ "type": "MIT" } { "type": "MIT" }
], ],
"year" : "2013", "year" : "2013",
"version": "1.0.0", "version": "1.1.0",
"devDependencies": { "devDependencies": {
"grunt": "~0.4.1", "grunt": "~0.4.1",
"grunt-contrib-concat": "~0.3.0", "grunt-contrib-concat": "~0.3.0",
@ -19,4 +19,4 @@
"grunt-contrib-jshint": "~0.4.3", "grunt-contrib-jshint": "~0.4.3",
"matchdep": "~0.1.2" "matchdep": "~0.1.2"
} }
} }

26
src/echo.js

@ -7,15 +7,13 @@ window.echo = (function (window, document) {
*/ */
var Echo = function (elem) { var Echo = function (elem) {
this.elem = elem; this.elem = elem;
this.render();
this.listen();
}; };
/* /*
* Images for echoing * Images for echoing
*/ */
var echoStore = []; var echoStore = [];
/* /*
* Element in viewport logic * Element in viewport logic
*/ */
@ -61,16 +59,6 @@ window.echo = (function (window, document) {
Echo.prototype = { Echo.prototype = {
init : function () { init : function () {
echoStore.push(this.elem); echoStore.push(this.elem);
},
render : function () {
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', echoImages, false);
} else {
window.onload = echoImages;
}
},
listen : function () {
window.onscroll = echoImages;
} }
}; };
@ -82,4 +70,14 @@ window.echo = (function (window, document) {
new Echo(lazyImgs[i]).init(); new Echo(lazyImgs[i]).init();
} }
})(window, document); /*
* Bind the events
*/
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', echoImages, false);
} else {
window.onload = echoImages;
}
window.onscroll = echoImages;
})(window, document);

Loading…
Cancel
Save