Skip to content

Commit 3f0bc5c

Browse files
Rollup merge of #85548 - GuillaumeGomez:remove-dead-js, r=jsha
Remove dead toggle JS code Explanations on how I got there: I randomly saw `adjustToggle` while browsing through code, checked where it was called, put a `debugger;` instruction in it and checked on all pages while playing with settings and toggles. The breakpoint was never triggered. I then looked at `collapseNonInherent` (its grand-parent). In there, the breakpoint was triggered so I look at what was being done and in fact... nothing. So I simply removed it all, re-ran the tests and play with the UI. Everything is working as expected. Better double check in case I forgot to check a case though, but if nothing has been left out, then it's a great cleanup once again. :) r? ``@jsha``
2 parents 51a99eb + aee054d commit 3f0bc5c

File tree

1 file changed

+0
-158
lines changed

1 file changed

+0
-158
lines changed

src/librustdoc/html/static/main.js

-158
Original file line numberDiff line numberDiff line change
@@ -764,138 +764,6 @@ function hideThemeButtonState() {
764764
innerToggle.children[0].innerText = labelForToggleButton(sectionIsCollapsed);
765765
}
766766

767-
function collapseDocs(toggle, mode) {
768-
if (!toggle || !toggle.parentNode) {
769-
return;
770-
}
771-
772-
function adjustToggle(arg) {
773-
return function(e) {
774-
if (hasClass(e, "toggle-label")) {
775-
if (arg) {
776-
e.style.display = "inline-block";
777-
} else {
778-
e.style.display = "none";
779-
}
780-
}
781-
if (hasClass(e, "inner")) {
782-
e.innerHTML = labelForToggleButton(arg);
783-
}
784-
};
785-
}
786-
787-
function implHider(addOrRemove, fullHide) {
788-
return function(n) {
789-
var shouldHide =
790-
fullHide ||
791-
hasClass(n, "method") ||
792-
hasClass(n, "associatedconstant");
793-
if (shouldHide || hasClass(n, "type")) {
794-
if (shouldHide) {
795-
if (addOrRemove) {
796-
addClass(n, "hidden-by-impl-hider");
797-
} else {
798-
removeClass(n, "hidden-by-impl-hider");
799-
}
800-
}
801-
var ns = n.nextElementSibling;
802-
while (ns && (hasClass(ns, "docblock") || hasClass(ns, "item-info"))) {
803-
if (addOrRemove) {
804-
addClass(ns, "hidden-by-impl-hider");
805-
} else {
806-
removeClass(ns, "hidden-by-impl-hider");
807-
}
808-
ns = ns.nextElementSibling;
809-
}
810-
}
811-
};
812-
}
813-
814-
var relatedDoc;
815-
var action = mode;
816-
if (!hasClass(toggle.parentNode, "impl")) {
817-
relatedDoc = toggle.parentNode.nextElementSibling;
818-
if (hasClass(relatedDoc, "item-info")) {
819-
relatedDoc = relatedDoc.nextElementSibling;
820-
}
821-
if (hasClass(relatedDoc, "docblock")) {
822-
if (mode === "toggle") {
823-
if (hasClass(relatedDoc, "hidden-by-usual-hider")) {
824-
action = "show";
825-
} else {
826-
action = "hide";
827-
}
828-
}
829-
if (action === "hide") {
830-
addClass(relatedDoc, "hidden-by-usual-hider");
831-
onEachLazy(toggle.childNodes, adjustToggle(true));
832-
addClass(toggle.parentNode, "collapsed");
833-
} else if (action === "show") {
834-
removeClass(relatedDoc, "hidden-by-usual-hider");
835-
removeClass(toggle.parentNode, "collapsed");
836-
onEachLazy(toggle.childNodes, adjustToggle(false));
837-
}
838-
}
839-
} else {
840-
// we are collapsing the impl block(s).
841-
842-
var parentElem = toggle.parentNode;
843-
relatedDoc = parentElem;
844-
var docblock = relatedDoc.nextElementSibling;
845-
846-
while (!hasClass(relatedDoc, "impl-items")) {
847-
relatedDoc = relatedDoc.nextElementSibling;
848-
}
849-
850-
if (!relatedDoc && !hasClass(docblock, "docblock")) {
851-
return;
852-
}
853-
854-
// Hide all functions, but not associated types/consts.
855-
856-
if (mode === "toggle") {
857-
if (hasClass(relatedDoc, "fns-now-collapsed") ||
858-
hasClass(docblock, "hidden-by-impl-hider")) {
859-
action = "show";
860-
} else {
861-
action = "hide";
862-
}
863-
}
864-
865-
var dontApplyBlockRule = toggle.parentNode.parentNode.id !== "main";
866-
if (action === "show") {
867-
removeClass(relatedDoc, "fns-now-collapsed");
868-
// Stability/deprecation/portability information is never hidden.
869-
if (!hasClass(docblock, "item-info")) {
870-
removeClass(docblock, "hidden-by-usual-hider");
871-
}
872-
onEachLazy(toggle.childNodes, adjustToggle(false, dontApplyBlockRule));
873-
onEachLazy(relatedDoc.childNodes, implHider(false, dontApplyBlockRule));
874-
} else if (action === "hide") {
875-
addClass(relatedDoc, "fns-now-collapsed");
876-
// Stability/deprecation/portability information should be shown even when detailed
877-
// info is hidden.
878-
if (!hasClass(docblock, "item-info")) {
879-
addClass(docblock, "hidden-by-usual-hider");
880-
}
881-
onEachLazy(toggle.childNodes, adjustToggle(true, dontApplyBlockRule));
882-
onEachLazy(relatedDoc.childNodes, implHider(true, dontApplyBlockRule));
883-
}
884-
}
885-
}
886-
887-
function collapseNonInherent(e) {
888-
// inherent impl ids are like "impl" or impl-<number>'.
889-
// they will never be hidden by default.
890-
var n = e.parentElement;
891-
if (n.id.match(/^impl(?:-\d+)?$/) === null) {
892-
// Automatically minimize all non-inherent impls
893-
if (hasClass(n, "impl")) {
894-
collapseDocs(e, "hide");
895-
}
896-
}
897-
}
898-
899767
function insertAfter(newNode, referenceNode) {
900768
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
901769
}
@@ -910,20 +778,6 @@ function hideThemeButtonState() {
910778
var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false";
911779
var hideLargeItemContents = getSettingValue("auto-hide-large-items") !== "false";
912780

913-
var impl_list = document.getElementById("trait-implementations-list");
914-
if (impl_list !== null) {
915-
onEachLazy(impl_list.getElementsByClassName("rustdoc-toggle"), function(e) {
916-
collapseNonInherent(e);
917-
});
918-
}
919-
920-
var blanket_list = document.getElementById("blanket-implementations-list");
921-
if (blanket_list !== null) {
922-
onEachLazy(blanket_list.getElementsByClassName("rustdoc-toggle"), function(e) {
923-
collapseNonInherent(e);
924-
});
925-
}
926-
927781
onEachLazy(document.getElementsByTagName("details"), function (e) {
928782
var showLargeItem = !hideLargeItemContents && hasClass(e, "type-contents-toggle");
929783
var showImplementor = !hideImplementors && hasClass(e, "implementors-toggle");
@@ -936,18 +790,6 @@ function hideThemeButtonState() {
936790

937791
});
938792

939-
var currentType = document.getElementsByClassName("type-decl")[0];
940-
if (currentType) {
941-
currentType = currentType.getElementsByClassName("rust")[0];
942-
if (currentType) {
943-
onEachLazy(currentType.classList, function(item) {
944-
if (item !== "main") {
945-
return true;
946-
}
947-
});
948-
}
949-
}
950-
951793
var pageId = getPageId();
952794
if (pageId !== null) {
953795
expandSection(pageId);

0 commit comments

Comments
 (0)