-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaqtree3clickable.js
More file actions
91 lines (76 loc) · 2.59 KB
/
aqtree3clickable.js
File metadata and controls
91 lines (76 loc) · 2.59 KB
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
/*
aqtree3clickable.js
Converts an unordered list to an explorer-style tree, with clickable
icons
To make this work, simply add one line to your HTML:
<script type="text/javascript" src="aqtree3clickable.js"></script>
and then make the top UL of your nested unordered list of class
"aqtree3clickable".
That's it. No registration function, nothing.
http://www.kryogenix.org/code/browser/aqlists/
Stuart Langridge, November 2002
Inspired by Aaron's labels.js (http://youngpup.net/demos/labels/) and Dave Lindquist's menuDropDown.js (http://www.gazingus.org/dhtml/?id=109)
*/
addEvent(window, "load", makeTreesC);
function makeTreesC() {
// We don't actually need createElement, but we do
// need good DOM support, so this is a good check.
if (!document.createElement) return;
uls = document.getElementsByTagName("ul");
for (uli=0;uli<uls.length;uli++) {
ul = uls[uli];
if (ul.nodeName == "UL" && ul.className == "aqtree3clickable") {
processULELC(ul);
}
}
}
function processULELC(ul) {
if (!ul.childNodes || ul.childNodes.length == 0) return;
// Iterate LIs
for (var itemi=0;itemi<ul.childNodes.length;itemi++) {
var item = ul.childNodes[itemi];
if (item.nodeName == "LI") {
// Iterate things in this LI
var a;
var subul;
subul = "";
for (var sitemi=0;sitemi<item.childNodes.length;sitemi++) {
var sitem = item.childNodes[sitemi];
switch (sitem.nodeName) {
case "A": a = sitem; break;
case "UL": subul = sitem;
processULELC(subul);
break;
}
}
if (subul) {
associateELC(a,subul);
} else {
a.parentNode.className = "aq3bullet";
}
}
}
}
function associateELC(a,ul) {
if (a.parentNode.className.indexOf('aq3open') == -1)
a.parentNode.className = 'aq3closed';
a.onclick = function () {
this.parentNode.className = (this.parentNode.className=='aq3open') ? "aq3closed" : "aq3open";
return false;
}
}
/* Utility functions */
function addEvent(obj, evType, fn){
/* adds an eventListener for browsers which support it
Written by Scott Andrew: nice one, Scott */
if (obj.addEventListener){
obj.addEventListener(evType, fn, false);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent("on"+evType, fn);
return r;
} else {
return false;
}
}