-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
69 lines (67 loc) · 2.24 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
<head>
<link rel="stylesheet" href="default.css" >
<body>
<a href = "#" onclick="showGridView()">back to grid</a>
<p/>
<div id = "image_container">
<div id = "grid_view">
<div class = "image_in_grid" onclick="showFullImage(1)">
<img src = "img/01.png" />
</div>
<div class = "image_in_grid" onclick="showFullImage(2)">
<img src = "img/02.png" />
</div>
<div class = "image_in_grid" onclick="showFullImage(3)">
<img src = "img/03.png" />
</div>
<div class = "image_in_grid" onclick="showFullImage(4)">
<img src = "img/04.png" />
</div>
</div>
</div>
<script>
function showFullImage(image) {
var image_path = ("img/0" + image + ".png");
document.getElementById('image_container').innerHTML = "<img src = '" + image_path + "' />";
console.log(image_path);
}
function showGridView() {
var content_string = "<div id = 'grid_view'>\
<div class = 'image_in_grid' onclick='showFullImage(1)'>\
<img src ='img/01.png' />\
</div>\
<div class = 'image_in_grid' onclick='showFullImage(2)'>\
<img src = 'img/02.png' />\
</div>\
<div class = 'image_in_grid' onclick='showFullImage(3)'>\
<img src = 'img/03.png' />\
</div>\
<div class = 'image_in_grid' onclick='showFullImage(4)'>\
<img src = 'img/04.png' />\
</div>\
</div>";
document.getElementById('image_container').innerHTML = content_string;
}
function refresh() {
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "https://your-api-url-here.amazonaws.com/prod/mydemoresource", true);
xhttp.send();
xhttp.addEventListener("readystatechange", processRequest, false);
function processRequest(e) {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var response = JSON.parse(xhttp.responseText);
var numberString = response.dogPicture;
if(numberString < 5 && numberString > 0) {
showFullImage(numberString);
} else {
showGridView();
}
console.log(numberString);
}
}
setTimeout(refresh, 1000);
}
refresh();
</script>
</body>
</head>