Browse Source

ie8- support

added 'compatibility' directory for 'bad browser' hacks
pull/8/head
Morozov Andrew 11 years ago
parent
commit
346b630840
  1. 21
      src/compatibility/array/indexOf.js
  2. 12
      src/compatibility/document/querySelectorAll.js
  3. 17
      src/echo.js

21
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;
};
}

12
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;
}
}

17
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);
}
}
}

Loading…
Cancel
Save