File: toc.js

package info (click to toggle)
publican 2.1-2%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,108 kB
  • ctags: 195
  • sloc: xml: 6,511; perl: 6,356; makefile: 30
file content (221 lines) | stat: -rw-r--r-- 5,483 bytes parent folder | download
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
var work = 1;
var name_c = window.location.hostname + '-publican';
var num_days = 7;

function setCookie(name, value, expires, path, domain, secure) { 
	var curCookie = name + "=" + value + 
		((expires) ? ";expires=" + expires.toGMTString() : "") + 
		((path) ? ";path=" + path : "");
// + 
//		((domain) ? ";domain=" + domain : "") + 
//		((secure) ? ";secure" : ""); 

	document.cookie = curCookie; 
}

function addID(id) {
	var current_val = "";

	if(document.cookie) {
		var cookies = document.cookie.split(/ *; */);
		for(var i=0; i < cookies.length; i++) {
			var current_c = cookies[i].split("=");
			if(current_c[0] == name_c) {
				current_val = current_c[1];
				break;
			}
		}
	}

	if(current_val) {
		current_val += "," + id;
	} else {
		current_val = id;
	}

	var expDate = new Date();
	expDate.setDate(expDate.getDate() + num_days);
	setCookie(name_c, current_val, expDate, '/', false, false);
}

function removeID(id) {
	var current_val = "";

	if(document.cookie) {
		var cookies = document.cookie.split(/ *; */);
		for(var i=0; i < cookies.length; i++) {
			var current_c = cookies[i].split("=");
			if(current_c[0] == name_c) {
				current_val = current_c[1];
				break;
			}
		}
	}


	if(current_val == id) {
		current_val = "";
	}

	if(current_val.match("," + id + ",") != -1) {
		current_val = current_val.replace("," + id + ",", ",");
	}

	var rg = new RegExp("^" + id + ",");
	if(current_val.match(rg) != -1) {
		current_val = current_val.replace(rg, "");
	}

	rg = new RegExp("," + id + "\$");
	if(current_val.match(rg) != -1) {
		current_val = current_val.replace(rg, "");
	}

	var expDate = new Date();
	expDate.setDate(expDate.getDate() + num_days);
	setCookie(name_c, current_val, expDate, '/', false, false);
}

// TODO: Should really removeID all ID
function clearCookie(id) {
	// TODO: split and toggle
	var current_val = "";

	if(document.cookie) {
		var cookies = document.cookie.split(/ *; */);
		for(var i=0; i < cookies.length; i++) {
			var current_c = cookies[i].split("=");
			if(current_c[0] == name_c) {
				current_val = current_c[1];
				break;
			}
		}
	}

	var ids = current_val.split(',');
	for(var j = 0; j < ids.length; j++) {
		work = 1;
		toggle("", ids[j]);
	}
	
	work = 1;
	current_val = "";

	var expDate = new Date();
	expDate.setDate(expDate.getDate() + num_days);
	setCookie(name_c, current_val, expDate, '/', false, false);
}

function getCookie() {
	var current_val = "";

	if(document.cookie.length <= 0) { return;}

	var cookies = document.cookie.split(/ *; */);
	for(var i=0; i < cookies.length; i++) {
		var current_c = cookies[i].split("=");
		if(current_c[0] == name_c) {
			current_val = current_c[1];
			break;
		}
                else if(current_c[0] == name_c + '-lang') {
			var lang = current_c[1];
           		var loc = location.href;
                        var rg = new RegExp("/" + lang + "/");
                        if(loc.match(rg) == null) {
				location.href="../" + lang + "/toc.html";
			}                        
                }
	}

	if(current_val.length <= 0) { return;}

	var ids = current_val.split(",");

	for(var i=0; i < ids.length; i++) {
		var entity = document.getElementById(ids[i]);
		if(entity) {
			var my_class = entity.className;
			var my_parent = entity.parentNode;
			if(my_class.indexOf("hidden") != -1) {
				entity.className = my_class.replace(/hidden/,"visible");
				my_parent.className = my_parent.className.replace(/collapsed/,"expanded");
			}
		}
	}

}

function toggle(e, id) {
	if(work) {
		work = 0;
		var entity = document.getElementById(id);
		if(entity) {
			var my_class = entity.className;
			var my_parent = entity.parentNode;
			if(my_class.indexOf("hidden") != -1) {
				entity.className = my_class.replace(/hidden/,"visible");
				my_parent.className = my_parent.className.replace(/collapsed/,"expanded");
				addID(id);
			}
			else if(my_class.indexOf("visible") != -1) {
				entity.className = my_class.replace(/visible/,"hidden");
				my_parent.className = my_parent.className.replace(/expanded/,"collapsed");
				removeID(id);
			}
			else {

			}
		}
	}
}

function loadToc() {
	var my_select = document.getElementById('langselect');
	if (my_select.selectedIndex > 0) {
		var expDate = new Date();
		expDate.setDate(expDate.getDate() + num_days);
		setCookie(name_c + '-lang', my_select.options[my_select.selectedIndex].value, expDate, '/', false, false);              
		location.href="../" + my_select.options[my_select.selectedIndex].value + "/toc.html";
//		parent.frames.main.location.replace("../" + my_select.options[my_select.selectedIndex].value + "/index.html");
	}
}

function checkCookie() {
	var found = false;
	var testCookie = 'test_nocookie';

	addID(testCookie);

	if(document.cookie) {
		var cookies = document.cookie.split(/ *; */);
		for(var i=0; i < cookies.length; i++) {
			var current_c = cookies[i].split("=");
			if(current_c[0] == name_c) {
				var ids = current_c[1].split(',');
				for( var j=0; j < ids.length; j++) {
					if(ids[j] == testCookie) {
						found = true;
						break;
					}
				}
				break;
			}
		}
	}

	if (found) {
		removeID(testCookie);
	} else {
		var entity = document.getElementById('nocookie');
		var my_class = entity.className;
		entity.className = my_class.replace(/hidden/, "nocookie");
//		alert("DEBUG: The Navigation Menu requires cookies to be enabled to function correctly.");
	}
}

function hideNoJS() {
	var entity = document.getElementById('nojs');
	entity.className = 'hidden';
}