From 8009c6c0175d8a4a26a159d2abb5bb77e6109775 Mon Sep 17 00:00:00 2001 From: Benjamin J DeLong Date: Tue, 26 Nov 2013 10:16:20 -0700 Subject: [PATCH] Remove element from array once the src is set I think this is what was intended. Elements are removed from `store` once the src is set to the data-echo attribute. --- src/echo.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/echo.js b/src/echo.js index 5cae710..53250cd 100644 --- a/src/echo.js +++ b/src/echo.js @@ -10,19 +10,18 @@ window.Echo = (function (window, document, undefined) { }; var _pollImages = function () { - for (var i = 0; i < store.length; i++) { + for (var i = 0, len = store.length; i < len; i++) { var self = store[i]; if (_inView(self)) { self.src = self.getAttribute('data-echo'); - if ([].indexOf && [].slice.call(store).indexOf(self) !== -1) { - [].slice.call(store).splice(i, 1); - } + store.splice(i, 1); } } }; var init = function () { store = document.querySelectorAll('[data-echo]'); + store = [].slice.call(store); _pollImages(); window.onscroll = _pollImages; };