Skip to content
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

Save crate filtering on rustdoc #62941

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 18 additions & 2 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,21 @@ if (!DOMTokenList.prototype.remove) {
var OUTPUT_DATA = 1;
var params = getQueryStringParams();

// Set the crate filter from saved storage, if the current page has the saved crate filter.
//
// If not, ignore the crate filter -- we want to support filtering for crates on sites like
// doc.rust-lang.org where the crates may differ from page to page while on the same domain.
var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
if (savedCrate !== null) {
onEachLazy(document.getElementById("crate-search").getElementsByTagName("option"),
function(e) {
if (e.value === savedCrate) {
document.getElementById("crate-search").value = e.value;
return true;
}
});
}

// Populate search bar with query string search term when provided,
// but only if the input bar is empty. This avoid the obnoxious issue
// where you start trying to do a search, and the index loads, and
Expand Down Expand Up @@ -1658,9 +1673,10 @@ if (!DOMTokenList.prototype.remove) {
};
search_input.onpaste = search_input.onchange;

var selectCrate = document.getElementById('crate-search');
var selectCrate = document.getElementById("crate-search");
if (selectCrate) {
selectCrate.onchange = function() {
updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value);
search(undefined, true);
};
}
Expand Down Expand Up @@ -2496,7 +2512,7 @@ if (!DOMTokenList.prototype.remove) {
}

function addSearchOptions(crates) {
var elem = document.getElementById('crate-search');
var elem = document.getElementById("crate-search");

if (!elem) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function onEachLazy(lazyArray, func, reversed) {

function usableLocalStorage() {
// Check if the browser supports localStorage at all:
if (typeof(Storage) === "undefined") {
if (typeof Storage === "undefined") {
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated change, I hope?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, syntax fix. Didn't even think about it...

return false;
}
// Check if we can access it; this access will fail if the browser
Expand Down