Browse Source

Kill zombies

pull/38/head
Teoh Han Hui 11 years ago
parent
commit
ad3f33f03a
  1. 21
      dist/echo.js
  2. 2
      dist/echo.min.js
  3. 21
      src/echo.js

21
dist/echo.js vendored

@ -20,6 +20,25 @@ window.Echo = (function (global, document, undefined) {
*/
var offset, throttle, poll;
/**
* _contains
* @private
* @param {Node} parent Parent node
* @param {Node} descendant Descendant node
* @returns {Boolean} Does parent contain descendant
*/
var _contains = !!document.compareDocumentPosition ?
// IE
function (parent, descendant) {
return parent.contains(descendant);
} :
// Everyone else
function (parent, descendant) {
/*jslint bitwise: true */
return parent.compareDocumentPosition(descendant) & 16;
/*jslint bitwise: false */
};
/**
* _inView
* @private
@ -41,7 +60,7 @@ window.Echo = (function (global, document, undefined) {
if (length > 0) {
for (var i = 0; i < length; i++) {
var self = store[i];
if (self && _inView(self)) {
if (self && _contains(document.documentElement, self) && _inView(self)) {
self.src = self.getAttribute('data-echo');
callback(self);
store.splice(i, 1);

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(){},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=f.length;if(c>0)for(var d=0;c>d;d++){var i=f[d];i&&h(i)&&(i.src=i.getAttribute("data-echo"),g(i),f.splice(d,1),c=f.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),g=k.callback||g;for(var l=0;l<h.length;l++)f.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);
window.Echo=function(a,b){"use strict";var c,d,e,f=[],g=function(){},h=b.compareDocumentPosition?function(a,b){return a.contains(b)}:function(a,b){return 16&a.compareDocumentPosition(b)},i=function(a){var d=a.getBoundingClientRect();return(d.top>=0&&d.left>=0&&d.top)<=(window.innerHeight||b.documentElement.clientHeight)+c},j=function(){var c=f.length;if(c>0)for(var d=0;c>d;d++){var j=f[d];j&&h(b.documentElement,j)&&i(j)&&(j.src=j.getAttribute("data-echo"),g(j),f.splice(d,1),c=f.length,d--)}else b.removeEventListener?a.removeEventListener("scroll",k):a.detachEvent("onscroll",k),clearTimeout(e)},k=function(){clearTimeout(e),e=setTimeout(j,d)},l=function(e){var h=b.querySelectorAll("[data-echo]"),i=e||{};c=parseInt(i.offset||0),d=parseInt(i.throttle||250),g=i.callback||g;for(var l=0;l<h.length;l++)f.push(h[l]);j(),b.addEventListener?(a.addEventListener("scroll",k,!1),a.addEventListener("load",k,!1)):(a.attachEvent("onscroll",k),a.attachEvent("onload",k))};return{init:l,render:j}}(this,document);

21
src/echo.js

@ -19,6 +19,25 @@ window.Echo = (function (global, document, undefined) {
*/
var offset, throttle, poll;
/**
* _contains
* @private
* @param {Node} parent Parent node
* @param {Node} descendant Descendant node
* @returns {Boolean} Does parent contain descendant
*/
var _contains = !!document.compareDocumentPosition ?
// IE
function (parent, descendant) {
return parent.contains(descendant);
} :
// Everyone else
function (parent, descendant) {
/*jslint bitwise: true */
return parent.compareDocumentPosition(descendant) & 16;
/*jslint bitwise: false */
};
/**
* _inView
* @private
@ -40,7 +59,7 @@ window.Echo = (function (global, document, undefined) {
if (length > 0) {
for (var i = 0; i < length; i++) {
var self = store[i];
if (self && _inView(self)) {
if (self && _contains(document.documentElement, self) && _inView(self)) {
self.src = self.getAttribute('data-echo');
callback(self);
store.splice(i, 1);

Loading…
Cancel
Save