Skip to content

Commit f20063d

Browse files
authored
[chore] Standardizing polyfills for reporting (#647)
* chore Moving polyfills into a separate file with standard syntax to make reporting on these easier in future * chore Add a documentation section on other types of polyfills and the property syntax for adding them * chore Add reporting to the demo page for polyfills and todos
1 parent 4bfefbf commit f20063d

File tree

49 files changed

+1521
-721
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1521
-721
lines changed

CHANGELOG-prerelease.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Tag: [v1.0.0-prerelease.33](https://github.com/patternfly/patternfly-elements/re
1212

1313
- [5ad398](https://github.com/patternfly/patternfly-elements/commit/5ad3983b9ead73cf2db30fd0bc52aada334c6961) Disclosure accordion variant
1414
- [3ccec6](https://github.com/patternfly/patternfly-elements/commit/3ccec6c82efc52aae67b74072b6c0b8ff1b47f23) Update pfe-cta to include broadcast variables for all variants [#659](https://github.com/patternfly/patternfly-elements/issues/658)
15+
- [](https://github.com/patternfly/patternfly-elements/commit/) chore: Pull polyfills out into separate files for easier parsing/reporting
1516

1617
## Prerelease 32 ( 2019-12-05 )
1718

@@ -26,11 +27,11 @@ Tag: [v1.0.0-prerelease.32](https://github.com/patternfly/patternfly-elements/re
2627
Tag: [v1.0.0-prerelease.31](https://github.com/patternfly/patternfly-elements/releases/tag/v1.0.0-prerelease.31)
2728

2829
- [cdcdddf](https://github.com/patternfly/patternfly-elements/commit/cdcdddfa6858953727a3b6d7dcb9add7a61adf93) fix: Bring back pfe-cta hover animation effect [#624](https://github.com/patternfly/patternfly-elements/pull/624)
29-
- [32b138e](https://github.com/patternfly/patternfly-elements/commit/32b138e64223031fd70ed2e525ee98cd5bb7f954) Update Travis tests
30+
- [32b138e](https://github.com/patternfly/patternfly-elements/commit/32b138e64223031fd70ed2e525ee98cd5bb7f954) fix: Update Travis tests
3031
- [67fa1fb](https://github.com/patternfly/patternfly-elements/commit/67fa1fb3f29ec3e48a6d0767b6c08eb008e56655) fix: pfe-navigation mobile login/language links working [#620](https://github.com/patternfly/patternfly-elements/pull/620)
3132
- [4ebcbcc](https://github.com/patternfly/patternfly-elements/commit/4ebcbcccaf50247c27a242a944dd4a5a654aeb80) fix: pfe-navigation add styles for when JavaScript does not load [#600](https://github.com/patternfly/patternfly-elements/pull/600))
3233
- [27ef3ec](https://github.com/patternfly/patternfly-elements/commit/27ef3ec08371ec32c9a9376904163ef48148affa) feat: Updating broadcast and how variables are applied [#392](https://github.com/patternfly/patternfly-elements/pull/392)
33-
- [a78ea1f]() Speed up Travis tests [#621](https://github.com/patternfly/patternfly-elements/issues/621)
34+
- [a78ea1f](https://github.com/patternfly/patternfly-elements/commit/a78ea1fc5e114856ede20e459d35875697410b56) fix: Speed up Travis tests [#621](https://github.com/patternfly/patternfly-elements/issues/621)
3435
- [f144b6f](https://github.com/patternfly/patternfly-elements/commit/f144b6f33dd6a8b615ac2a63cec6b29f3bf70d32) feat: pfe-select component [#553](https://github.com/patternfly/patternfly-elements/pull/553)
3536

3637

docs/content/develop/step-2b.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ We'll also need to update `/demo/index.html` so that the user's name is passed i
3939
<link href="../../pfelement/dist/pfelement.min.css" rel="stylesheet">
4040
4141
<!-- uncomment the es5-adapter if you're using the umd version -->
42-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.10/custom-elements-es5-adapter.js"></script>
43-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.10/webcomponents-bundle.js"></script>
42+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/custom-elements-es5-adapter.js"></script>
43+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/webcomponents-bundle.js"></script>
4444
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script>
4545
<script>require(['../pfe-cool-element.umd.js'])</script>
4646
</head>

docs/content/getting-started/browser-support.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ As a developer, you will need to make sure you include the necessary polyfills.
3434
<title>PatternFly Elements</title>
3535
3636
<!-- uncomment the es5-adapter if you're using the compiled version -->
37-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.4/custom-elements-es5-adapter.js"></script>
37+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/custom-elements-es5-adapter.js"></script>
3838
<!-- webcomponents-bundle.js includes all of the polyfills -->
39-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.4/webcomponents-bundle.js"></script>
39+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/webcomponents-bundle.js"></script>
4040
</head>
4141
<body>
4242
@@ -58,8 +58,8 @@ There's only a difference of the web component file that's being downloaded, but
5858
<title>PatternFly Elements</title>
5959
6060
<!-- uncomment the es5-adapter if you're using the compiled version -->
61-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.4/custom-elements-es5-adapter.js"></script>
62-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.4/webcomponents-loader.js"></script>
61+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/custom-elements-es5-adapter.js"></script>
62+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/webcomponents-loader.js"></script>
6363
</head>
6464
<body>
6565
<script>
@@ -78,7 +78,7 @@ For a more in-depth explanation, view the [example on GitHub](https://github.com
7878
The two examples above also include the `custom-elements-es5-adapter.js` file before the web component polyfill. In the case that you need to support ES5, you need to include this polyfill. According to the spec, custom elements must be written as ES6 classes. However, in our build step we transpile our ES6 components to ES5 which makes it necessary for us to include the adapter to get our components to work.
7979

8080
```
81-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.4/custom-elements-es5-adapter.js"></script>
81+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/custom-elements-es5-adapter.js"></script>
8282
```
8383

8484
For more documentation, check out the [custom-elements-es5-adapter.js section](https://github.com/WebComponents/webcomponentsjs#custom-elements-es5-adapterjs) on GitHub.

docs/content/getting-started/polyfills.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ the head of your document.
2626
<title>PatternFly Elements</title>
2727
2828
<!-- polyfills -->
29-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.4/custom-elements-es5-adapter.js"></script>
30-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.4/webcomponents-bundle.js"></script>
29+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/custom-elements-es5-adapter.js"></script>
30+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/webcomponents-bundle.js"></script>
3131
</head>
3232
<body></body>
33-
</html
33+
</html>
3434
```
3535

3636
## What type of Javascript are you using?
@@ -43,8 +43,8 @@ the head of your document.
4343
## Custom elements ES5 adapter
4444

4545
This polyfill is needed if your custom elements have been compiled from ES6 to ES5.
46-
It's not necessary to include this polyfill for IE 11 and it will throw a syntax
47-
error in IE 11 because the adapter was written in ES6. However, you can ignore
46+
It's not necessary to include this polyfill for IE11 and it will throw a syntax
47+
error in IE11 because the adapter was written in ES6. However, you can ignore
4848
this error because it will not cause issues with your elements.
4949

5050

@@ -68,3 +68,18 @@ this error because it will not cause issues with your elements.
6868

6969
Check out the ES6 pfelement and include it.
7070

71+
## Additional polyfills
72+
73+
Some components may require the addition of certain functions in order to use modern JavaScript in older browsers. Until we can build in a way to automatically add these polyfills, please create a separate file called `polyfills--<component-name>.js` and import that file into your component using the following syntax. Be sure to specify what functions are being defined inside the polyfills file in the comment section above the import statement.
74+
75+
```js
76+
// Import polyfills: <list of function names>
77+
import "polyfills--<component-name>.js";
78+
```
79+
80+
In your polyfills file, please prefix each addition with the name of the polyfill and the URL from which it was copied. Please use the following syntax so that we can easily report on/grep for these values:
81+
82+
```js
83+
// @POLYFILL Array.prototype.find
84+
// https://tc39.github.io/ecma262/#sec-array.prototype.find
85+
```

elements/pfe-accordion/demo/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<link rel="stylesheet" href="../../pfe-styles/dist/pfe-layouts.css" />
2222

2323
<!-- uncomment the es5-adapter if you're using the umd version -->
24-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.10/custom-elements-es5-adapter.js"></script>
25-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.10/webcomponents-bundle.js"></script>
24+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/custom-elements-es5-adapter.js"></script>
25+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/webcomponents-bundle.js"></script>
2626
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script>
2727

2828
<script>require([

elements/pfe-accordion/src/pfe-accordion.js

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,7 @@
1-
import PFElement from "../../pfelement/dist/pfelement.js";
2-
3-
// Polyfill: findIndex -- https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
4-
if (!Array.prototype.findIndex) {
5-
Object.defineProperty(Array.prototype, "findIndex", {
6-
value: function(predicate) {
7-
// 1. Let O be ? ToObject(this value).
8-
if (this == null) {
9-
throw new TypeError('"this" is null or not defined');
10-
}
11-
12-
var o = Object(this);
13-
14-
// 2. Let len be ? ToLength(? Get(O, "length")).
15-
var len = o.length >>> 0;
16-
17-
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
18-
if (typeof predicate !== "function") {
19-
throw new TypeError("predicate must be a function");
20-
}
21-
22-
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
23-
var thisArg = arguments[1];
24-
25-
// 5. Let k be 0.
26-
var k = 0;
27-
28-
// 6. Repeat, while k < len
29-
while (k < len) {
30-
// a. Let Pk be ! ToString(k).
31-
// b. Let kValue be ? Get(O, Pk).
32-
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
33-
// d. If testResult is true, return k.
34-
var kValue = o[k];
35-
if (predicate.call(thisArg, kValue, k, o)) {
36-
return k;
37-
}
38-
// e. Increase k by 1.
39-
k++;
40-
}
1+
// Import polyfills: findIndex
2+
import "./polyfills--pfe-accordion.js";
413

42-
// 7. Return -1.
43-
return -1;
44-
}
45-
});
46-
}
4+
import PFElement from "../../pfelement/dist/pfelement.js";
475

486
function generateId() {
497
return Math.random()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// @POLYFILL Array.prototype.findIndex
2+
// https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
3+
if (!Array.prototype.findIndex) {
4+
Object.defineProperty(Array.prototype, "findIndex", {
5+
value: function(predicate) {
6+
// 1. Let O be ? ToObject(this value).
7+
if (this == null) {
8+
throw new TypeError('"this" is null or not defined');
9+
}
10+
11+
var o = Object(this);
12+
13+
// 2. Let len be ? ToLength(? Get(O, "length")).
14+
var len = o.length >>> 0;
15+
16+
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
17+
if (typeof predicate !== "function") {
18+
throw new TypeError("predicate must be a function");
19+
}
20+
21+
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
22+
var thisArg = arguments[1];
23+
24+
// 5. Let k be 0.
25+
var k = 0;
26+
27+
// 6. Repeat, while k < len
28+
while (k < len) {
29+
// a. Let Pk be ! ToString(k).
30+
// b. Let kValue be ? Get(O, Pk).
31+
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
32+
// d. If testResult is true, return k.
33+
var kValue = o[k];
34+
if (predicate.call(thisArg, kValue, k, o)) {
35+
return k;
36+
}
37+
// e. Increase k by 1.
38+
k++;
39+
}
40+
41+
// 7. Return -1.
42+
return -1;
43+
}
44+
});
45+
}

elements/pfe-autocomplete/src/pfe-autocomplete.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
/*
2-
* Copyright 2018 Red Hat, Inc.
3-
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a copy
5-
* of this software and associated documentation files (the "Software"), to deal
6-
* in the Software without restriction, including without limitation the rights
7-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8-
* copies of the Software, and to permit persons to whom the Software is
9-
* furnished to do so, subject to the following conditions:
10-
*
11-
* The above copyright notice and this permission notice shall be included in
12-
* all copies or substantial portions of the Software.
13-
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20-
* SOFTWARE.
21-
*/
22-
231
import PFElement from "../../pfelement/dist/pfelement.js";
242

253
const KEYCODE = {

elements/pfe-avatar/demo/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.2/vue.min.js"></script>
2323

2424
<!-- uncomment the es5-adapter if you're using the umd version -->
25-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.10/custom-elements-es5-adapter.js"></script>
26-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.10/webcomponents-bundle.js"></script>
25+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/custom-elements-es5-adapter.js"></script>
26+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/webcomponents-bundle.js"></script>
2727
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script>
2828

2929
<script>require([

elements/pfe-band/demo/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
<link href="../../pfe-styles/dist/pfe-layouts.css" rel="stylesheet">
2626

2727
<!-- uncomment the es5-adapter if you're using the umd version -->
28-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.10/custom-elements-es5-adapter.js"></script>
28+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/custom-elements-es5-adapter.js"></script>
2929
<!-- testing to see if this is needed -->
30-
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.10/webcomponents-loader.js"></script>
30+
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/webcomponents-loader.js"></script>
3131
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script>
3232

3333
<!-- Use webcomponents-loader when you are adding support for more modern browsers -->
34-
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.10/webcomponents-bundle.js"></script> -->
34+
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.3.0/webcomponents-bundle.js"></script> -->
3535

3636
<!-- IE11 test: use bundle + require with umd files -->
3737
<!-- Use webcomponents-bundle when supporting much older browsers like IE11 -->

0 commit comments

Comments
 (0)