-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
142 lines (125 loc) · 4.32 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
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
<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta charset="utf-8">
<title>Diplomap</title>
<link rel="icon" type="image/png" href="icon-world.png">
<style media="screen">
.main {
max-width: 1280px;
margin: 0 auto;
}
#images {
position: relative;
}
#images img {
/* display: block; */
width: 100%;
max-width: 1280px;
max-height: 80vh;
/* margin: 0 auto; */
/* clip-path: inset(10% 0.5%); */
position: absolute;
top: 0;
}
.slidecontainer {
width: 100%;
}
.slider {
height: 15px;
border-radius: 5px;
-webkit-appearance: none;
appearance: none;
width: 100%;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb,
.slider::-moz-range-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #04AA6D;
cursor: pointer;
}
</style>
</head>
<body>
<div class="main">
<h1>Évolution de la situation sécuritaire mondiale</h1>
<p>
<a href="https://github.com/lecfab/diplomap" target="_blank" title="Voir sur Github" style="text-decoration: none;">
<img src="http://external-content.duckduckgo.com/ip3/github.com.ico" width="16" height="16">
</a>
Période : du <span id="periodStart"></span> au <span id="periodEnd"></span>.
Source : <a href="https://www.diplomatie.gouv.fr/fr/conseils-aux-voyageurs/" target="_blank">France Diplomatie</a>.
</p>
<div class="slidecontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="date-range">
</div>
<div id="images"></div>
</div>
</body>
<script type="text/javascript">
var slider = document.getElementById("date-range");
var nbLoads = 0;
function loadImage(i) {
if (nbLoads > 3 * images.length) return;
nbLoads++;
let id = "img" + i
let node = document.getElementById(id);
if (node == null) {
node = document.createElement("img");
node.onerror = function() {
setTimeout(loadImage, 500, i);
};
node.style.zIndex = parseInt(i == slider.value);
// node.style.opacity = 1 - i / images.length;
node.src = images[i];
node.id = id;
// node.onload = function() { showImage(i, true); }
document.getElementById("images").appendChild(node);
} else node.src = images[i] + "#" + (new Date().getTime());
}
function showImage(i, init = false) {
document.getElementById("img" + i).style.zIndex = 1;
// document.getElementById("img"+i).style.transition = "1s";
// document.getElementById("img" + i).style.opacity = 1;
document.querySelectorAll("img").forEach(e => {
if (e.id != "img" + i) {
e.style.zIndex = 0;
// e.style.transition = "1s";
// e.style.opacity = 0;
}
});
}
function dateFromUrl(url) { // extract format /yyyymmdd_
return new Date(url.replace(/^.*\/([0-9]{4})([0-9]{2})([0-9]{2})_.*$/, "$1-$2-$3"));
}
var images;
async function getImages() {
const response = await fetch('images.json', { headers: {'Accept': 'application/json'} });
images = await response.json();
slider.min = 0;
slider.max = images.length - 1;
slider.value = slider.max;
slider.addEventListener("input", e => {
showImage(slider.value);
});
document.getElementById("periodStart").innerHTML = dateFromUrl(images[0]).toLocaleDateString();
document.getElementById("periodEnd").innerHTML = dateFromUrl(images[images.length - 1]).toLocaleDateString();
for (let i = 0; i < images.length; i++) {
loadImage(i);
}
}
getImages();
</script>
</html>