Skip to content

Commit c310228

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

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

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

+20-14
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

+4-14
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,21 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
7373

7474
let toggleLabel;
7575

76-
function getToggleLabel() {
77-
toggleLabel = toggleLabel || document.querySelector("#src-sidebar-toggle button");
78-
return toggleLabel;
79-
}
80-
8176
window.rustdocCloseSourceSidebar = () => {
8277
removeClass(document.documentElement, "src-sidebar-expanded");
83-
getToggleLabel().innerText = ">";
8478
updateLocalStorage("source-sidebar-show", "false");
8579
};
8680

8781
window.rustdocShowSourceSidebar = () => {
8882
addClass(document.documentElement, "src-sidebar-expanded");
89-
getToggleLabel().innerText = "<";
9083
updateLocalStorage("source-sidebar-show", "true");
9184
};
9285

9386
function toggleSidebar() {
94-
const child = this.parentNode.children[0];
95-
if (child.innerText === ">") {
96-
window.rustdocShowSourceSidebar();
97-
} else {
87+
if (document.documentElement.classList.contains("src-sidebar-expanded")) {
9888
window.rustdocCloseSourceSidebar();
89+
} else {
90+
window.rustdocShowSourceSidebar();
9991
}
10092
}
10193

@@ -106,9 +98,7 @@ function createSidebarToggle() {
10698
const inner = document.createElement("button");
10799

108100
if (getCurrentValue("source-sidebar-show") === "true") {
109-
inner.innerText = "<";
110-
} else {
111-
inner.innerText = ">";
101+
window.rustdocShowSourceSidebar();
112102
}
113103
inner.onclick = toggleSidebar;
114104

0 commit comments

Comments
 (0)