-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexplorers.js
More file actions
119 lines (102 loc) · 3.7 KB
/
explorers.js
File metadata and controls
119 lines (102 loc) · 3.7 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
document.addEventListener('DOMContentLoaded', function () {
const searchInput = document.getElementById('search');
const listContainer = document.getElementById('list');
const paginationContainer = document.getElementById('pagination-buttons');
const prevPageButton = document.getElementById('prevPage');
const nextPageButton = document.getElementById('nextPage');
const firstPageButton = document.getElementById('firstPage');
const lastPageButton = document.getElementById('lastPage');
const loadingIndicator = document.getElementById('loading');
const itemsPerPage = 20;
let currentPage = 1;
let totalPages = 1;
let allData = [];
let filteredData = [];
function showLoading(isLoading) {
loadingIndicator.style.display = isLoading ? 'block' : 'none';
listContainer.style.display = isLoading ? 'none' : 'grid';
}
function renderList(data, page = 1) {
listContainer.innerHTML = '';
const start = (page - 1) * itemsPerPage;
const end = start + itemsPerPage;
const paginatedItems = data.slice(start, end);
paginatedItems.forEach(item => {
const listItem = document.createElement('a');
listItem.className = 'list-item';
listItem.href = item.link || '#';
listItem.target = '_blank';
listItem.rel = 'noopener noreferrer';
listItem.innerHTML = `<div>${item.name}</div>`;
listContainer.appendChild(listItem);
});
renderPagination(data.length, page);
}
function renderPagination(totalItems, page) {
paginationContainer.innerHTML = '';
totalPages = Math.ceil(totalItems / itemsPerPage);
for (let i = 1; i <= totalPages; i++) {
const pageItem = document.createElement('button');
pageItem.innerText = i;
pageItem.className = i === page ? 'active' : '';
pageItem.addEventListener('click', () => {
currentPage = i;
renderList(filteredData, currentPage);
});
paginationContainer.appendChild(pageItem);
}
prevPageButton.disabled = currentPage === 1;
nextPageButton.disabled = currentPage === totalPages;
firstPageButton.disabled = currentPage === 1;
lastPageButton.disabled = currentPage === totalPages;
}
function filterAndRender() {
const searchTerm = searchInput.value.toLowerCase();
filteredData = allData.filter(item => item.name.toLowerCase().includes(searchTerm));
renderList(filteredData, currentPage);
}
// Pagination controls
searchInput.addEventListener('input', () => {
currentPage = 1;
filterAndRender();
});
prevPageButton.addEventListener('click', () => {
if (currentPage > 1) {
currentPage--;
renderList(filteredData, currentPage);
}
});
nextPageButton.addEventListener('click', () => {
if (currentPage < totalPages) {
currentPage++;
renderList(filteredData, currentPage);
}
});
firstPageButton.addEventListener('click', () => {
currentPage = 1;
renderList(filteredData, currentPage);
});
lastPageButton.addEventListener('click', () => {
currentPage = totalPages;
renderList(filteredData, currentPage);
});
// Load from local JSON only
async function loadChains() {
showLoading(true);
try {
const res = await fetch('chains.json');
const data = await res.json();
allData = data;
filteredData = allData;
renderList(filteredData, currentPage);
} catch (err) {
listContainer.innerHTML = '<div class="error">Unable to load explorers.</div>';
} finally {
showLoading(false);
}
}
loadChains();
if (typeof initializeTranslations === 'function') {
initializeTranslations();
}
});