-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate.js
66 lines (64 loc) · 2.04 KB
/
rotate.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
63
64
65
66
var index = 1;
///Animate & change text
function changeBanner() {
titleLoop=[JSON.parse(localStorage.getItem("title"))];
if(JSON.parse(localStorage.getItem("title"))!== titleLoop){
var title = document.getElementById('tickerHeaderText').children;
title[0].textContent=titleLoop;
title[0].className="showup";
};
if(currentArray !== JSON.parse(localStorage.getItem("list"))){
loadLines();
}
var list = document.getElementById('tickerContent').children;
[].forEach.call(list, function (v, i) {
///Show the current item
list[i].hidden = i !== index;
if (i == index) {
list[i].className = "showup";
}
}
);
///Rotate through the list
index = (index + 1) % list.length;
}
window.onload = function () {
///load title
var titleLoop=[];
var title = document.getElementById('tickerHeaderText').children;
title[0].className="showup";
titleLoop=[JSON.parse(localStorage.getItem("title"))];
title[0].textContent=titleLoop;
///load text
var currentArray = [];
loadLines();
console.log="Lines loaded";
///Begin display
var list = document.getElementById('tickerContent').children;
list[0].className = "showup";
list[0].hidden = 0;
console.log="First line shown";
///Rest of the rotation
if (list.length>=2){
setInterval(changeBanner, 5000);
}else{
console.log="No looping effect";
}
};
loadLines = function () {
var linesArray = localStorage.getItem("list");
var readArray = JSON.parse(linesArray);
currentArray = readArray;
if(linesArray===null){
readArray = ["ERROR: no lines saved.","Please change the lines in tickerSet."]
}
var area = document.getElementById("tickerContent");
area.innerHTML = "";
for (var i = 0; i < readArray.length; i++) {
area.innerHTML += "<p>" + readArray[i] + "</p>";
}
}
///auto-reload
/*window.setTimeout(function() {
window.location.href = window.location.href;
}, 5000); */