3 xmlns=
"http://www.w3.org/TR/html4/"
4 xmlns:
empathy=
"http://live.gnome.org/Empathy">
6 <style type=
"text/css">
23 white-space: pre-wrap;
42 vertical-align: middle;
46 <script type=
"text/javascript">
47 var EMPATHY_NS='http://live.gnome.org/Empathy';
49 function filterNodes (node, tagName)
51 var out = new Array();
53 for (var i =
0; i < node.childNodes.length; i++)
55 var elem = node.childNodes[i];
57 if (elem.tagName == tagName)
64 function getNodes(node)
66 return filterNodes(node, 'DIV');
69 function getContent(node)
71 return filterNodes(node, 'P')[
0];
74 function getToggle(node)
76 return filterNodes(node, 'SPAN')[
0];
79 function setExpander(node, open)
81 var toggle = getToggle(node);
87 toggle.setAttribute('class', 'open');
92 toggle.setAttribute('class', 'closed');
96 nodes = getNodes(node);
98 for (var i =
0; i < nodes.length; i++)
99 nodes[i].style.display = display;
104 function expandAllRecurse(node)
106 var nodes = getNodes(node);
108 for (var i =
0; i < nodes.length; i++)
110 setExpander(nodes[i], true);
112 expandAllRecurse(nodes[i]);
116 var treeview = document.getElementById('treeview');
118 expandAllRecurse(treeview);
121 function setContent (contents, text, icon, date_)
123 contents.innerHTML =
"";
127 contents.innerHTML += '
<img class=
"icon" src=
"' + icon + '"/>';
130 contents.innerHTML += text;
131 contents.innerHTML += '
<span class=
"date">' + date_ + '
</span>';
134 function insertRow (path, text, icon, date_)
136 var treeview = document.getElementById('treeview');
137 var parentnode = treeview;
141 for (i =
0; i < path.length -
1; i++)
142 parentnode = getNodes(parentnode)[path[i]];
145 var newnode = document.createElement('div');
146 newnode.setAttribute('class', 'row');
148 // insert the new node into the tree
149 var nodes = getNodes(parentnode);
151 if (path[i]
>= nodes.length)
152 parentnode.appendChild(newnode);
154 parentnode.insertBefore(newnode, nodes[path[i]]);
157 newnode.setAttributeNS(EMPATHY_NS, 'path', path.join(':'));
160 var toggle = document.createElement('span');
161 newnode.appendChild(toggle);
162 toggle.setAttribute('class', 'closed');
163 toggle.style.display = 'none';
165 var contents = document.createElement('p');
166 newnode.appendChild(contents);
167 setContent(contents, text, icon, date_);
169 function toggleExpander (e)
171 if (toggle.getAttribute('class') == 'closed')
172 setExpander(newnode, true);
174 setExpander(newnode, false);
177 toggle.onclick = toggleExpander;
178 contents.ondblclick = toggleExpander;
180 // if the node is not a top-level node, hide it
181 if (parentnode != treeview)
182 newnode.style.display = 'none';
185 function changeRow (path, text, icon, date_)
187 var treeview = document.getElementById('treeview');
191 for (var i =
0; i < path.length; i++)
192 node = getNodes(node)[path[i]];
195 var contents = getContent(node);
196 setContent(contents, text, icon, date_);
199 function deleteRow (path)
201 var treeview = document.getElementById('treeview');
205 for (var i =
0; i < path.length; i++)
206 node = getNodes(node)[path[i]];
208 node.parentNode.removeChild(node);
211 function reorderRows (path, new_order)
213 var treeview = document.getElementById('treeview');
217 for (var i =
0; i < path.length; i++)
218 node = getNodes(node)[path[i]];
220 var nodes = getNodes(node);
222 // remove all the nodes from the DOM
223 for (var i =
0; i < nodes.length; i++)
224 node.removeChild(nodes[i]);
226 // put them back in the new order
227 // For reference: new_order[new_pos] = old_pos
228 for (var i =
0; i < nodes.length; i++)
229 node.appendChild(nodes[new_order[i]]);
231 // recursively update the path
232 function updatePaths(path, node)
234 var nodes = getNodes(node);
236 for (var i =
0; i < nodes.length; i++)
238 var newpath = path.concat([i]);
240 nodes[i].setAttributeNS(EMPATHY_NS, 'path', newpath.join(':'));
241 updatePaths(newpath, nodes[i]);
245 updatePaths(path, node);
248 function hasChildRows (path, has_children)
250 var treeview = document.getElementById('treeview');
254 for (var i =
0; i < path.length; i++)
255 node = getNodes(node)[path[i]];
257 var toggle = getToggle(node);
260 toggle.style.display = 'inline';
262 toggle.style.display = 'none';
265 function getOffset (node)
269 while (node != null && !isNaN(node.offsetTop))
271 y += node.offsetTop - node.scrollTop;
272 node = node.offsetParent;
278 function scrollToRow (path)
280 var treeview = document.getElementById('treeview');
284 for (var i =
0; i < path.length; i++)
285 node = getNodes(node)[path[i]];
287 window.scrollTo(
0, getOffset(node));