Skip to content

Commit 81e65cb

Browse files
authored
Merge pull request #87 from shiftlab/expand-sidebar
Expand Sidebar
2 parents 8ae2920 + 4d8c650 commit 81e65cb

File tree

4 files changed

+41
-32
lines changed

4 files changed

+41
-32
lines changed

js/theme.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -262,29 +262,35 @@ if (downloadNote.length >= 1) {
262262
$(".pytorch-call-to-action-links").hide();
263263
}
264264

265-
//This code makes the Notes section of the Docs Left Nav collapsible
266-
267-
if ($("p.caption:first").text() == "Notes") {
268-
269-
$("p.caption:first").addClass("left-nav-top-caption");
270-
$("span.caption-text:first").after("<span class='expand-menu'>[Expand]</span>");
271-
$(".expand-menu").after("<span class='hide-menu'>[Hide]</span>");
272-
$("p.caption:first").next("ul").hide();
265+
//This code handles the Expand/Hide toggle for the Docs/Tutorials left nav items
266+
267+
$("#pytorch-left-menu p.caption").each(function(){
268+
var collapsedSections = ['Notes'];
269+
var menuName = this.innerText.replace(/[^\w\s]/gi, '').trim();
270+
if (collapsedSections.includes(menuName) == true && $(this).children().not(".expand-menu")) {
271+
$(this).children("span").after("<span class='expand-menu'>[ + ]</span>");
272+
$(this).children("span").after("<span class='hide-menu collapse'>[ - ]</span>");
273+
$(this).next("ul").hide();
274+
}else{
275+
$(this).children("span").after("<span class='hide-menu'>[ - ]</span>");
276+
$(this).children("span").after("<span class='expand-menu collapse'>[ + ]</span>");
277+
}
278+
})
273279

274-
$(".expand-menu").on("click", function() {
275-
$(".hide-menu").toggle();
276-
toggleList(this);
277-
});
280+
$(".expand-menu").on("click", function() {
281+
$(this).next(".hide-menu").toggle();
282+
$(this).parent().next("ul").toggle();
283+
toggleList(this);
284+
});
278285

279-
$(".hide-menu").on("click", function() {
280-
$(".expand-menu").toggle();
281-
toggleList(this);
282-
});
286+
$(".hide-menu").on("click", function() {
287+
$(this).prev(".expand-menu").toggle();
288+
$(this).parent().next("ul").toggle();
289+
toggleList(this);
290+
});
283291

284-
function toggleList(menuCommand) {
285-
$(menuCommand).toggle();
286-
$("p.caption:first").next("ul").toggle();
287-
}
292+
function toggleList(menuCommand) {
293+
$(menuCommand).toggle();
288294
}
289295

290296
// Get the card link from the card's link attribute

pytorch_sphinx_theme/static/css/theme.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pytorch_sphinx_theme/static/js/theme.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -957,28 +957,31 @@ if (downloadNote.length >= 1) {
957957
$(".pytorch-call-to-action-links").hide();
958958
}
959959

960-
//This code makes the Notes section of the Docs Left Nav collapsible
960+
//This code handles the Expand/Hide toggle for the Docs/Tutorials left nav items
961961

962-
if ($("p.caption:first").text() == "Notes") {
962+
var expandMenu = "#pytorch-left-menu p.caption";
963963

964-
$("p.caption:first").addClass("left-nav-top-caption");
965-
$("span.caption-text:first").after("<span class='expand-menu'>[Expand]</span>");
966-
$(".expand-menu").after("<span class='hide-menu'>[Hide]</span>");
967-
$("p.caption:first").next("ul").hide();
964+
if ($(expandMenu)) {
965+
966+
$(expandMenu).addClass("left-nav-top-caption");
967+
$("#pytorch-left-menu span.caption-text").after("<span class='expand-menu'>[ + ]</span>");
968+
$("#pytorch-left-menu .expand-menu").after("<span class='hide-menu'>[ - ]</span>");
969+
$(expandMenu).next("ul").hide();
968970

969971
$(".expand-menu").on("click", function() {
970-
$(".hide-menu").toggle();
972+
$(this).next(".hide-menu").toggle();
973+
$(this).parent().next("ul").toggle();
971974
toggleList(this);
972975
});
973976

974977
$(".hide-menu").on("click", function() {
975-
$(".expand-menu").toggle();
978+
$(this).prev(".expand-menu").toggle();
979+
$(this).parent().next("ul").toggle();
976980
toggleList(this);
977981
});
978982

979983
function toggleList(menuCommand) {
980984
$(menuCommand).toggle();
981-
$("p.caption:first").next("ul").toggle();
982985
}
983986
}
984987

scss/_sphinx_layout.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
cursor: pointer;
156156
}
157157

158-
.hide-menu {
158+
.collapse {
159159
display: none;
160160
}
161161

@@ -170,7 +170,7 @@
170170
line-height: rem(22px);
171171
margin-bottom: rem(16px);
172172
text-transform: none;
173-
white-space: nowrap;
173+
white-space: normal;
174174
}
175175

176176
.pytorch-left-menu-search {

0 commit comments

Comments
 (0)