1 // Append using posix-style a file name or directory to Base
2 function append(Base
, New
) {
11 // Get relative path to access FilePath from CurrentDirectory
12 function computeRelativePath(FilePath
, CurrentDirectory
) {
15 if (CurrentDirectory
== Path
)
16 return FilePath
.substring(Path
.length
+ 1);
17 Path
= Path
.substring(0, Path
.lastIndexOf("/"));
20 var Dir
= CurrentDirectory
;
25 Dir
= Dir
.substring(0, Dir
.lastIndexOf("/"));
26 Result
= append(Result
, "..")
28 Result
= append(Result
, FilePath
.substring(Dir
.length
))
32 function genLink(Ref
, CurrentDirectory
) {
33 var Path
= computeRelativePath(Ref
.Path
, CurrentDirectory
);
34 if (Ref
.RefType
== "namespace")
35 Path
= append(Path
, "index.html");
37 Path
= append(Path
, Ref
.Name
+ ".html")
39 ANode
= document
.createElement("a");
40 ANode
.setAttribute("href", Path
);
41 var TextNode
= document
.createTextNode(Ref
.Name
);
42 ANode
.appendChild(TextNode
);
46 function genHTMLOfIndex(Index
, CurrentDirectory
, IsOutermostList
) {
47 // Out will store the HTML elements that Index requires to be generated
50 var SpanNode
= document
.createElement("span");
51 var TextNode
= document
.createTextNode(Index
.Name
);
52 SpanNode
.appendChild(genLink(Index
, CurrentDirectory
));
55 if (Index
.Children
.length
== 0)
57 // Only the outermost list should use ol, the others should use ul
58 var ListNodeName
= IsOutermostList
? "ol" : "ul";
59 var ListNode
= document
.createElement(ListNodeName
);
60 for (Child
of Index
.Children
) {
61 var LiNode
= document
.createElement("li");
62 ChildNodes
= genHTMLOfIndex(Child
, CurrentDirectory
, false);
63 for (Node
of ChildNodes
)
64 LiNode
.appendChild(Node
);
65 ListNode
.appendChild(LiNode
);
71 function createIndex(Index
) {
72 // Get the DOM element where the index will be created
73 var IndexDiv
= document
.getElementById("sidebar-left");
74 // Get the relative path of this file
75 CurrentDirectory
= IndexDiv
.getAttribute("path");
76 var IndexNodes
= genHTMLOfIndex(Index
, CurrentDirectory
, true);
77 for (Node
of IndexNodes
)
78 IndexDiv
.appendChild(Node
);
81 // Runs after DOM loads
82 document
.addEventListener("DOMContentLoaded", function() {
83 // JsonIndex is a variable from another file that contains the index
85 var Index
= JSON
.parse(JsonIndex
);