Skip to content

Commit c2ddfda

Browse files
committed
partial IE11 support
* changing webpack to target ES5 (instead of ES6) (186k -> 192k) * adding couple polyfills helps go further along BUT still complains > SCRIPT438: Object doesn't support property or method 'forEach' target.querySelectorAll('.grid-stack').forEach() even tough I added forAll. Note: I am gonna punt on this mark IE11 no longer supported, but wanted to check this in case we go back.
1 parent 3c63efb commit c2ddfda

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

src/gridstack-poly.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,87 @@ if (!Array.prototype.findIndex) {
122122
configurable: true,
123123
writable: true
124124
});
125+
}
126+
127+
// Source: https://github.com/jserz/js_piece/blob/master/DOM/ParentNode/append()/append().md
128+
(function (arr) {
129+
arr.forEach(function (item) {
130+
if (item.hasOwnProperty('append')) {
131+
return;
132+
}
133+
Object.defineProperty(item, 'append', {
134+
configurable: true,
135+
enumerable: true,
136+
writable: true,
137+
value: function append() {
138+
var argArr = Array.prototype.slice.call(arguments),
139+
docFrag = document.createDocumentFragment();
140+
141+
argArr.forEach(function (argItem) {
142+
var isNode = argItem instanceof Node;
143+
docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem)));
144+
});
145+
146+
this.appendChild(docFrag);
147+
}
148+
});
149+
});
150+
})([Element.prototype, Document.prototype, DocumentFragment.prototype]);
151+
152+
// Production steps of ECMA-262, Edition 5, 15.4.4.18
153+
// Reference: http://es5.github.io/#x15.4.4.18
154+
155+
if (!Array.prototype['forEach']) {
156+
157+
Array.prototype.forEach = function(callback, thisArg) {
158+
159+
if (this == null) { throw new TypeError('Array.prototype.forEach called on null or undefined'); }
160+
161+
var T, k;
162+
// 1. Let O be the result of calling toObject() passing the
163+
// |this| value as the argument.
164+
var O = Object(this);
165+
166+
// 2. Let lenValue be the result of calling the Get() internal
167+
// method of O with the argument "length".
168+
// 3. Let len be toUint32(lenValue).
169+
var len = O.length >>> 0;
170+
171+
// 4. If isCallable(callback) is false, throw a TypeError exception.
172+
// See: http://es5.github.com/#x9.11
173+
if (typeof callback !== "function") { throw new TypeError(callback + ' is not a function'); }
174+
175+
// 5. If thisArg was supplied, let T be thisArg; else let
176+
// T be undefined.
177+
if (arguments.length > 1) { T = thisArg; }
178+
179+
// 6. Let k be 0
180+
k = 0;
181+
182+
// 7. Repeat, while k < len
183+
while (k < len) {
184+
185+
var kValue;
186+
187+
// a. Let Pk be ToString(k).
188+
// This is implicit for LHS operands of the in operator
189+
// b. Let kPresent be the result of calling the HasProperty
190+
// internal method of O with argument Pk.
191+
// This step can be combined with c
192+
// c. If kPresent is true, then
193+
if (k in O) {
194+
195+
// i. Let kValue be the result of calling the Get internal
196+
// method of O with argument Pk.
197+
kValue = O[k];
198+
199+
// ii. Call the Call internal method of callback with T as
200+
// the this value and argument list containing kValue, k, and O.
201+
callback.call(T, kValue, k, O);
202+
}
203+
// d. Increase k by 1.
204+
k++;
205+
}
206+
// 8. return undefined
207+
};
125208
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"outDir": "./dist",
1616
"sourceMap": true,
1717
"strict": false,
18-
"target": "ES6"
18+
"target": "ES5"
1919
},
2020
"exclude": [
2121
"./src/**/*.spec.ts",

0 commit comments

Comments
 (0)