[78ef36]: / docs-source / pytorch_sphinx_theme / js / side-menus.js

Download this file

208 lines (173 with data), 8.0 kB

  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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
window.sideMenus = {
rightMenuIsOnScreen: function() {
return document.getElementById("pytorch-content-right").offsetParent !== null;
},
isFixedToBottom: false,
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();
}
});
},
leftMenuIsFixed: function() {
return document.getElementById("pytorch-left-menu").classList.contains("make-fixed");
},
handleNavBar: function() {
var mainHeaderHeight = document.getElementById('header-holder').offsetHeight;
// If we are scrolled past the main navigation header fix the sub menu bar to top of page
if (utilities.scrollTop() >= mainHeaderHeight) {
document.getElementById("pytorch-left-menu").classList.add("make-fixed");
document.getElementById("pytorch-page-level-bar").classList.add("left-menu-is-fixed");
} else {
document.getElementById("pytorch-left-menu").classList.remove("make-fixed");
document.getElementById("pytorch-page-level-bar").classList.remove("left-menu-is-fixed");
}
},
expandClosestUnexpandedParentList: function (el) {
var closestParentList = utilities.closest(el, "ul");
if (closestParentList) {
var closestParentLink = closestParentList.previousElementSibling;
var closestParentLinkExists = closestParentLink &&
closestParentLink.tagName === "A" &&
closestParentLink.classList.contains("reference");
if (closestParentLinkExists) {
// Don't add expansion class to any title links
if (closestParentLink.classList.contains("title-link")) {
return;
}
closestParentList.style.display = "block";
closestParentLink.classList.remove("not-expanded");
closestParentLink.classList.add("expanded");
sideMenus.expandClosestUnexpandedParentList(closestParentLink);
}
}
},
handleLeftMenu: function () {
var windowHeight = utilities.windowHeight();
var topOfFooterRelativeToWindow = document.getElementById("docs-tutorials-resources").getBoundingClientRect().top;
if (topOfFooterRelativeToWindow >= windowHeight) {
document.getElementById("pytorch-left-menu").style.height = "100%";
} else {
var howManyPixelsOfTheFooterAreInTheWindow = windowHeight - topOfFooterRelativeToWindow;
var leftMenuDifference = howManyPixelsOfTheFooterAreInTheWindow;
document.getElementById("pytorch-left-menu").style.height = (windowHeight - leftMenuDifference) + "px";
}
},
handleRightMenu: function() {
var rightMenuWrapper = document.getElementById("pytorch-content-right");
var rightMenu = document.getElementById("pytorch-right-menu");
var rightMenuList = rightMenu.getElementsByTagName("ul")[0];
var article = document.getElementById("pytorch-article");
var articleHeight = article.offsetHeight;
var articleBottom = utilities.offset(article).top + articleHeight;
var mainHeaderHeight = document.getElementById('header-holder').offsetHeight;
if (utilities.scrollTop() < mainHeaderHeight) {
rightMenuWrapper.style.height = "100%";
rightMenu.style.top = 0;
rightMenu.classList.remove("scrolling-fixed");
rightMenu.classList.remove("scrolling-absolute");
} else {
if (rightMenu.classList.contains("scrolling-fixed")) {
var rightMenuBottom =
utilities.offset(rightMenuList).top + rightMenuList.offsetHeight;
if (rightMenuBottom >= articleBottom) {
rightMenuWrapper.style.height = articleHeight + mainHeaderHeight + "px";
rightMenu.style.top = utilities.scrollTop() - mainHeaderHeight + "px";
rightMenu.classList.add("scrolling-absolute");
rightMenu.classList.remove("scrolling-fixed");
}
} else {
rightMenuWrapper.style.height = articleHeight + mainHeaderHeight + "px";
rightMenu.style.top =
articleBottom - mainHeaderHeight - rightMenuList.offsetHeight + "px";
rightMenu.classList.add("scrolling-absolute");
}
if (utilities.scrollTop() < articleBottom - rightMenuList.offsetHeight) {
rightMenuWrapper.style.height = "100%";
rightMenu.style.top = "";
rightMenu.classList.remove("scrolling-absolute");
rightMenu.classList.add("scrolling-fixed");
}
}
var rightMenuSideScroll = document.getElementById("pytorch-side-scroll-right");
var sideScrollFromWindowTop = rightMenuSideScroll.getBoundingClientRect().top;
rightMenuSideScroll.style.height = utilities.windowHeight() - sideScrollFromWindowTop + "px";
}
};