Skip to content

Commit 05624aa

Browse files
author
Jordan Humphreys
committed
Fix IE11 compatability with reduce polyfill.
1 parent 614c84f commit 05624aa

File tree

7 files changed

+162
-37
lines changed

7 files changed

+162
-37
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tribute",
33
"description": "Native ES6 @mentions",
4-
"version": "2.3.4",
4+
"version": "2.3.5",
55
"main": [
66
"dist/tribute.js",
77
"dist/tribute.css"

dist/tribute.js

Lines changed: 93 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tribute.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tribute.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tributejs",
3-
"version": "2.3.4",
3+
"version": "2.3.5",
44
"description": "Native ES6 @mentions",
55
"main": "dist/tribute.js",
66
"devDependencies": {

src/utils.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,70 @@ if (!Array.prototype.find) {
2121
}
2222
}
2323

24+
// Production steps of ECMA-262, Edition 5, 15.4.4.21
25+
// Reference: http://es5.github.io/#x15.4.4.21
26+
// https://tc39.github.io/ecma262/#sec-array.prototype.reduce
27+
if (!Array.prototype.reduce) {
28+
Object.defineProperty(Array.prototype, 'reduce', {
29+
value: function(callback /*, initialValue*/) {
30+
if (this === null) {
31+
throw new TypeError( 'Array.prototype.reduce ' +
32+
'called on null or undefined' );
33+
}
34+
if (typeof callback !== 'function') {
35+
throw new TypeError( callback +
36+
' is not a function');
37+
}
38+
39+
// 1. Let O be ? ToObject(this value).
40+
var o = Object(this);
41+
42+
// 2. Let len be ? ToLength(? Get(O, "length")).
43+
var len = o.length >>> 0;
44+
45+
// Steps 3, 4, 5, 6, 7
46+
var k = 0;
47+
var value;
48+
49+
if (arguments.length >= 2) {
50+
value = arguments[1];
51+
} else {
52+
while (k < len && !(k in o)) {
53+
k++;
54+
}
55+
56+
// 3. If len is 0 and initialValue is not present,
57+
// throw a TypeError exception.
58+
if (k >= len) {
59+
throw new TypeError( 'Reduce of empty array ' +
60+
'with no initial value' );
61+
}
62+
value = o[k++];
63+
}
64+
65+
// 8. Repeat, while k < len
66+
while (k < len) {
67+
// a. Let Pk be ! ToString(k).
68+
// b. Let kPresent be ? HasProperty(O, Pk).
69+
// c. If kPresent is true, then
70+
// i. Let kValue be ? Get(O, Pk).
71+
// ii. Let accumulator be ? Call(
72+
// callbackfn, undefined,
73+
// « accumulator, kValue, k, O »).
74+
if (k in o) {
75+
value = callback(value, o[k], k, o);
76+
}
77+
78+
// d. Increase k by 1.
79+
k++;
80+
}
81+
82+
// 9. Return accumulator.
83+
return value;
84+
}
85+
});
86+
}
87+
2488
(function() {
2589

2690
if (typeof window.CustomEvent === "function") return false

tributejs.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for TributeJS v2.3.4
1+
// Type definitions for TributeJS v2.3.5
22
// Project: https://github.com/zurb/tribute
33
// Definitions by: Jordan Humphreys <https://github.com/mrsweaters/>
44

0 commit comments

Comments
 (0)