Skip to content

Commit a441bc5

Browse files
authored
Merge pull request #270 from rackerlabs/eliminate-polyfill-io
refactor(polyfills): eliminate polyfill.io
2 parents 9ce67fd + 03bbd9f commit a441bc5

File tree

9 files changed

+55
-74
lines changed

9 files changed

+55
-74
lines changed

docs/_templates/partials/after_footer.njk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<script src="dist/scripts/helix-ui.polyfills.js"></script>
2-
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
3-
41
<!-- intelligently load ES5 Adapter (if needed) -->
52
<span id="ce-es5-adapter">
63
<script>

docs/components/layouts/horizontal-layout-template.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ <h2>Right Panel</h2>
9999
<!-- FIXME: point to HelixUI polyfills in node_modules/helix-ui -->
100100
<script src="dist/scripts/helix-ui.polyfills.min.js"></script>
101101

102-
<!-- Browser polyfills (mainly for IE) -->
103-
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
104-
105102
<!-- intelligently load ES5 Adapter (if needed) -->
106103
<span id="ce-es5-adapter">
107104
<script>

docs/components/layouts/vertical-layout-template.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ <h1>Page Content</h1>
9494
<!-- FIXME: point to HelixUI polyfills in node_modules/helix-ui -->
9595
<script src="dist/scripts/helix-ui.polyfills.min.js"></script>
9696

97-
<!-- Browser polyfills (mainly for IE) -->
98-
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
99-
10097
<!-- intelligently load ES5 Adapter (if needed) -->
10198
<span id="ce-es5-adapter">
10299
<script>

rollup.config.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -120,33 +120,4 @@ export default [
120120
lessPlugin,
121121
],
122122
},
123-
124-
// src/polyfills.js --> dis/helix-ui.polyfills.js (IIFE)
125-
{
126-
input: 'src/polyfills.js',
127-
output: [
128-
{
129-
file: 'dist/scripts/helix-ui.polyfills.js',
130-
format: 'iife',
131-
}
132-
],
133-
plugins: [
134-
babelPlugin,
135-
],
136-
},
137-
138-
// src/polyfills.js --> dis/helix-ui.polyfills.min.js (IIFE)
139-
{
140-
input: 'src/polyfills.js',
141-
output: [
142-
{
143-
file: 'dist/scripts/helix-ui.polyfills.min.js',
144-
format: 'iife',
145-
}
146-
],
147-
plugins: [
148-
babelPlugin,
149-
uglify({}, minify),
150-
],
151-
},
152123
]

src/browser-entry.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import './polyfills/ChildNode';
2+
import './polyfills/Element';
13
import HelixUI from './helix-ui/index';
24

35
// add HelixUI to global scope if not already defined
46
if (!window.HelixUI) {
57
window.HelixUI = HelixUI;
68
}
79

10+
// Initialize on load
811
HelixUI.initialize();

src/polyfills.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/polyfills/ChildNode.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Modified from https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove#Polyfill
2+
[
3+
Element.prototype,
4+
CharacterData.prototype,
5+
DocumentType.prototype,
6+
].forEach(function (proto) {
7+
if (!proto.hasOwnProperty('remove')) {
8+
Object.defineProperty(proto, 'remove', {
9+
configurable: true,
10+
enumerable: true,
11+
writable: true,
12+
value: function () {
13+
if (this.parentNode !== null) {
14+
this.parentNode.removeChild(this);
15+
}
16+
},
17+
});
18+
}
19+
});

src/polyfills/Element.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Modified from https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
2+
3+
/*
4+
* If browser supports a variation of matches(), (IE9+)
5+
* normalize to 'matches' on the prototype.
6+
*/
7+
if (!Element.prototype.matches) {
8+
Element.prototype.matches = Element.prototype.msMatchesSelector ||
9+
Element.prototype.webkitMatchesSelector;
10+
}
11+
12+
if (!Element.prototype.closest) {
13+
Element.prototype.closest = function (selectors) {
14+
var el = this;
15+
16+
// fail fast if element isn't attached to the document
17+
if (!document.documentElement.contains(el)) {
18+
return null;
19+
}
20+
21+
// Check if any ancestors match selectors
22+
while (el !== null && el.nodetype === 1) {
23+
if (el.matches(selectors)) {
24+
return el;
25+
} else {
26+
el = el.parentElement || el.parentNode;
27+
}
28+
}
29+
30+
// Return null if no ancestors match
31+
return null;
32+
};
33+
}

src/polyfills/Object.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)