-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsidenav.js
149 lines (132 loc) · 4.71 KB
/
sidenav.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Script provides methods for sidebar navigation behavior
/**
* Adds links based on tree element to side bar navigation.
*/
function addSideNavLinks() {
let tree = JSON.parse(getDataFromSessionStorage(repoName + "Tree"));
if (!tree) return;
let decomBlocks = JSON.parse(getDataFromSessionStorage(repoName + "decomBlocks"));
if (!decomBlocks) return;
decomBlocks.forEach(function (d) {
// append button
let btn = $("<a></a>")
.html(d)
.appendTo($("#side_nav_links"))
$("<i></i>")
.addClass("fa fa-caret-down")
.appendTo(btn);
// add links for each node of block
let ddLinks = [];
tree.forEach(function (n) {
if (n.decomBlock == d) {
// add node
let nodeName = n.title.replace(/[^A-Z0-9]/ig, "_").toLowerCase();
ddLinks.push(
$("<a></a>")
.attr("onclick", "navLink('" + n.title + "')")
.html(n.title)
);
}
});
$("#side_nav_links").append(createDropDownContainer(ddLinks));
// add listener
btn.on("click", function () {
let localALinks = JSON.parse(getDataFromSessionStorage(repoName + "ActiveLinks"));
if (!localALinks) return;
this.classList.toggle("active");
var dropdownContent = this.nextElementSibling;
var caretIcon = this.querySelector("i"); // Get the caret icon element
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
let index = localALinks.indexOf(this.innerText)
localALinks.splice(index, 1);
caretIcon.classList.remove("fa-caret-up"); // Remove the up arrow class
caretIcon.classList.add("fa-caret-down"); // Add the down arrow class
} else {
dropdownContent.style.display = "block";
localALinks.push(this.innerText);
caretIcon.classList.remove("fa-caret-down"); // Remove the down arrow class
caretIcon.classList.add("fa-caret-up"); // Add the up arrow class
}
keepDataInSessionStorage(repoName + "ActiveLinks", JSON.stringify(localALinks));
});
// set currently active links
let aLinks = JSON.parse(getDataFromSessionStorage(repoName + "ActiveLinks"));
if (!aLinks) return;
if (aLinks.includes(btn.text())) {
btn.next().css("display", "block");
btn.toggleClass("active");
}
});
}
/**
* Gets the path to link
* @returns path to source
*/
function getLinkPath() {
if (window.location.href.includes("localhost")) {
// set path for local development
return window.location.origin;
}
else {
// get repo name
let repoName = window.location.pathname.split("/")[1];
return `${window.location.origin}/${repoName}`;
}
}
/**
* Creates a dropdown container
* @param {Array} linkArray of links to add to the container
* @returns container element
*/
function createDropDownContainer(linkArray) {
let ddContainer = $("<div></div>")
.addClass("dropdown-container");
linkArray.forEach(function (l) {
ddContainer.append(l);
});
return ddContainer;
}
/**
* Creates navigation links
* @param {String} title title of node
* @param {String} id id of node
*/
function navLink(title) {
let node = getNodeByTitle(title);
$("#info_box").empty();
expandSearchedNodeTree(node);
addNodeInfos(node, "preview");
updateGraphPlot(node.id);
}
/**
* Creates a link element
* @param {String} name innerHTML of link
* @param {String} url of link
* @returns link element
*/
function createLink(name, url) {
return $("<a></a>")
.attr("href", url)
.html(name);
}
function addTreesLinks()
{
const treesLinksContainer = document.createElement('div');
treesLinksContainer.classList.add('tree_links_container');
const horizontalLine = document.createElement('hr');
horizontalLine.classList.add('h_line');
const sideNav = document.getElementById('side_nav');
sideNav.appendChild(horizontalLine)
let repos = ["LidarLimbs", "RadarRami", "UltrasonicUnderwood", "CameraCopse"];
repos.forEach(function(repo){
if(repo !== repoName) {
let treeElement = document.createElement('a');
let treeLink = document.createTextNode(repo);
treeElement.appendChild(treeLink);
treeElement.href = "https://percollect.github.io/" + repo + "/";
treesLinksContainer.appendChild(treeElement);
}
})
sideNav.appendChild(treesLinksContainer)
}