-
Notifications
You must be signed in to change notification settings - Fork 318
/
Copy pathdoc_version_select.js
53 lines (44 loc) · 1.9 KB
/
doc_version_select.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
// The line below will be replaced to include any additional
// auto-detected versions. See script in docs.yaml.
var allVersions = ["develop", "master", "ros2", "v0.17.0", "v0.17.1", "v0.17.2", "v0.17.3", "v0.18.0", "v0.19.0", "v0.19.1"];
function buildSelect(currentVersion) {
if (!allVersions.includes(currentVersion)) {
allVersions.unshift(currentVersion);
}
// couldn't get external CSS stylesheet to apply here for some reason
var buf = ['<span id="versionselectorlabel">Astrobee Version:</span><select id="versionselector" style="font-size: 100%; padding: 3px 5px 3px 5px; margin-left: 5px;">'];
for (version of allVersions) {
buf.push('<option value="' + version + '"');
if (version == currentVersion) {
buf.push(' selected="selected"');
}
buf.push(">" + version + "</option>");
}
buf.push("</select>");
return buf.join("");
}
function detectCurrentVersion() {
const version_regex = /\/v\/(.*)\//;
var match = version_regex.exec(window.location.pathname);
if (match) {
return match[1];
} else {
return "(unknown)";
}
}
function onSelectorChange() {
var selector = document.getElementById("versionselector");
var currentVersion = detectCurrentVersion();
var selectedVersion = selector.value;
window.location.pathname = window.location.pathname.replace(currentVersion, selectedVersion);
}
function initVersionSelector() {
var currentVersion = detectCurrentVersion();
var projNumDiv = document.getElementById("projectnumber");
projNumDiv.innerHTML = buildSelect(currentVersion);
var selector = document.getElementById("versionselector");
// couldn't get external CSS stylesheet to apply here for some reason
document.getElementById('projectnumber').style = "position: relative; top: -0.3em;";
selector.addEventListener("change", onSelectorChange);
}
initVersionSelector();