Implement Array.forEach for browsers which don't have it
authorTom Hughes <tom@compton.nu>
Wed, 29 Aug 2012 08:29:51 +0000 (09:29 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 29 Aug 2012 08:30:14 +0000 (09:30 +0100)
app/assets/javascripts/application.js
app/assets/javascripts/compat.js [new file with mode: 0644]

index e02949f..352ec9f 100644 (file)
@@ -5,11 +5,20 @@
 //= require openlayers
 //= require i18n/translations
 //= require globals
+//= require compat
 //= require browse
 //= require export
 //= require map
 //= require menu
 
+if ( !Array.prototype.forEach ) {
+  Array.prototype.forEach = function(fn, scope) {
+    for(var i = 0, len = this.length; i < len; ++i) {
+      fn.call(scope || this, this[i], i, this);
+    }
+  }
+}
+
 /*
  * Called as the user scrolls/zooms around to aniplate hrefs of the
  * view tab and various other links
diff --git a/app/assets/javascripts/compat.js b/app/assets/javascripts/compat.js
new file mode 100644 (file)
index 0000000..3af9297
--- /dev/null
@@ -0,0 +1,10 @@
+/*
+ * Implement Array.forEach for browsers which don't have it
+ */
+if ( !Array.prototype.forEach ) {
+  Array.prototype.forEach = function(fn, scope) {
+    for(var i = 0, len = this.length; i < len; ++i) {
+      fn.call(scope || this, this[i], i, this);
+    }
+  }
+}