From 18280dcaf303ff7ca8fa3c053fe9a60982b17bfb Mon Sep 17 00:00:00 2001 From: Benjamin J DeLong Date: Tue, 26 Nov 2013 10:45:11 -0700 Subject: [PATCH] Possible solution to IE8 problem Function to convert querySelector object to array. --- src/echo.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/echo.js b/src/echo.js index 53250cd..9e6c746 100644 --- a/src/echo.js +++ b/src/echo.js @@ -10,18 +10,27 @@ window.Echo = (function (window, document, undefined) { }; var _pollImages = function () { - for (var i = 0, len = store.length; i < len; i++) { - var self = store[i]; + var imgs = store.slice(); + for (var i = 0, len = imgs.length; i < len; i++) { + var self = imgs[i]; if (_inView(self)) { self.src = self.getAttribute('data-echo'); store.splice(i, 1); } } }; - + + var toArray (obj) { + var arr = []; + for (var i = 0, len = obj.length; i < len; i++) { + arr.push(obj[i]); + } + return arr; + } + var init = function () { store = document.querySelectorAll('[data-echo]'); - store = [].slice.call(store); + store = toArray(store); _pollImages(); window.onscroll = _pollImages; };