Skip to content

Commit 930da7d

Browse files
author
Helen Chapman
committed
Merge branch 'fix/ie11-js-errors' into 'master'
Add ie11 js polyfills See merge request tech/django-pattern-library!48
2 parents 280ede5 + dcae519 commit 930da7d

File tree

5 files changed

+84
-11
lines changed

5 files changed

+84
-11
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"webpack-cli": "^2.0.14"
1818
},
1919
"dependencies": {
20+
"babel-polyfill": "^6.26.0",
2021
"babel-preset-env": "^1.6.1",
2122
"highlight.js": "^9.12.0"
2223
}

pattern_library/static/pattern_library/src/js/app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'babel-polyfill';
2+
13
import '../scss/main.scss';
24
import persistMenu from './components/persist-menu';
35
import patternSearch from './components/pattern-search';
@@ -6,6 +8,11 @@ import syntaxHighlighting from './components/syntax-highlighting';
68
import hideMenuMobile from './components/hide-menu-mobile';
79
import {setIframeSize, resizeIframe} from './components/iframe';
810
import {toggleNav, toggleNavItems} from './components/navigation';
11+
import foreachPolyfill from './polyfills/foreach-polyfill';
12+
import closestPolyfill from './polyfills/closest-polyfill';
13+
14+
foreachPolyfill();
15+
closestPolyfill();
916

1017
document.addEventListener('DOMContentLoaded', () => {
1118
syntaxHighlighting();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export default function closestPolyfill() {
2+
// Closest polyfill see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
3+
if (!Element.prototype.matches) {
4+
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
5+
}
6+
7+
if (!Element.prototype.closest) {
8+
Element.prototype.closest = function(s) {
9+
var el = this;
10+
11+
do {
12+
if (el.matches(s)) return el;
13+
el = el.parentElement || el.parentNode;
14+
} while (el !== null && el.nodeType === 1);
15+
return null;
16+
};
17+
}
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default function foreachPolyfill() {
2+
// forEach polyfill see https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach#Polyfill
3+
if (window.NodeList && !NodeList.prototype.forEach) {
4+
NodeList.prototype.forEach = function (callback, thisArg) {
5+
thisArg = thisArg || window;
6+
for (var i = 0; i < this.length; i++) {
7+
callback.call(thisArg, this[i], i, this);
8+
}
9+
};
10+
}
11+
}

0 commit comments

Comments
 (0)