-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
111 lines (103 loc) · 3.05 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
110
111
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Main page</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="main.css" />
<script src="main.js" async defer></script>
</head>
<body>
<script src="main.js" async defer></script>
<script>
function count_keys(jsonfile) {
var count = 0;
return fetch(jsonfile)
.then((response) => response.json())
.then((data) => {
for (let key in data) {
count += 1;
}
return count;
})
.catch((error) => {
console.error("Error loading JSON file:", error);
});
}
var max_images = 5;
var dropdown = document.getElementById("postsDropdown");
window.onload = function () {
dropdown = document.getElementById("postsDropdown");
dropdown.addEventListener("change", () => {
max_images = dropdown.value;
});
populate(
"photos_container",
"photo",
"photodiv",
current_page,
max_images
);
};
var current_page = 0;
var page_text = "Page ";
var page_element = "page_indicator";
var source_json = "photos.json";
function update_text(page_num, text, element) {
var thing = document.getElementById(element);
thing.textContent = text + (page_num + 1);
}
function nextpage() {
count_keys(source_json).then((num) => {
number_keys = num;
if (number_keys > (current_page + 1) * max_images) {
current_page += 1;
update_text(current_page, page_text, page_element);
populate(
"photos_container",
"photo",
"photodiv",
current_page,
max_images
);
}
});
}
function previouspage() {
if (current_page != 0) {
current_page -= 1;
update_text(current_page, page_text, page_element);
populate(
"photos_container",
"photo",
"photodiv",
current_page,
max_images
);
}
}
</script>
<div id="main" class="centerdiv">
<p class="indiv">Photos</p>
<p class="indiv" , id="page_indicator">Page 1</p>
<p class="posts_options">
Posts per page:
<select id="postsDropdown">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
</select>
</p>
<div class="navbuttons">
<button onclick="previouspage()">←</button
><button onclick="nextpage()">→</button>
</div>
<div id="photos_container"></div>
</div>
</body>
</html>