forked from luciopaiva/country-flags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
109 lines (95 loc) · 3.4 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Country Flags</title>
<link rel="stylesheet" href="dist/country-flag.css">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f1f1f1;
color: #4e4e4e;
}
.country-container {
width: 400px;
border: 1px solid #d8d8d8;
border-radius: 16px;
box-shadow: 2px 2px 2px #676767;
background-color: white;
display: flex;
flex-direction: column;
}
.country-header {
display: flex;
flex-direction: row;
grid-column: 1 / 3;
}
.country-flag {
margin: 16px;
}
.country-name {
justify-self: start;
align-self: center;
font-size: 24px;
font-weight: bold;
}
.country-properties {
display: grid;
grid-gap: 16px;
padding: 16px;
grid-template-columns: 35% auto;
}
.country-property-value {
font-weight: bold;
}
</style>
<script src="dist/country-flag.js"></script>
</head>
<body>
<h1>Country Flags</h1>
<p>Renders a country's flag based on it's ISO <a href="https://en.wikipedia.org/wiki/ISO_3166-1">3166-1</a> code (alpha-2, alpha-3 or numeric).</p>
<div id="sample-country" class="country-container">
<div class="country-header">
<div class="country-flag"></div>
<div class="country-name"></div>
</div>
<div class="country-properties">
<div class="country-property-name">ISO alpha-2:</div>
<div class="country-property-value alpha-2"></div>
<div class="country-property-name">ISO alpha-3:</div>
<div class="country-property-value alpha-3"></div>
<div class="country-property-name">ISO numeric:</div>
<div class="country-property-value iso-numeric"></div>
<div class="country-property-name">Top-level domain:</div>
<div class="country-property-value top-level-domain"></div>
</div>
</div>
<p>Images are 32x32 pixels, transparent background.</p>
<script>
const flag = new CountryFlag(document.querySelector("#sample-country .country-flag"));
const nameElement = document.querySelector("#sample-country .country-name");
const alpha2Element = document.querySelector("#sample-country .alpha-2");
const alpha3Element = document.querySelector("#sample-country .alpha-3");
const isoNumericElement = document.querySelector("#sample-country .iso-numeric");
const topLevelDomainElement = document.querySelector("#sample-country .top-level-domain");
/**
* @param {CountryFlagInfo} country
*/
function displayCountry(country) {
flag.selectByAlpha2(country.alpha2);
nameElement.innerText = country.name;
alpha2Element.innerText = country.alpha2.toUpperCase();
alpha3Element.innerText = country.alpha3.toUpperCase();
isoNumericElement.innerText = country.isoNumeric;
topLevelDomainElement.innerText = `.${country.topLevelDomain}`;
}
function pickRandomCountry() {
const isoNumeric = flag.randomize();
const country = CountryFlag.getCountryByIsoNumeric(isoNumeric);
displayCountry(country);
}
pickRandomCountry();
setInterval(pickRandomCountry, 500);
</script>
</body>
</html>