-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathversion-menu.js.gotmpl
80 lines (60 loc) · 2.31 KB
/
version-menu.js.gotmpl
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
const versions = [
{{- range $version := .Versions }}
{path: "{{ $version.Path }}", text: "{{ $version.Text }}", selected: {{ $version.Selected }} },
{{- end}}
];
// Material theme
function addMaterialMenu(elt, versions) {
const current = versions.find(function (value) {
return value.selected
})
const rootLi = document.createElement('li');
rootLi.classList.add('md-nav__item');
rootLi.classList.add('md-nav__item--nested');
const input = document.createElement('input');
input.classList.add('md-toggle');
input.classList.add('md-nav__toggle');
input.setAttribute('data-md-toggle', 'nav-10000000');
input.id = "nav-10000000";
input.type = 'checkbox';
rootLi.appendChild(input);
const lbl01 = document.createElement('label')
lbl01.classList.add('md-nav__link');
lbl01.setAttribute('for', 'nav-10000000');
lbl01.textContent = current.text + " ";
rootLi.appendChild(lbl01);
const nav = document.createElement('nav')
nav.classList.add('md-nav');
nav.setAttribute('data-md-component','collapsible');
nav.setAttribute('data-md-level','1');
rootLi.appendChild(nav);
const lbl02 = document.createElement('label')
lbl02.classList.add('md-nav__title');
lbl02.setAttribute('for', 'nav-10000000');
lbl02.textContent = current.text + " ";
nav.appendChild(lbl02);
const ul = document.createElement('ul')
ul.classList.add('md-nav__list');
ul.setAttribute('data-md-scrollfix','');
nav.appendChild(ul);
for (let i = 0; i < versions.length; i++) {
const li = document.createElement('li');
li.classList.add('md-nav__item');
ul.appendChild(li);
const a = document.createElement('a');
a.classList.add('md-nav__link');
if (versions[i].selected) {
a.classList.add('md-nav__link--active');
}
a.href = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname.split("/")[1] + "/";
if (versions[i].path) {
a.href = a.href + "/" + versions[i].path + "/"
}
a.title = versions[i].text;
a.text = versions[i].text;
li.appendChild(a);
}
elt.appendChild(rootLi);
}
const materialSelector = 'div.md-container main.md-main div.md-main__inner.md-grid div.md-sidebar.md-sidebar--primary div.md-sidebar__scrollwrap div.md-sidebar__inner nav.md-nav.md-nav--primary ul.md-nav__list';
addMaterialMenu(elt, versions);