-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathpreview.html
52 lines (48 loc) · 1.41 KB
/
preview.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Country Flags</title>
<style>
ul {
list-style: none;
padding: 0;
margin: 0;
width: 80%;
max-width: 500px;
display: flex;
flex-wrap: wrap;
}
li {
padding: 0;
margin: 5px 5px 0 0;
}
</style>
</head>
<body>
<div id="app"></div>
<script>
class CountriesPreview {
constructor() {
this.$el = document.querySelector('#app');
this.build();
}
async getCountries() {
const response = await fetch('countries.json');
return await response.json();
}
async build() {
const countries = await this.getCountries();
const list = countries.map(country => {
return `<li><img src="images/svg/${country.alpha3.toLowerCase()}.svg" width="40" alt="${country.name}" /></li>`;
});
this.$el.innerHTML = `<ul>${list.join('\n')}</ul>`;
}
}
new CountriesPreview();
</script>
</body>
</html>