-
Notifications
You must be signed in to change notification settings - Fork 0
/
slideshow.js
62 lines (55 loc) · 1.66 KB
/
slideshow.js
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
$.ajax({
dataType: "json",
url: "https://kuoppai1.firebaseio.com/.json",
success: articles
});
function articles(data, status, jqXHR) {
console.log(data);
jsonData = data;
currentContent = parseInt(localStorage.getItem('currentMediaContent'));
if (!Number.isInteger(currentContent)) {
currentContent = 0;
}
setContent(jsonData.uutiset[currentContent]);
}
function rotateContent(direction) {
if (direction === undefined) { direction="forward"; }
if (direction == "forward") {
currentContent += 1;
currentContent = currentContent % jsonData.uutiset.length;
} else {
currentContent -= 1;
if (currentContent == -1) {
currentContent = jsonData.uutiset.length - 1;
}
}
setContent(jsonData.uutiset[currentContent]);
localStorage.setItem('currentMediaContent', currentContent);
}
function toggleAutoRotation() {
if (rotate) {
clearInterval(interval);
rotate = false;
$("#toggleRotateButton").text("Toista");
} else {
interval = setInterval(rotateContent, 10000);
rotate = true;
$("#toggleRotateButton").text("Tauota");
}
}
function setContent(data) {
$("#mediaelement").hide().fadeIn();
$("#mediaelement > #content").text(data.sisältö);
$("#mediaelement > h3").text(data.otsikko);
$("#mediaelement > p > #pvm").text(data.päivämäärä);
if (data.kuva !== undefined) {
$("#mediaelement > #img").html(data.kuva);
} else {
$("#mediaelement > #img").html("");
}
}
window.onload = onPageLoad;
function onPageLoad() {
rotate = true;
interval = setInterval(rotateContent, 3000);
}