-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimeforkhtmlrenderer.js
41 lines (32 loc) · 1.16 KB
/
timeforkhtmlrenderer.js
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
var TimeForkHtmlRenderer = function(elem) {
this.elem = elem
}
TimeForkHtmlRenderer.prototype.makeContainer = function(){
this.container = document.createElement('ul');
this.container.id = "history";
this.elem.appendChild(this.container);
}
TimeForkHtmlRenderer.prototype.render = function(timefork){
if(!this.container){
this.makeContainer();
}
this.container.innerHTML = "";
this.container.appendChild(this.renderTree(timefork.stateTree, timefork.activeNodes()));
};
TimeForkHtmlRenderer.prototype.renderTree = function(tree, activeNodes) {
var rendering = document.createElement('li');
if (activeNodes.indexOf(tree) != -1) {
rendering.setAttribute("class", "active");
}
rendering.innerHTML = this.renderNode(tree);
var branches = document.createElement('ul');
for (branch in tree.branches) {
console.log(branch);
branches.appendChild(this.renderTree(tree.branches[branch], activeNodes));
}
rendering.appendChild(branches);
return rendering;
};
TimeForkHtmlRenderer.prototype.renderNode = function(node) {
return '<a href="#' + node.eventTime + '">' + (uneval(node.propState.delta()) || " ") + '</a>';
}