Skip to content

Commit 38ceca6

Browse files
author
Ire Aderinokun
committed
fixes
1 parent 891d5d1 commit 38ceca6

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

caniuse-embed.html

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
}
2424
</style>
2525

26-
<iframe src="//caniuse.bitsofco.de/embed/index.html?feat=[[feature]]&periods=[[periods]]"
27-
frameborder="0"
28-
width="100%"
29-
height="400px"></iframe>
26+
<!-- HTML added in ready() -->
27+
3028
</template>
3129

3230
<script>
@@ -40,34 +38,46 @@
4038
futureVersions: String,
4139

4240
/* The number of previous browser versions to display (optional) */
43-
pastVersions: String,
44-
45-
/* An internally used property (don't specify) */
46-
periods: String
41+
pastVersions: String
4742
},
4843
ready: function() {
4944

5045
if ( !this.feature ) this.textContent = `A feature was not included. Go to <a href='http://caniuse.bitsofco.de/#how-to-use'>http://caniuse.bitsofco.de/#how-to-use</a> to generate an embed.`;
5146

52-
let future = '';
53-
if ( this.futureVersions ) {
54-
for (let i = 1; i < parseInt(this.futureVersions) + 1; i++) {
55-
future += `future_${i},`
56-
}
57-
}
47+
const periods = calculatePeriods(this.futureVersions, this.pastVersions);
5848

59-
let past = '';
60-
if ( this.pastVersions ) {
61-
for (let i = 1; i < parseInt(this.pastVersions) + 1; i++) {
62-
past += `,past_${i}`
63-
}
64-
}
49+
this.innerHTML = `
50+
<iframe src="//caniuse.bitsofco.de/embed/index.html?feat=${this.feature}&periods=${periods}"
51+
frameborder="0"
52+
width="100%"
53+
height="400px"></iframe>
54+
`;
6555

66-
this.periods = future + 'current' + past;
6756
}
6857
});
6958

7059

60+
function calculatePeriods(futureVersions, pastVersions) {
61+
62+
let future = '';
63+
if ( futureVersions ) {
64+
for (let i = 1; i < parseInt(futureVersions) + 1; i++) {
65+
future += `future_${i},`
66+
}
67+
}
68+
69+
let past = '';
70+
if ( pastVersions ) {
71+
for (let i = 1; i < parseInt(pastVersions) + 1; i++) {
72+
past += `,past_${i}`
73+
}
74+
}
75+
76+
return future + 'current' + past;
77+
78+
}
79+
80+
7181
// Handle Sizing of iFrame
7282
const eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
7383
const eventer = window[eventMethod];

0 commit comments

Comments
 (0)