Skip to content

Commit

Permalink
Simplify source pages sidebar handling
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 16, 2023
1 parent 028a313 commit c310228
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
34 changes: 20 additions & 14 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,26 @@ a.tooltip:hover::after {
align-items: stretch;
z-index: 10;
}
#src-sidebar-toggle > button {
font-size: inherit;
font-weight: bold;
background: none;
color: inherit;
text-align: center;
border: none;
outline: none;
flex: 1 1;
/* iOS button gradient: https://stackoverflow.com/q/5438567 */
-webkit-appearance: none;
opacity: 1;
}
#src-sidebar-toggle > button::before {
content: ">";
}
.src-sidebar-expanded #src-sidebar-toggle > button::before {
content: "<";
}

#src-sidebar {
width: 100%;
overflow: auto;
Expand All @@ -1557,20 +1577,6 @@ a.tooltip:hover::after {
#src-sidebar div.files > a.selected {
background-color: var(--src-sidebar-background-selected);
}
#src-sidebar-toggle > button {
font-size: inherit;
font-weight: bold;
background: none;
color: inherit;
text-align: center;
border: none;
outline: none;
flex: 1 1;
/* iOS button gradient: https://stackoverflow.com/q/5438567 */
-webkit-appearance: none;
opacity: 1;
}

#settings-menu, #help-button {
margin-left: 4px;
display: flex;
Expand Down
18 changes: 4 additions & 14 deletions src/librustdoc/html/static/js/src-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,21 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {

let toggleLabel;

function getToggleLabel() {
toggleLabel = toggleLabel || document.querySelector("#src-sidebar-toggle button");
return toggleLabel;
}

window.rustdocCloseSourceSidebar = () => {
removeClass(document.documentElement, "src-sidebar-expanded");
getToggleLabel().innerText = ">";
updateLocalStorage("source-sidebar-show", "false");
};

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

function toggleSidebar() {
const child = this.parentNode.children[0];
if (child.innerText === ">") {
window.rustdocShowSourceSidebar();
} else {
if (document.documentElement.classList.contains("src-sidebar-expanded")) {
window.rustdocCloseSourceSidebar();
} else {
window.rustdocShowSourceSidebar();
}
}

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

if (getCurrentValue("source-sidebar-show") === "true") {
inner.innerText = "<";
} else {
inner.innerText = ">";
window.rustdocShowSourceSidebar();
}
inner.onclick = toggleSidebar;

Expand Down

0 comments on commit c310228

Please sign in to comment.