Skip to content

Remember state of top-level collapse toggle widget #48631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 13, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,7 @@
function toggleAllDocs() {
var toggle = document.getElementById("toggle-all-docs");
if (hasClass(toggle, "will-expand")) {
updateLocalStorage("collapse", "false");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like "too simple" for a name. Can you replace it with "rustdoc-collapse" please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please use booleans instead of strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values end up in localStorage, which converts all values to strings so I thought it clearer to avoid any type coercion and use strings always.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't know, thanks for the clarification! Then just ignore this comment.

removeClass(toggle, "will-expand");
onEveryMatchingChild(toggle, "inner", function(e) {
e.innerHTML = labelForToggleButton(false);
Expand All @@ -1632,6 +1633,7 @@
collapseDocs(e, "show");
});
} else {
updateLocalStorage("collapse", "true");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

addClass(toggle, "will-expand");
onEveryMatchingChild(toggle, "inner", function(e) {
e.innerHTML = labelForToggleButton(true);
Expand Down Expand Up @@ -1972,6 +1974,10 @@
window.onresize = function() {
hideSidebar();
};

if (getCurrentValue("collapse") === "true") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update this line as well. ;)

toggleAllDocs();
}
}());

// Sets the focus on the search bar at the top of the page
Expand Down