diff --git a/src/compatibility/array/indexOf.js b/src/compatibility/array/indexOf.js new file mode 100644 index 0000000..98c1cb3 --- /dev/null +++ b/src/compatibility/array/indexOf.js @@ -0,0 +1,21 @@ +if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (element , start) { + var start = start ? start : 0, length; + if (!this) { + throw new TypeError(); + } + length = this.length; + if (length === 0 || start >= length) { + return -1; + } + if (start < 0) { + start = length - Math.abs(start); + } + for (var i = start; i < length; i++) { + if (this[i] === element) { + return i; + } + } + return -1; + }; +} \ No newline at end of file diff --git a/src/compatibility/document/querySelectorAll.js b/src/compatibility/document/querySelectorAll.js new file mode 100644 index 0000000..4fbbee9 --- /dev/null +++ b/src/compatibility/document/querySelectorAll.js @@ -0,0 +1,12 @@ +if (!document.querySelectorAll && document.createStyleSheet) { + document.querySelectorAll = function (selector) { + var all = document.all, result = [], style = document.createStyleSheet(); + style.addRule(selector, 'fake:fake'); + for (var i = all.length - 1; i >= 0; i--) { + if (all[i].currentStyle.fake === 'fake') { + result.push(all[i]); + } + } + style.removeRule(0); return result; + } +} \ No newline at end of file diff --git a/src/echo.js b/src/echo.js index e7e1f75..4e89920 100644 --- a/src/echo.js +++ b/src/echo.js @@ -1,16 +1,3 @@ -if (!document.querySelectorAll && document.createStyleSheet) { - document.querySelectorAll = function (selector) { - var all = document.all, result = [], style = document.createStyleSheet(); - style.addRule(selector, 'fake:fake'); - for (var i = all.length - 1; i >= 0; i--) { - if (all[i].currentStyle.fake === 'fake') { - result.push(all[i]); - } - } - style.removeRule(0); return result; - } -} - window.Echo = (function (window, document, undefined) { 'use strict'; @@ -28,8 +15,8 @@ window.Echo = (function (window, document, undefined) { 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); + if (store.indexOf(self) !== -1) { + store.splice(i, 1); } } }