From b65546abb2bf4342b8f3eca31081d32c87935249 Mon Sep 17 00:00:00 2001 From: Michael Cornwell Date: Wed, 15 Nov 2017 07:12:59 -0600 Subject: [PATCH] Added IE11 fix for discussion cohorts bug. --- lms/static/js/ie11_find_array.js | 45 ++++++++++++++++++++++++++++++++ lms/templates/main.html | 2 ++ 2 files changed, 47 insertions(+) create mode 100644 lms/static/js/ie11_find_array.js diff --git a/lms/static/js/ie11_find_array.js b/lms/static/js/ie11_find_array.js new file mode 100644 index 0000000000..4d3c36fd42 --- /dev/null +++ b/lms/static/js/ie11_find_array.js @@ -0,0 +1,45 @@ +// Polyfill for patching IE11 Browsers +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find#Polyfill +if (!Array.prototype.find) { + Object.defineProperty(Array.prototype, 'find', { + value: function(predicate) { + // 1. Let O be ? ToObject(this value). + if (this == null) { + throw new TypeError('"this" is null or not defined'); + } + + var o = Object(this); + + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = o.length >>> 0; + + // 3. If IsCallable(predicate) is false, throw a TypeError exception. + if (typeof predicate !== 'function') { + throw new TypeError('predicate must be a function'); + } + + // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + var thisArg = arguments[1]; + + // 5. Let k be 0. + var k = 0; + + // 6. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + // b. Let kValue be ? Get(O, Pk). + // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + // d. If testResult is true, return kValue. + var kValue = o[k]; + if (predicate.call(thisArg, kValue, k, o)) { + return kValue; + } + // e. Increase k by 1. + k++; + } + + // 7. Return undefined. + return undefined; + } + }); +} diff --git a/lms/templates/main.html b/lms/templates/main.html index 52576191e3..5e60e46a37 100644 --- a/lms/templates/main.html +++ b/lms/templates/main.html @@ -56,9 +56,11 @@ from pipeline_mako import render_require_js_path_overrides <% jsi18n_path = "js/i18n/{language}/djangojs.js".format(language=LANGUAGE_CODE) + ie11_fix_path = "js/ie11_find_array.js" %> +