Fallback enum variant srclink to the enum itself

This commit is contained in:
Folyd 2021-03-03 23:36:29 +08:00
parent 05291a5420
commit c44847596d

View file

@ -3,7 +3,12 @@ document.addEventListener("DOMContentLoaded", () => {
// https://doc.rust-lang.org/src/core/option.rs.html#161-170
let currentUrl = new URL(location.href);
if (currentUrl.searchParams.get("mode") === "src") {
let element = document.getElementById(currentUrl.hash.replace("#", ""))
// Special case:
// We can not redirect https://doc.rust-lang.org/std/option/enum.Option.html#variant.Some
// to the corresponding lines of variant Some, since the docs has no "srclink" for variant.
// We fallback to the "srclink" of Option.
let hash = currentUrl.hash.replace(/#(variant\.)?/i, "");
let element = document.getElementById(hash)
|| document.querySelector(".fqn");
if (element) {
let srclink = element.querySelector(".srclink");