1 function genLink(Ref) {
2 // we treat the file paths different depending on if we're
3 // serving via a http server or viewing from a local
4 var Path = window.location.protocol.startsWith("file") ?
5 `${window.location.protocol}//${window.location.host}/${Ref.Path}` :
6 `${window.location.protocol}//${RootPath}/${Ref.Path}`;
7 if (Ref.RefType === "namespace") {
8 Path = `${Path}/index.html`
9 } else if (Ref.Path === "") {
10 Path = `${Path}${Ref.Name}.html`;
12 Path = `${Path}/${Ref.Name}.html`;
14 ANode = document.createElement("a");
15 ANode.setAttribute("href", Path);
16 var TextNode = document.createTextNode(Ref.Name);
17 ANode.appendChild(TextNode);
21 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
22 // Out will store the HTML elements that Index requires to be generated
25 var SpanNode = document.createElement("span");
26 var TextNode = document.createTextNode(Index.Name);
27 SpanNode.appendChild(genLink(Index, CurrentDirectory));
30 if (Index.Children.length == 0)
32 // Only the outermost list should use ol, the others should use ul
33 var ListNodeName = IsOutermostList ? "ol" : "ul";
34 var ListNode = document.createElement(ListNodeName);
35 for (Child of Index.Children) {
36 var LiNode = document.createElement("li");
37 ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
38 for (Node of ChildNodes)
39 LiNode.appendChild(Node);
40 ListNode.appendChild(LiNode);
46 function createIndex(Index) {
47 // Get the DOM element where the index will be created
48 var IndexDiv = document.getElementById("sidebar-left");
49 // Get the relative path of this file
50 CurrentDirectory = IndexDiv.getAttribute("path");
51 var IndexNodes = genHTMLOfIndex(Index, CurrentDirectory, true);
52 for (Node of IndexNodes)
53 IndexDiv.appendChild(Node);
56 // Runs after DOM loads
57 document.addEventListener("DOMContentLoaded", function() {
58 // LoadIndex is an asynchronous function that will be generated clang-doc.
59 // It ensures that the function call will not block as soon the page loads,
60 // since the index object are often huge and can contain thousands of lines.
61 LoadIndex().then((Index) => { createIndex(Index); });