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

Fix "Auto-hide item methods documentation" setting #58873

Merged
merged 1 commit into from
Mar 16, 2019
Merged
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
69 changes: 37 additions & 32 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2077,16 +2077,22 @@ if (!DOMTokenList.prototype.remove) {
}

var toggle = createSimpleToggle(false);
var hideMethodDocs = getCurrentValue("rustdoc-method-docs") !== "false";
var pageId = getPageId();

var func = function(e) {
var next = e.nextElementSibling;
if (!next) {
return;
}
if (hasClass(next, "docblock") ||
(hasClass(next, "stability") &&
hasClass(next.nextElementSibling, "docblock"))) {
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
if (hasClass(next, "docblock") === true ||
(hasClass(next, "stability") === true &&
hasClass(next.nextElementSibling, "docblock") === true)) {
var newToggle = toggle.cloneNode(true);
insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
if (hideMethodDocs === true && hasClass(e, "method") === true) {
collapseDocs(newToggle, "hide", pageId);
}
}
};

Expand All @@ -2107,17 +2113,16 @@ if (!DOMTokenList.prototype.remove) {
onEachLazy(document.getElementsByClassName("associatedconstant"), func);
onEachLazy(document.getElementsByClassName("impl"), funcImpl);
var impl_call = function() {};
if (getCurrentValue("rustdoc-method-docs") !== "false") {
if (hideMethodDocs === true) {
impl_call = function(e, newToggle, pageId) {
if (e.id.match(/^impl(?:-\d+)?$/) === null) {
// Automatically minimize all non-inherent impls
if (hasClass(e, "impl")) {
if (hasClass(e, "impl") === true) {
collapseDocs(newToggle, "hide", pageId);
}
}
};
}
var pageId = getPageId();
var newToggle = document.createElement("a");
newToggle.href = "javascript:void(0)";
newToggle.className = "collapse-toggle hidden-default collapsed";
Expand Down Expand Up @@ -2163,7 +2168,7 @@ if (!DOMTokenList.prototype.remove) {
var inner_toggle = newToggle.cloneNode(true);
inner_toggle.onclick = toggleClicked;
e.insertBefore(inner_toggle, e.firstChild);
impl_call(e, inner_toggle, pageId);
impl_call(e.previousSibling, inner_toggle, pageId);
}
});

Expand Down Expand Up @@ -2265,30 +2270,6 @@ if (!DOMTokenList.prototype.remove) {
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);

// In the search display, allows to switch between tabs.
function printTab(nb) {
if (nb === 0 || nb === 1 || nb === 2) {
currentTab = nb;
}
var nb_copy = nb;
onEachLazy(document.getElementById("titles").childNodes, function(elem) {
if (nb_copy === 0) {
addClass(elem, "selected");
} else {
removeClass(elem, "selected");
}
nb_copy -= 1;
});
onEachLazy(document.getElementById("results").childNodes, function(elem) {
if (nb === 0) {
elem.style.display = "";
} else {
elem.style.display = "none";
}
nb -= 1;
});
}

function createToggleWrapper(tog) {
var span = document.createElement("span");
span.className = "toggle-label";
Expand Down Expand Up @@ -2374,6 +2355,30 @@ if (!DOMTokenList.prototype.remove) {
};
});

// In the search display, allows to switch between tabs.
function printTab(nb) {
Copy link
Member

Choose a reason for hiding this comment

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

Why was this function moved? It doesn't seem to have anything to do with this PR, and it breaks the ability to do git blame analysis on it. (And probably will create a merge conflict with #58364 on top of that.)

Copy link
Member Author

Choose a reason for hiding this comment

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

It was between functions that should be along each other. I can move it back if you want?

Copy link
Member

Choose a reason for hiding this comment

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

It's fine; i won't let that hold up the PR.

if (nb === 0 || nb === 1 || nb === 2) {
currentTab = nb;
}
var nb_copy = nb;
onEachLazy(document.getElementById("titles").childNodes, function(elem) {
if (nb_copy === 0) {
addClass(elem, "selected");
} else {
removeClass(elem, "selected");
}
nb_copy -= 1;
});
onEachLazy(document.getElementById("results").childNodes, function(elem) {
if (nb === 0) {
elem.style.display = "";
} else {
elem.style.display = "none";
}
nb -= 1;
});
}

function putBackSearch(search_input) {
if (search_input.value !== "") {
addClass(main, "hidden");
Expand Down