From a35cff243ea709059a4b268494a8f5cf1c744b85 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 29 Aug 2012 09:29:51 +0100 Subject: [PATCH] Implement Array.forEach for browsers which don't have it --- app/assets/javascripts/application.js | 9 +++++++++ app/assets/javascripts/compat.js | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 app/assets/javascripts/compat.js diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e02949f58..352ec9f8a 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -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 index 000000000..3af9297a3 --- /dev/null +++ b/app/assets/javascripts/compat.js @@ -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); + } + } +} -- 2.43.2