blob: a209d12adb342c5483cf95e090225c2f97a3cb02 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001
2function new_node(me, mom, text, link, children_data)
3{
4 var node = new Object();
5 node.children = Array();
6 node.children_data = children_data;
7 node.depth = mom.depth + 1;
8
9 node.li = document.createElement("li");
10 mom.get_children_ul().appendChild(node.li);
11
12 node.label_div = document.createElement("div");
13 node.li.appendChild(node.label_div);
14 node.label_div.style.paddingLeft = 10*node.depth + "px";
15 node.label_div.className = "label";
16
17 if (children_data == null) {
18 // 12 is the width of the triangle and padding extra space
19 node.label_div.style.paddingLeft = ((10*node.depth)+12) + "px";
20 } else {
21 node.label_div.style.paddingLeft = 10*node.depth + "px";
22 node.expand_toggle = document.createElement("a");
23 node.expand_toggle.href = "javascript:void(0)";
24 node.expand_toggle.onclick = function() {
25 if (node.expanded) {
26 $(node.get_children_ul()).slideUp("fast");
27 node.plus_img.src = me.toroot + "assets/images/triangle-closed-small.png";
28 node.expanded = false;
29 } else {
30 expand_node(me, node);
31 }
32 };
33 node.label_div.appendChild(node.expand_toggle);
34
35 node.plus_img = document.createElement("img");
36 node.plus_img.src = me.toroot + "assets/images/triangle-closed-small.png";
37 node.plus_img.className = "plus";
38 node.plus_img.border = "0";
39 node.expand_toggle.appendChild(node.plus_img);
40
41 node.expanded = false;
42 }
43
44 var a = document.createElement("a");
45 node.label_div.appendChild(a);
46 node.label = document.createTextNode(text);
47 a.appendChild(node.label);
48 if (link) {
49 a.href = me.toroot + link;
50 } else {
51 if (children_data != null) {
52 a.className = "nolink";
53 a.href = "javascript:void(0)";
54 a.onclick = node.expand_toggle.onclick;
55 // This next line shouldn't be necessary. I'll buy a beer for the first
56 // person who figures out how to remove this line and have the link
57 // toggle shut on the first try. --joeo@android.com
58 node.expanded = false;
59 }
60 }
61
62
63 node.children_ul = null;
64 node.get_children_ul = function() {
65 if (!node.children_ul) {
66 node.children_ul = document.createElement("ul");
67 node.children_ul.className = "children_ul";
68 node.children_ul.style.display = "none";
69 node.li.appendChild(node.children_ul);
70 }
71 return node.children_ul;
72 };
73
74 return node;
75}
76
77function expand_node(me, node)
78{
79 if (node.children_data && !node.expanded) {
80 if (node.children_visited) {
81 $(node.get_children_ul()).slideDown("fast");
82 } else {
83 get_node(me, node);
84 $(node.get_children_ul()).slideDown("fast");
85 }
86 node.plus_img.src = me.toroot + "assets/images/triangle-opened-small.png";
87 node.expanded = true;
88 }
89}
90
91function get_node(me, mom)
92{
93 mom.children_visited = true;
94 for (var i in mom.children_data) {
95 var node_data = mom.children_data[i];
96 mom.children[i] = new_node(me, mom, node_data[0], node_data[1],
97 node_data[2]);
98 }
99}
100
101function this_page_relative(toroot)
102{
103 var full = document.location.pathname;
104 var file = "";
105 if (toroot.substr(0, 1) == "/") {
106 if (full.substr(0, toroot.length) == toroot) {
Scott Main8ebeb522009-07-08 14:45:58 -0700107 var basePath = getBaseUri(full);
108 return basePath.substring(toroot.length);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800109 } else {
110 // the file isn't under toroot. Fail.
111 return null;
112 }
113 } else {
114 if (toroot != "./") {
115 toroot = "./" + toroot;
116 }
117 do {
118 if (toroot.substr(toroot.length-3, 3) == "../" || toroot == "./") {
119 var pos = full.lastIndexOf("/");
120 file = full.substr(pos) + file;
121 full = full.substr(0, pos);
122 toroot = toroot.substr(0, toroot.length-3);
123 }
124 } while (toroot != "" && toroot != "/");
125 return file.substr(1);
126 }
127}
128
129function find_page(url, data)
130{
131 var nodes = data;
132 var result = null;
133 for (var i in nodes) {
134 var d = nodes[i];
135 if (d[1] == url) {
136 return new Array(i);
137 }
138 else if (d[2] != null) {
139 result = find_page(url, d[2]);
140 if (result != null) {
141 return (new Array(i).concat(result));
142 }
143 }
144 }
145 return null;
146}
147
148function init_navtree(navtree_id, toroot, root_nodes)
149{
150 var me = new Object();
151 me.toroot = toroot;
152 me.node = new Object();
153
154 me.node.li = document.getElementById(navtree_id);
155 me.node.children_data = root_nodes;
156 me.node.children = new Array();
157 me.node.children_ul = document.createElement("ul");
158 me.node.get_children_ul = function() { return me.node.children_ul; };
159 //me.node.children_ul.className = "children_ul";
160 me.node.li.appendChild(me.node.children_ul);
161 me.node.depth = 0;
162
163 get_node(me, me.node);
164
165 me.this_page = this_page_relative(toroot);
166 me.breadcrumbs = find_page(me.this_page, root_nodes);
167 if (me.breadcrumbs != null && me.breadcrumbs.length != 0) {
168 var mom = me.node;
169 for (var i in me.breadcrumbs) {
170 var j = me.breadcrumbs[i];
171 mom = mom.children[j];
172 expand_node(me, mom);
173 }
174 mom.label_div.className = mom.label_div.className + " selected";
175 addLoadEvent(function() {
176 scrollIntoView("nav-tree");
177 });
178 }
179}
180