-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountry.html
More file actions
295 lines (278 loc) · 20 KB
/
Copy pathcountry.html
File metadata and controls
295 lines (278 loc) · 20 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>World Countries - Hindi Tutor Point</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<style>
:root { --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
body { background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); min-height: 100vh; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
.navbar { background: white !important; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
.navbar-brand { font-weight: 700; background: var(--primary-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; font-size: 1.5rem; }
.nav-link { color: #667eea !important; font-weight: 500; transition: all 0.3s ease; position: relative; }
.nav-link:hover { color: #764ba2 !important; }
.nav-link::after { content: ''; position: absolute; bottom: 0; left: 50%; width: 0; height: 2px; background: var(--primary-gradient); transition: all 0.3s ease; transform: translateX(-50%); }
.nav-link:hover::after { width: 80%; }
.hero-section { background: var(--primary-gradient); color: white; padding: 4rem 0 3rem; margin-bottom: 2rem; box-shadow: 0 10px 30px rgba(0,0,0,0.2); }
.card { border: none; border-radius: 15px; box-shadow: 0 5px 20px rgba(0,0,0,0.1); overflow: hidden; }
.table th { background: var(--primary-gradient); color: white; }
.spinner-overlay { display: flex; justify-content: center; align-items: center; padding: 3rem; }
.empty-state { text-align: center; padding: 3rem; color: #6c757d; }
.empty-state i { font-size: 3rem; margin-bottom: 1rem; display: block; }
body.print-mode .navbar,
body.print-mode .hero-section,
body.print-mode footer,
body.print-mode .no-print,
body.print-mode .pagination { display: none !important; }
body.print-mode .print-only { display: block !important; }
body.print-mode .card { box-shadow: none; border: 1px solid #ddd; }
.print-only { display: none; }
</style>
</head>
<body>
<div x-data="countryPage()">
<nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
<div class="container">
<a class="navbar-brand d-flex align-items-center" href="index.html"><img src="jar.svg" alt="JAR" height="35" class="me-2"><span class="d-flex flex-column"><span>JAR</span><small class="text-muted" style="font-size:0.6rem;font-weight:400;line-height:1;background:none;-webkit-text-fill-color:#6c757d;color:#6c757d;">JSON API Repository</small></span></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="demographicDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-globe2 me-1"></i>Demographic
</a>
<ul class="dropdown-menu" aria-labelledby="demographicDropdown">
<li><a class="dropdown-item" href="regions.html"><i class="bi bi-globe me-1"></i>Regions</a></li>
<li><a class="dropdown-item" href="subregions.html"><i class="bi bi-map me-1"></i>Subregions</a></li>
<li><a class="dropdown-item" href="country.html"><i class="bi bi-flag me-1"></i>Countries</a></li>
<li><a class="dropdown-item" href="states.html"><i class="bi bi-building me-1"></i>States</a></li>
<li><a class="dropdown-item" href="cities.html"><i class="bi bi-geo-alt me-1"></i>Cities</a></li>
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="personalities.html"><i class="bi bi-person-badge me-1"></i>Personalities</a></li>
<li class="nav-item"><a class="nav-link" href="quotes.html"><i class="bi bi-quote me-1"></i>Quotes</a></li>
<li class="nav-item"><a class="nav-link" href="blogs.html"><i class="bi bi-file-post me-1"></i>Blogs</a></li>
<li class="nav-item"><a class="nav-link" href="vocabulary.html"><i class="bi bi-book me-1"></i>Vocabulary</a></li>
<li class="nav-item"><a class="nav-link" href="https://github.com/hinditutorpoint/json" target="_blank"><i class="bi bi-github me-1"></i>GitHub</a></li>
</ul>
</div>
</div>
</nav>
<div class="hero-section">
<div class="container text-center">
<h1 class="display-4 fw-bold mb-3"><i class="bi bi-flag me-3"></i>World Countries</h1>
<p class="lead mb-0">Browse countries by region and subregion</p>
</div>
</div>
<div class="container pb-5">
<div class="card mb-4">
<div class="card-body p-4">
<div class="row g-3 align-items-end">
<div class="col-12 col-sm-6 col-md-4">
<label class="form-label fw-bold"><i class="bi bi-globe me-1"></i>Region</label>
<select class="form-select" x-model="selectedRegion" @change="onRegionChange">
<option value="">-- Choose Region --</option>
<template x-for="region in regions" :key="region.id">
<option :value="region.id" x-text="region.region"></option>
</template>
</select>
</div>
<div class="col-12 col-sm-6 col-md-4">
<label class="form-label fw-bold"><i class="bi bi-map me-1"></i>Subregion</label>
<select class="form-select" x-model="selectedSubregion" @change="onSubregionChange">
<option value="">-- Choose Subregion --</option>
<template x-for="sr in filteredSubregions" :key="sr.id">
<option :value="sr.id" x-text="sr.name"></option>
</template>
</select>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-body p-4">
<h3 class="mb-4"><i class="bi bi-list-columns me-2"></i>Countries</h3>
<div x-show="!selectedSubregion" class="empty-state">
<i class="bi bi-hand-index-thumb"></i>
<p class="fs-5">Please select a region and subregion to view countries</p>
</div>
<div x-show="loading" class="spinner-overlay">
<div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div>
</div>
<div x-show="error" class="alert alert-danger" x-text="error"></div>
<div x-show="selectedSubregion && !loading && !error">
<div class="row g-2 mb-3">
<div class="col-12 col-sm-6 col-md-5">
<input type="text" class="form-control form-control-sm" placeholder="Search countries..." x-model="searchQuery" @input="page = 1">
</div>
<div class="col-12 col-sm-6 col-md-7 d-flex align-items-center justify-content-sm-end gap-2 flex-wrap no-print">
<button class="btn btn-outline-secondary btn-sm" @click="printTable"><i class="bi bi-printer"></i> Print</button>
<button class="btn btn-outline-success btn-sm" @click="exportExcel"><i class="bi bi-file-earmark-excel"></i> Excel</button>
<select class="form-select form-select-sm" style="width: auto;" x-model="perPage" @change="page = 1">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="200">200</option>
</select>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead><tr><th>#</th><th>Name</th><th>Capital</th><th class="d-none d-md-table-cell">Code</th><th class="d-none d-md-table-cell">Phone</th><th class="d-none d-lg-table-cell">Currency</th><th class="d-none d-lg-table-cell">Nationality</th></tr></thead>
<tbody>
<template x-for="c in paginatedData" :key="c.id">
<tr>
<td x-text="c.id"></td>
<td>
<strong x-text="c.name"></strong>
<small class="d-block text-muted d-md-none" x-text="c.alpha_code + ' | +' + c.phone_code"></small>
</td>
<td x-text="c.capital"></td>
<td class="d-none d-md-table-cell"><code x-text="c.alpha_code"></code></td>
<td class="d-none d-md-table-cell"><span class="badge bg-secondary" x-text="'+' + c.phone_code"></span></td>
<td class="d-none d-lg-table-cell" x-text="c.currency_name"></td>
<td class="d-none d-lg-table-cell" x-text="c.nationality"></td>
</tr>
</template>
</tbody>
</table>
</div>
<div class="print-only mt-4" id="print-section">
<table class="table table-bordered">
<thead><tr><th>#</th><th>Name</th><th>Capital</th><th>Code</th><th>Phone</th><th>Currency</th><th>Nationality</th></tr></thead>
<tbody>
<template x-for="c in searchedData" :key="c.id">
<tr><td x-text="c.id"></td><td x-text="c.name"></td><td x-text="c.capital"></td><td x-text="c.alpha_code"></td><td x-text="'+' + c.phone_code"></td><td x-text="c.currency_name"></td><td x-text="c.nationality"></td></tr>
</template>
</tbody>
</table>
</div>
<div x-show="searchedData.length === 0" class="alert alert-info mt-3">No countries found.</div>
<div class="d-flex flex-column flex-sm-row justify-content-between align-items-center mt-3 gap-2">
<small class="text-muted">
Showing <strong x-text="showingFrom"></strong>–<strong x-text="showingTo"></strong> of <strong x-text="searchedData.length"></strong>
<template x-if="searchQuery && searchedData.length !== filteredCountries.length">
<span>(filtered from <strong x-text="filteredCountries.length"></strong>)</span>
</template>
</small>
<nav x-show="totalPages > 1" class="no-print">
<ul class="pagination pagination-sm mb-0">
<li class="page-item" :class="{ disabled: page === 1 }"><button class="page-link" @click="goToPage(1)">«</button></li>
<li class="page-item" :class="{ disabled: page === 1 }"><button class="page-link" @click="goToPage(page - 1)">‹</button></li>
<template x-for="p in getPageNumbers()" :key="p">
<li class="page-item" :class="{ active: p === page, disabled: p === '...' }"><button class="page-link" x-text="p" @click="goToPage(p)"></button></li>
</template>
<li class="page-item" :class="{ disabled: page === totalPages }"><button class="page-link" @click="goToPage(page + 1)">›</button></li>
<li class="page-item" :class="{ disabled: page === totalPages }"><button class="page-link" @click="goToPage(totalPages)">»</button></li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
<footer class="bg-dark text-white py-4 mt-5">
<div class="container text-center">
<p class="mb-2"><i class="bi bi-github me-2"></i><a href="https://github.com/hinditutorpoint/json" target="_blank" class="text-white text-decoration-none">github.com/hinditutorpoint/json</a></p>
<p class="mb-0 text-muted">Built with Alpine.js & Bootstrap 5 | © 2026 Hindi Tutor Point</p>
</div>
</footer>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
function countryPage() {
return {
regions: [],
selectedRegion: '',
filteredSubregions: [],
allSubregions: null,
selectedSubregion: '',
allCountries: null,
filteredCountries: [],
searchQuery: '',
page: 1,
perPage: 10,
loading: false,
error: null,
get searchedData() {
if (!this.searchQuery) return this.filteredCountries;
const q = this.searchQuery.toLowerCase();
return this.filteredCountries.filter(c => c.name.toLowerCase().includes(q) || (c.capital || '').toLowerCase().includes(q) || (c.nationality || '').toLowerCase().includes(q));
},
get totalPages() { return Math.ceil(this.searchedData.length / this.perPage) || 1; },
get paginatedData() { const s = (this.page - 1) * this.perPage; return this.searchedData.slice(s, s + this.perPage); },
get showingFrom() { return this.searchedData.length ? (this.page - 1) * this.perPage + 1 : 0; },
get showingTo() { return Math.min(this.page * this.perPage, this.searchedData.length); },
goToPage(p) { if (p >= 1 && p <= this.totalPages) this.page = p; },
getPageNumbers() {
const t = this.totalPages, c = this.page, p = [];
if (t <= 7) { for (let i = 1; i <= t; i++) p.push(i); }
else { p.push(1); if (c > 3) p.push('...'); for (let i = Math.max(2, c - 1); i <= Math.min(t - 1, c + 1); i++) p.push(i); if (c < t - 2) p.push('...'); p.push(t); }
return p;
},
printTable() {
const opt = {
margin: [5, 5, 5, 5],
filename: 'countries.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, useCORS: true },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
};
document.body.classList.add('print-mode');
setTimeout(() => {
html2pdf().set(opt).from(document.getElementById('print-section')).save().then(() => {
document.body.classList.remove('print-mode');
}).catch(() => { document.body.classList.remove('print-mode'); });
}, 300);
},
exportExcel() {
const rows = [['ID', 'Name', 'Capital', 'Code', 'Phone', 'Currency', 'Nationality']];
this.searchedData.forEach(c => rows.push([c.id, c.name, c.capital, c.alpha_code, '+' + c.phone_code, c.currency_name, c.nationality]));
const csv = rows.map(r => r.map(v => `"${String(v).replace(/"/g, '""')}"`).join(',')).join('\n');
const blob = new Blob(['\uFEFF' + csv], { type: 'text/csv;charset=utf-8;' });
const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'countries.csv'; a.click(); URL.revokeObjectURL(a.href);
},
async init() { await this.loadRegions(); },
extractData(json, tableName) { const table = json.find(item => item.type === 'table' && item.name === tableName); return table ? table.data : []; },
async loadRegions() {
try {
const res = await fetch('https://raw.githubusercontent.com/hinditutorpoint/json/main/regions.json');
this.regions = this.extractData(await res.json(), 'regions');
} catch (err) { this.error = 'Failed to load regions.'; console.error(err); }
},
async onRegionChange() {
this.selectedSubregion = ''; this.filteredCountries = []; this.searchQuery = ''; this.page = 1;
if (!this.selectedRegion) { this.filteredSubregions = []; return; }
if (!this.allSubregions) {
this.loading = true; this.error = null;
try {
const res = await fetch('https://raw.githubusercontent.com/hinditutorpoint/json/main/subregions.json');
this.allSubregions = this.extractData(await res.json(), 'subregions');
} catch (err) { this.error = 'Failed to load subregions.'; console.error(err); }
finally { this.loading = false; }
}
this.filteredSubregions = this.allSubregions.filter(sr => sr.region_id === this.selectedRegion);
},
async onSubregionChange() {
this.filteredCountries = []; this.searchQuery = ''; this.page = 1;
if (!this.selectedSubregion) return;
if (!this.allCountries) {
this.loading = true; this.error = null;
try {
const res = await fetch('https://raw.githubusercontent.com/hinditutorpoint/json/main/countries.json');
this.allCountries = this.extractData(await res.json(), 'countries');
} catch (err) { this.error = 'Failed to load countries.'; console.error(err); }
finally { this.loading = false; }
}
this.filteredCountries = this.allCountries.filter(c => c.subregion_id === this.selectedSubregion);
}
}
}
</script>
</body>
</html>