in js/side-menus.js [8:107]
bind: function() {
sideMenus.handleLeftMenu();
var rightMenuLinks = document.querySelectorAll("#pytorch-right-menu li");
var rightMenuHasLinks = rightMenuLinks.length > 1;
if (!rightMenuHasLinks) {
for (var i = 0; i < rightMenuLinks.length; i++) {
rightMenuLinks[i].style.display = "none";
}
}
if (rightMenuHasLinks) {
// Don't show the Shortcuts menu title text unless there are menu items
document.getElementById("pytorch-shortcuts-wrapper").style.display = "block";
// We are hiding the titles of the pages in the right side menu but there are a few
// pages that include other pages in the right side menu (see 'torch.nn' in the docs)
// so if we exclude those it looks confusing. Here we add a 'title-link' class to these
// links so we can exclude them from normal right side menu link operations
var titleLinks = document.querySelectorAll(
"#pytorch-right-menu #pytorch-side-scroll-right \
> ul > li > a.reference.internal"
);
for (var i = 0; i < titleLinks.length; i++) {
var link = titleLinks[i];
link.classList.add("title-link");
if (
link.nextElementSibling &&
link.nextElementSibling.tagName === "UL" &&
link.nextElementSibling.children.length > 0
) {
link.classList.add("has-children");
}
}
// Add + expansion signifiers to normal right menu links that have sub menus
var menuLinks = document.querySelectorAll(
"#pytorch-right-menu ul li ul li a.reference.internal"
);
for (var i = 0; i < menuLinks.length; i++) {
if (
menuLinks[i].nextElementSibling &&
menuLinks[i].nextElementSibling.tagName === "UL"
) {
menuLinks[i].classList.add("not-expanded");
}
}
// If a hash is present on page load recursively expand menu items leading to selected item
var linkWithHash =
document.querySelector(
"#pytorch-right-menu a[href=\"" + window.location.hash + "\"]"
);
if (linkWithHash) {
// Expand immediate sibling list if present
if (
linkWithHash.nextElementSibling &&
linkWithHash.nextElementSibling.tagName === "UL" &&
linkWithHash.nextElementSibling.children.length > 0
) {
linkWithHash.nextElementSibling.style.display = "block";
linkWithHash.classList.add("expanded");
}
// Expand ancestor lists if any
sideMenus.expandClosestUnexpandedParentList(linkWithHash);
}
// Bind click events on right menu links
$("#pytorch-right-menu a.reference.internal").on("click", function() {
if (this.classList.contains("expanded")) {
this.nextElementSibling.style.display = "none";
this.classList.remove("expanded");
this.classList.add("not-expanded");
} else if (this.classList.contains("not-expanded")) {
this.nextElementSibling.style.display = "block";
this.classList.remove("not-expanded");
this.classList.add("expanded");
}
});
sideMenus.handleRightMenu();
}
$(window).on('resize scroll', function(e) {
sideMenus.handleNavBar();
sideMenus.handleLeftMenu();
if (sideMenus.rightMenuIsOnScreen()) {
sideMenus.handleRightMenu();
}
});
},