Skip to content

Commit ac97299

Browse files
Simplify source pages sidebar handling
1 parent 028a313 commit ac97299

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,26 @@ a.tooltip:hover::after {
15401540
align-items: stretch;
15411541
z-index: 10;
15421542
}
1543+
#src-sidebar-toggle > button {
1544+
font-size: inherit;
1545+
font-weight: bold;
1546+
background: none;
1547+
color: inherit;
1548+
text-align: center;
1549+
border: none;
1550+
outline: none;
1551+
flex: 1 1;
1552+
/* iOS button gradient: https://stackoverflow.com/q/5438567 */
1553+
-webkit-appearance: none;
1554+
opacity: 1;
1555+
}
1556+
#src-sidebar-toggle > button::before {
1557+
content: ">";
1558+
}
1559+
.src-sidebar-expanded #src-sidebar-toggle > button::before {
1560+
content: "<";
1561+
}
1562+
15431563
#src-sidebar {
15441564
width: 100%;
15451565
overflow: auto;
@@ -1557,20 +1577,6 @@ a.tooltip:hover::after {
15571577
#src-sidebar div.files > a.selected {
15581578
background-color: var(--src-sidebar-background-selected);
15591579
}
1560-
#src-sidebar-toggle > button {
1561-
font-size: inherit;
1562-
font-weight: bold;
1563-
background: none;
1564-
color: inherit;
1565-
text-align: center;
1566-
border: none;
1567-
outline: none;
1568-
flex: 1 1;
1569-
/* iOS button gradient: https://stackoverflow.com/q/5438567 */
1570-
-webkit-appearance: none;
1571-
opacity: 1;
1572-
}
1573-
15741580
#settings-menu, #help-button {
15751581
margin-left: 4px;
15761582
display: flex;

src/librustdoc/html/static/js/src-script.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,21 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
7171
return hasFoundFile;
7272
}
7373

74-
let toggleLabel;
75-
76-
function getToggleLabel() {
77-
toggleLabel = toggleLabel || document.querySelector("#src-sidebar-toggle button");
78-
return toggleLabel;
79-
}
80-
8174
window.rustdocCloseSourceSidebar = () => {
8275
removeClass(document.documentElement, "src-sidebar-expanded");
83-
getToggleLabel().innerText = ">";
8476
updateLocalStorage("source-sidebar-show", "false");
8577
};
8678

8779
window.rustdocShowSourceSidebar = () => {
8880
addClass(document.documentElement, "src-sidebar-expanded");
89-
getToggleLabel().innerText = "<";
9081
updateLocalStorage("source-sidebar-show", "true");
9182
};
9283

9384
function toggleSidebar() {
94-
const child = this.parentNode.children[0];
95-
if (child.innerText === ">") {
96-
window.rustdocShowSourceSidebar();
97-
} else {
85+
if (document.documentElement.classList.contains("src-sidebar-expanded")) {
9886
window.rustdocCloseSourceSidebar();
87+
} else {
88+
window.rustdocShowSourceSidebar();
9989
}
10090
}
10191

@@ -106,9 +96,7 @@ function createSidebarToggle() {
10696
const inner = document.createElement("button");
10797

10898
if (getCurrentValue("source-sidebar-show") === "true") {
109-
inner.innerText = "<";
110-
} else {
111-
inner.innerText = ">";
99+
window.rustdocShowSourceSidebar();
112100
}
113101
inner.onclick = toggleSidebar;
114102

0 commit comments

Comments
 (0)