-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathversion-switcher.js
40 lines (37 loc) · 1.58 KB
/
version-switcher.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
/**
* Adds the link to available documentation page as the last entry in the version
* switcher dropdown. Since other entries in the dropdown are also added dynamically,
* we only add the link when the user clicks on some version switcher button to make
* sure that this entry is the last one.
*/
function addVersionSwitcherAvailDocsLink() {
var availDocsLinkAdded = false;
// There can be multiple version switcher buttons because there is at least one for
// laptop size and one for mobile size (in the sidebar)
document
.querySelectorAll(".version-switcher__button")
.forEach(function (btn) {
btn.addEventListener("click", function () {
if (!availDocsLinkAdded) {
// All version switcher dropdowns are updated once any button is clicked
document
.querySelectorAll(".version-switcher__menu")
.forEach(function (menu) {
var availDocsLink = document.createElement("a");
availDocsLink.setAttribute(
"href",
"https://scikit-learn.org/dev/versions.html"
);
availDocsLink.innerHTML = "More";
// We use the same class as the last entry to be safe
availDocsLink.className = menu.lastChild.className;
availDocsLink.classList.add("sk-avail-docs-link");
menu.appendChild(availDocsLink);
});
// Set the flag so we do not add again
availDocsLinkAdded = true;
}
});
});
}
document.addEventListener("DOMContentLoaded", addVersionSwitcherAvailDocsLink);