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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
// **********************************************************************
//
// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
var symboltree = new Object();
symboltree.id = 'SymbolTree';
symboltree.cookie = 'SliceSymbolTree';
symboltree.main = function()
{
//
// Look for a collapsible list.
//
symboltree.tree = document.getElementById(symboltree.id);
if(!symboltree.tree)
{
alert('There is no symbol tree on this page.');
return;
}
if(symboltree.tree.style)
{
//
// Assign class 'CollapsibleList' to all the unordered lists.
// That way, if the browser does not support DOM, the CCS style
// that removes the bullets and indent does not apply.
//
symboltree.tree.className = 'CollapsibleList';
var ul = symboltree.tree.getElementsByTagName('ul');
for(var i = 0; i < ul.length; ++i)
{
ul[i].className = 'CollapsibleList';
}
}
else
{
return; // Browser doesn't support DOM, don't do anything.
}
//
// Find all <li> list items.
//
var list = symboltree.tree.getElementsByTagName('li');
for(var i = 0; i < list.length; ++i)
{
//
// If this list contains sub-lists, it needs a collapse/expand widget.
//
if(list[i].getElementsByTagName('ul').length != 0)
{
//
// Attach an event listener to the widget.
//
list[i].addEventListener('click', symboltree.handleEvent, false);
//
// The list starts out collapsed by default. Set state and class name, and
// hide all the entries in this list.
//
list[i].setAttribute('state', 'collapsed');
list[i].className = 'CollapsedList';
var children = list[i].childNodes;
for(var j = 0; j < children.length; ++j)
{
if(children[j].tagName == 'UL' || children[j].tagName == 'LI')
{
children[j].style.display = 'none';
}
}
}
else
{
//
// We have a plain <li> list item without <ul> sub-lists. We attach a class name
// to these items so we can refer to them separately in the style sheet.
//
list[i].className = 'ListEntry';
}
}
//
// Save expanded list indexes in cookie when page unloads.
//
window.addEventListener('unload', symboltree.save, false);
//
// Load state of list.
//
symboltree.restore();
//
// Set handler for the "Expand All" and "Collapse All" buttons.
//
var expandAll = document.getElementById('ExpandAllButton');
expandAll.addEventListener('click', symboltree.expandAll, false);
var collapseAll = document.getElementById('CollapseAllButton');
collapseAll.addEventListener('click', symboltree.collapseAll, false);
}
//
// Mouse click event handler for collapse/expand widget.
//
symboltree.handleEvent = function(e)
{
var target;
if(e.target)
{
target = e.target;
}
else if(e.srcObject)
{
target = e.srcObject;
}
if(!target.className || (target.className != 'CollapsedList' && target.className != 'ExpandedList'))
{
return; // Ignore event because it bubbled up from child element (namely, from a link in the list).
}
//
// Toggle the list.
//
if(target.getAttribute('state') == 'expanded')
{
symboltree.collapse(e.currentTarget);
}
else
{
symboltree.expand(e.currentTarget);
}
//
// Stop event from bubbling up.
//
if(e.stopPropagation)
{
e.stopPropagation(); // For standards-compliant browsers.
}
else
{
e.cancelBubble = true; // For IE
}
}
//
// Expand sub-list. The state of the list is remembered in the 'state' attribute.
// Expanded lists have a class name of 'ExpandedList', so the style sheet can select
// the correct icon. To expand a list, we change the display of all immediate
// child <ul> and <li> nodes to 'block'.
//
symboltree.expand = function(list)
{
var state = list.getAttribute('state');
if(state && state != 'expanded')
{
list.setAttribute('state', 'expanded');
list.className = 'ExpandedList';
var children = list.childNodes;
for(var i = 0; i < children.length; ++i)
{
if(children[i].tagName == 'UL' || children[i].tagName == 'LI')
{
children[i].style.display = 'block';
}
}
}
}
symboltree.expandAll = function()
{
var list = symboltree.tree.getElementsByTagName('li');
for(var i = 0; i < list.length; ++i)
{
if(list[i].getElementsByTagName('ul').length != 0)
{
symboltree.expand(list[i]);
}
}
}
//
// Collapse a sub-list. The state of the list is remembered in the 'state' attribute.
// Collapsed lists have a class name of 'CollapsedList', so the style sheet can select
// the correct icon. To collapse a list, we change the display of all immediate
// child <ul> and <li> nodes to 'none'.
//
symboltree.collapse = function(list)
{
var state = list.getAttribute('state');
if(state && state != 'collapsed')
{
list.setAttribute('state', 'collapsed');
list.className = 'CollapsedList';
var children = list.childNodes;
for(var i = 0; i < children.length; ++i)
{
if(children[i].tagName == 'UL' || children[i].tagName == 'LI')
{
children[i].style.display = 'none';
}
}
}
}
symboltree.collapseAll = function()
{
var list = symboltree.tree.getElementsByTagName('li');
for(var i = 0; i < list.length; ++i)
{
if(list[i].getElementsByTagName('ul').length != 0)
{
symboltree.collapse(list[i]);
}
}
}
//
// Save state of the list in a cookie. We save the index of each
// expanded <li> element.
//
symboltree.save = function()
{
var list = symboltree.tree.getElementsByTagName('li');
var saved = new Array();
for(var i = 0; i < list.length; ++i)
{
if(list[i].getElementsByTagName('ul').length != 0)
{
var state = list[i].getAttribute('state');
if(state && state == 'expanded')
{
saved[saved.length] = i;
}
}
}
if(saved.length == 0)
{
saved[0] = 'none';
}
document.cookie = symboltree.cookie + '=' + saved;
}
//
// Restore the state of the list from a cookie.
//
symboltree.restore = function()
{
var regex = new RegExp(symboltree.cookie + '=[^;]+', 'i');
if (document.cookie.match(regex))
{
var value = document.cookie.match(regex)[0].split('=')[1];
if(value != 'none')
{
var indexes = value.split(',');
var list = symboltree.tree.getElementsByTagName('li');
for(var i = 0; i < indexes.length; ++i)
{
symboltree.expand(list[indexes[i]]);
}
}
}
}
symboltree.main(); // Start running.
|