-
Notifications
You must be signed in to change notification settings - Fork 11
/
menu.js
159 lines (149 loc) · 6.41 KB
/
menu.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
function openIntroductionPage(){
var tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
var tab = document.getElementsByClassName("tab")[0];
var listTags = tab.getElementsByTagName("li");
for (i = 0; i < listTags.length; i++) {
listTags[i].className = listTags[i].className.replace(" active", "");
}
document.getElementById("default").style.display = "block";
}
function openPage(evt, PageName) {
localStorage.setItem("last_visited",PageName);
localStorage.setItem("last_visited_link",evt.currentTarget)
if(typeof localStorage.visit_history == 'undefined'){
localStorage.setItem("visit_history","");
}
document.getElementById("default").style.display = "none";
var i, tabcontent, listTags, tab;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tab = document.getElementsByClassName("tab")[0];
listTags = tab.getElementsByTagName("li");
for (i = 0; i < listTags.length; i++) {
listTags[i].className = listTags[i].className.replace(" active", "");
}
document.getElementById(PageName).style.display = "block";
if(evt.currentTarget.className != " active") {
evt.currentTarget.className += " active";
}
if(evt.currentTarget.className != " visited") {
evt.currentTarget.className += " visited";
}
for (i = 0; i < listTags.length; i++) {
if(listTags[i].className.indexOf("active")>-1){
localStorage.setItem("last_visited_link",listTags[i].innerHTML);
if(localStorage.visit_history.indexOf(listTags[i].innerHTML) == -1){
localStorage.visit_history = localStorage.visit_history + listTags[i].innerHTML;
}
}
}
}
function nextPage(){
var tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
if(tabcontent[i].style.display == "block" && i<tabcontent.length-1){
tabcontent[i].style.display = "none";
tabcontent[i+1].style.display = "block";
localStorage.setItem("last_visited",tabcontent[i+1].id);
break;
}
}
var tab = document.getElementById("ID");
var listTags = tab.getElementsByTagName("li");
tab.style.overflow="auto";
for (i = 0; i < listTags.length; i++) {
if(listTags[i].className.indexOf("active") > -1 && i<listTags.length-1){
console.log("test");
// listTags[i].className = listTags[i].className.replace(" active", "");
listTags[i].className = listTags[i].className.replace(" active", "");
listTags[i+1].className += " active visited";
if(i>4){
listTags[i-4].scrollIntoView();
}
break;
}
}
tab.style.overflow="hidden";
for (i = 0; i < listTags.length; i++) {
if(listTags[i].className.indexOf("active")>-1){
localStorage.setItem("last_visited_link",listTags[i].innerHTML);
if(localStorage.visit_history.indexOf(listTags[i].innerHTML) == -1){
localStorage.visit_history = localStorage.visit_history + listTags[i].innerHTML;
}
}
}
}
function previousPage(){
var tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
if(tabcontent[i].style.display == "block" && i>0){
tabcontent[i].style.display = "none";
tabcontent[i-1].style.display = "block";
localStorage.setItem("last_visited",tabcontent[i-1].id);
}
}
var tab = document.getElementById("ID");
var listTags = tab.getElementsByTagName("li");
tab.style.overflow="auto";
for (i = 0; i < listTags.length; i++) {
if(listTags[i].className.indexOf("active") > -1 && i>0){
// listTags[i].className = listTags[i].className.replace(" active", "");
listTags[i].className = listTags[i].className.replace(" active", "");
listTags[i-1].className += " active visited";
if(i>4){
listTags[i-4].scrollIntoView();
}
if(i<3){
listTags[0].scrollIntoView();
}
}
}
tab.style.overflow="hidden";
for (i = 0; i < listTags.length; i++) {
if(listTags[i].className.indexOf("active")>-1){
localStorage.setItem("last_visited_link",listTags[i].innerHTML);
if(localStorage.visit_history.indexOf(listTags[i].innerHTML) == -1){
localStorage.visit_history = localStorage.visit_history + listTags[i].innerHTML;
}
}
}
}
window.onload = function() {
var viewPortHeight = document.documentElement.clientHeight;
document.getElementsByClassName("tab")[0].style.height = (document.documentElement.clientHeight-20)+"px";
// If anyone knows why the above line is required please email to manishsherawat1@gmail.com!!
if(localStorage.last_visited !== undefined){
//for switching the display on for the last visited page and turning off the default page
document.getElementById("default").style.display = "none";
last_page=document.getElementById(localStorage["last_visited"]);
last_page.style.display = "block";
//for setting the last visited page as active in the left side index.
var i, listTags, tab;
tab = document.getElementsByClassName("tab")[0];
tab = document.getElementsByClassName("tab")[0];
listTags = tab.getElementsByTagName("li");
// overflow is set to auto for the menu in order to get the active element in the view.
tab.style.overflow="auto";
for(i = 0; i < listTags.length; i++){
if(listTags[i].innerHTML == localStorage["last_visited_link"]){
listTags[i].className += " active visited";
if(i>4){
listTags[i-4].scrollIntoView();
}
}
}
tab.style.overflow="hidden";
// tab.setAttribute("style","height:500px");
// For setting the previous visited links to visited status
for(i = 0; i < listTags.length; i++){
if(localStorage.visit_history.indexOf(listTags[i].innerHTML) > -1){
listTags[i].className += " visited";
}
}
}
}