mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-14 23:57:07 +00:00
Fallback enum variant srclink to the enum itself
This commit is contained in:
parent
05291a5420
commit
c44847596d
1 changed files with 6 additions and 1 deletions
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue