From ad3f33f03a874fc80e318dc20e312f538e603045 Mon Sep 17 00:00:00 2001 From: Teoh Han Hui Date: Wed, 2 Apr 2014 11:15:50 +0000 Subject: [PATCH] Kill zombies --- dist/echo.js | 21 ++++++++++++++++++++- dist/echo.min.js | 2 +- src/echo.js | 21 ++++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/dist/echo.js b/dist/echo.js index 4a1edd1..c5e3087 100644 --- a/dist/echo.js +++ b/dist/echo.js @@ -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); diff --git a/dist/echo.min.js b/dist/echo.min.js index b24d32e..e8928cc 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=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=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 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);