-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscreenshots.js
More file actions
134 lines (120 loc) · 3.25 KB
/
screenshots.js
File metadata and controls
134 lines (120 loc) · 3.25 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
var modal = document.getElementById('modal');
var span = document.getElementsByClassName("close")[0];
var screenshots = {};
var boxInfo = {};
var modalImages = [];
var modalIndex = 0;
var modalTitle = "";
var modalBox = null;
function sortedBoxKeys()
{
var keys = Object.keys(boxInfo).filter(function(k) { return screenshots[k]; });
keys.sort(function(a, b) { return parseInt(a) - parseInt(b); });
return keys;
}
function updateModal()
{
var e = document.getElementById('screenshot');
var header = "";
if (modalTitle) {
var keys = sortedBoxKeys();
var idx = keys.indexOf(String(modalBox));
var prev = (idx > 0)
? "<a href=\"#\" onclick=\"modalBoxPrev();return false\" style=\"margin-right:16px;\"><</a>"
: "<span style=\"margin-right:16px;color:#ccc;\"><</span>";
var next = (idx >= 0 && idx < keys.length - 1)
? "<a href=\"#\" onclick=\"modalBoxNext();return false\" style=\"margin-left:16px;\">></a>"
: "<span style=\"margin-left:16px;color:#ccc;\">></span>";
header = "<h3 style=\"margin-top:0;text-align:center;\">" + prev + modalTitle + next + "</h3>";
}
var img = "<img width=\"100%\" src=\"" + modalImages[modalIndex] + "\"/>";
var nav = "";
if (modalImages.length > 1) {
nav = "<div style=\"text-align:center;margin-top:8px;\">";
if (modalIndex > 0) {
nav += "<a href=\"#\" onclick=\"modalPrev();return false\" style=\"margin-right:16px;\">< prev</a>";
}
nav += (modalIndex + 1) + " of " + modalImages.length;
if (modalIndex < modalImages.length - 1) {
nav += "<a href=\"#\" onclick=\"modalNext();return false\" style=\"margin-left:16px;\">next ></a>";
}
nav += "</div>";
}
e.innerHTML = header + img + nav;
}
function modalPrev()
{
if (modalIndex > 0) {
modalIndex--;
updateModal();
}
}
function modalNext()
{
if (modalIndex < modalImages.length - 1) {
modalIndex++;
updateModal();
}
}
function modalBoxPrev()
{
var keys = sortedBoxKeys();
var idx = keys.indexOf(String(modalBox));
if (idx > 0) {
showscreenshot(keys[idx - 1]);
}
}
function modalBoxNext()
{
var keys = sortedBoxKeys();
var idx = keys.indexOf(String(modalBox));
if (idx >= 0 && idx < keys.length - 1) {
showscreenshot(keys[idx + 1]);
}
}
function showscreenshot(n)
{
modalBox = n;
modalImages = screenshots[n];
modalIndex = 0;
var info = boxInfo[n];
modalTitle = info
? "Box " + n + " - " + info.name + " - By " + info.author
: "Box " + n;
updateModal();
modal.style.display = "block";
}
function getbox(n, name, author)
{
if (screenshots[n]) {
boxInfo[n] = { name: name, author: author };
return("<a href=\"#\" onclick=\"showscreenshot('" + n + "');return false\">" + name + "</a>");
}
return name;
}
function screenshotjsonget(url)
{
var r = new XMLHttpRequest();
r.open("GET", url, true);
r.setRequestHeader("Content-type", "application/json")
r.onreadystatechange = function()
{
if (r.readyState == 4 && r.status == 200)
{
var tbl = JSON.parse(r.responseText);
Object.keys(tbl).forEach(function(key, index) {
screenshots[key] = tbl[key];
})
}
}
r.send();
}
screenshotjsonget("https://luanti.foo-projects.org/screenshots.json");
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}