From caa0d08ba9ff7eab5500ff9716051117cdc46018 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Tue, 21 Jan 2014 10:48:02 -0800 Subject: [PATCH] removed event listeners and cleaned up timeout when work is complete --- src/echo.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/echo.js b/src/echo.js index 9f15708..684dc6e 100644 --- a/src/echo.js +++ b/src/echo.js @@ -1,3 +1,4 @@ +/*! Echo v1.4.0 | (c) 2013 @toddmotto | MIT license | github.com/toddmotto/echo */ window.Echo = (function (window, document, undefined) { 'use strict'; @@ -10,12 +11,26 @@ window.Echo = (function (window, document, undefined) { }; var _pollImages = function () { - for (var i = store.length; i--;) { - var self = store[i]; - if (_inView(self)) { - self.src = self.getAttribute('data-echo'); - store.splice(i, 1); + + var storeLength = store.length; + + if (storeLength > 0) { + console.log("Remaining: " + storeLength); + for (var i = storeLength; i--;) { + var self = store[i]; + if (_inView(self)) { + self.src = self.getAttribute('data-echo'); + store.splice(i, 1); + } + } + } else { + if (document.removeEventListener) { + window.removeEventListener('scroll', _throttle); + } else { + window.detachEvent('onscroll', _throttle); } + clearTimeout(poll); + console.log("done"); } };