|
23 | 23 | }
|
24 | 24 | </style>
|
25 | 25 |
|
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 | + |
30 | 28 | </template>
|
31 | 29 |
|
32 | 30 | <script>
|
|
40 | 38 | futureVersions: String,
|
41 | 39 |
|
42 | 40 | /* 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 |
47 | 42 | },
|
48 | 43 | ready: function() {
|
49 | 44 |
|
50 | 45 | 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.`;
|
51 | 46 |
|
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); |
58 | 48 |
|
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 | + `; |
65 | 55 |
|
66 |
| - this.periods = future + 'current' + past; |
67 | 56 | }
|
68 | 57 | });
|
69 | 58 |
|
70 | 59 |
|
| 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 | + |
71 | 81 | // Handle Sizing of iFrame
|
72 | 82 | const eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
|
73 | 83 | const eventer = window[eventMethod];
|
|
0 commit comments