1 // Local js definitions:
2 /* global addClass, getSettingValue, hasClass, searchState */
3 /* global onEach, onEachLazy, removeClass */
7 // Get a value from the rustdoc-vars div, which is used to convey data from
8 // Rust to the JS. If there is no such element, return null.
9 function getVar(name) {
10 const el = document.getElementById("rustdoc-vars");
12 return el.attributes["data-" + name].value;
18 // Given a basename (e.g. "storage") and an extension (e.g. ".js"), return a URL
19 // for a resource under the root-path, with the resource-suffix.
20 function resourcePath(basename, extension) {
21 return getVar("root-path") + basename + getVar("resource-suffix") + extension;
25 addClass(document.getElementById(MAIN_ID), "hidden");
29 removeClass(document.getElementById(MAIN_ID), "hidden");
32 function elemIsInParent(elem, parent) {
33 while (elem && elem !== document.body) {
34 if (elem === parent) {
37 elem = elem.parentElement;
42 function blurHandler(event, parentElem, hideCallback) {
43 if (!elemIsInParent(document.activeElement, parentElem) &&
44 !elemIsInParent(event.relatedTarget, parentElem)
51 window.rootPath = getVar("root-path");
52 window.currentCrate = getVar("current-crate");
55 function setMobileTopbar() {
56 // FIXME: It would be nicer to generate this text content directly in HTML,
57 // but with the current code it's hard to get the right information in the right place.
58 const mobileLocationTitle = document.querySelector(".mobile-topbar h2.location");
59 const locationTitle = document.querySelector(".sidebar h2.location");
60 if (mobileLocationTitle && locationTitle) {
61 mobileLocationTitle.innerHTML = locationTitle.innerHTML;
65 // Gets the human-readable string for the virtual-key code of the
66 // given KeyboardEvent, ev.
68 // This function is meant as a polyfill for KeyboardEvent#key,
69 // since it is not supported in IE 11 or Chrome for Android. We also test for
70 // KeyboardEvent#keyCode because the handleShortcut handler is
71 // also registered for the keydown event, because Blink doesn't fire
72 // keypress on hitting the Escape key.
74 // So I guess you could say things are getting pretty interoperable.
75 function getVirtualKey(ev) {
76 if ("key" in ev && typeof ev.key !== "undefined") {
80 const c = ev.charCode || ev.keyCode;
84 return String.fromCharCode(c);
87 const MAIN_ID = "main-content";
88 const SETTINGS_BUTTON_ID = "settings-menu";
89 const ALTERNATIVE_DISPLAY_ID = "alternative-display";
90 const NOT_DISPLAYED_ID = "not-displayed";
91 const HELP_BUTTON_ID = "help-button";
93 function getSettingsButton() {
94 return document.getElementById(SETTINGS_BUTTON_ID);
97 function getHelpButton() {
98 return document.getElementById(HELP_BUTTON_ID);
101 // Returns the current URL without any query parameter or hash.
102 function getNakedUrl() {
103 return window.location.href.split("?")[0].split("#")[0];
107 * This function inserts `newNode` after `referenceNode`. It doesn't work if `referenceNode`
108 * doesn't have a parent node.
110 * @param {HTMLElement} newNode
111 * @param {HTMLElement} referenceNode
113 function insertAfter(newNode, referenceNode) {
114 referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
118 * This function creates a new `<section>` with the given `id` and `classes` if it doesn't already
121 * More information about this in `switchDisplayedElement` documentation.
124 * @param {string} classes
126 function getOrCreateSection(id, classes) {
127 let el = document.getElementById(id);
130 el = document.createElement("section");
132 el.className = classes;
133 insertAfter(el, document.getElementById(MAIN_ID));
139 * Returns the `<section>` element which contains the displayed element.
141 * @return {HTMLElement}
143 function getAlternativeDisplayElem() {
144 return getOrCreateSection(ALTERNATIVE_DISPLAY_ID, "content hidden");
148 * Returns the `<section>` element which contains the not-displayed elements.
150 * @return {HTMLElement}
152 function getNotDisplayedElem() {
153 return getOrCreateSection(NOT_DISPLAYED_ID, "hidden");
157 * To nicely switch between displayed "extra" elements (such as search results or settings menu)
158 * and to alternate between the displayed and not displayed elements, we hold them in two different
159 * `<section>` elements. They work in pair: one holds the hidden elements while the other
160 * contains the displayed element (there can be only one at the same time!). So basically, we switch
161 * elements between the two `<section>` elements.
163 * @param {HTMLElement} elemToDisplay
165 function switchDisplayedElement(elemToDisplay) {
166 const el = getAlternativeDisplayElem();
168 if (el.children.length > 0) {
169 getNotDisplayedElem().appendChild(el.firstElementChild);
171 if (elemToDisplay === null) {
172 addClass(el, "hidden");
176 el.appendChild(elemToDisplay);
178 removeClass(el, "hidden");
181 function browserSupportsHistoryApi() {
182 return window.history && typeof window.history.pushState === "function";
185 // eslint-disable-next-line no-unused-vars
186 function loadCss(cssFileName) {
187 const link = document.createElement("link");
188 link.href = resourcePath(cssFileName, ".css");
189 link.type = "text/css";
190 link.rel = "stylesheet";
191 document.getElementsByTagName("head")[0].appendChild(link);
195 function loadScript(url) {
196 const script = document.createElement("script");
198 document.head.append(script);
201 getSettingsButton().onclick = event => {
202 addClass(getSettingsButton(), "rotate");
203 event.preventDefault();
204 // Sending request for the CSS and the JS files at the same time so it will
205 // hopefully be loaded when the JS will generate the settings content.
207 loadScript(resourcePath("settings", ".js"));
210 window.searchState = {
211 loadingText: "Loading search results...",
212 input: document.getElementsByClassName("search-input")[0],
213 outputElement: () => {
214 let el = document.getElementById("search");
216 el = document.createElement("section");
218 getNotDisplayedElem().appendChild(el);
222 title: document.title,
223 titleBeforeSearch: document.title,
225 // On the search screen, so you remain on the last tab you opened.
228 // 1 for "In Parameters"
229 // 2 for "In Return Types"
231 // tab and back preserves the element that was focused.
232 focusedByTab: [null, null, null],
233 clearInputTimeout: () => {
234 if (searchState.timeout !== null) {
235 clearTimeout(searchState.timeout);
236 searchState.timeout = null;
239 isDisplayed: () => searchState.outputElement().parentElement.id === ALTERNATIVE_DISPLAY_ID,
240 // Sets the focus on the search bar at the top of the page
242 searchState.input.focus();
244 // Removes the focus from the search bar.
246 searchState.input.blur();
248 showResults: search => {
249 if (search === null || typeof search === "undefined") {
250 search = searchState.outputElement();
252 switchDisplayedElement(search);
253 searchState.mouseMovedAfterSearch = false;
254 document.title = searchState.title;
257 switchDisplayedElement(null);
258 document.title = searchState.titleBeforeSearch;
259 // We also remove the query parameter from the URL.
260 if (browserSupportsHistoryApi()) {
261 history.replaceState(null, window.currentCrate + " - Rust",
262 getNakedUrl() + window.location.hash);
265 getQueryStringParams: () => {
267 window.location.search.substring(1).split("&").
269 const pair = s.split("=");
270 params[decodeURIComponent(pair[0])] =
271 typeof pair[1] === "undefined" ? null : decodeURIComponent(pair[1]);
276 const search_input = searchState.input;
277 if (!searchState.input) {
280 let searchLoaded = false;
281 function loadSearch() {
284 loadScript(resourcePath("search", ".js"));
285 loadScript(resourcePath("search-index", ".js"));
289 search_input.addEventListener("focus", () => {
290 search_input.origPlaceholder = search_input.placeholder;
291 search_input.placeholder = "Type your search here.";
295 if (search_input.value !== "") {
299 const params = searchState.getQueryStringParams();
300 if (params.search !== undefined) {
301 const search = searchState.outputElement();
302 search.innerHTML = "<h3 class=\"search-loading\">" +
303 searchState.loadingText + "</h3>";
304 searchState.showResults(search);
310 function getPageId() {
311 if (window.location.hash) {
312 const tmp = window.location.hash.replace(/^#/, "");
313 if (tmp.length > 0) {
320 const toggleAllDocsId = "toggle-all-docs";
323 function handleHashes(ev) {
324 if (ev !== null && searchState.isDisplayed() && ev.newURL) {
325 // This block occurs when clicking on an element in the navbar while
327 switchDisplayedElement(null);
328 const hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1);
329 if (browserSupportsHistoryApi()) {
330 // `window.location.search`` contains all the query parameters, not just `search`.
331 history.replaceState(null, "",
332 getNakedUrl() + window.location.search + "#" + hash);
334 const elem = document.getElementById(hash);
336 elem.scrollIntoView();
339 // This part is used in case an element is not visible.
340 if (savedHash !== window.location.hash) {
341 savedHash = window.location.hash;
342 if (savedHash.length === 0) {
345 expandSection(savedHash.slice(1)); // we remove the '#'
349 function onHashChange(ev) {
350 // If we're in mobile mode, we should hide the sidebar in any case.
351 const sidebar = document.getElementsByClassName("sidebar")[0];
352 removeClass(sidebar, "shown");
356 function openParentDetails(elem) {
358 if (elem.tagName === "DETAILS") {
361 elem = elem.parentNode;
365 function expandSection(id) {
366 openParentDetails(document.getElementById(id));
369 function handleEscape(ev) {
370 searchState.clearInputTimeout();
371 switchDisplayedElement(null);
372 if (browserSupportsHistoryApi()) {
373 history.replaceState(null, window.currentCrate + " - Rust",
374 getNakedUrl() + window.location.hash);
377 searchState.defocus();
378 window.hidePopoverMenus();
381 function handleShortcut(ev) {
382 // Don't interfere with browser shortcuts
383 const disableShortcuts = getSettingValue("disable-shortcuts") === "true";
384 if (ev.ctrlKey || ev.altKey || ev.metaKey || disableShortcuts) {
388 if (document.activeElement.tagName === "INPUT" &&
389 document.activeElement.type !== "checkbox") {
390 switch (getVirtualKey(ev)) {
396 switch (getVirtualKey(ev)) {
423 document.addEventListener("keypress", handleShortcut);
424 document.addEventListener("keydown", handleShortcut);
426 function addSidebarItems() {
427 if (!window.SIDEBAR_ITEMS) {
430 const sidebar = document.getElementsByClassName("sidebar-elems")[0];
433 * Append to the sidebar a "block" of links - a heading along with a list (`<ul>`) of items.
435 * @param {string} shortty - A short type name, like "primitive", "mod", or "macro"
436 * @param {string} id - The HTML id of the corresponding section on the module page.
437 * @param {string} longty - A long, capitalized, plural name, like "Primitive Types",
438 * "Modules", or "Macros".
440 function block(shortty, id, longty) {
441 const filtered = window.SIDEBAR_ITEMS[shortty];
446 const div = document.createElement("div");
447 div.className = "block " + shortty;
448 const h3 = document.createElement("h3");
449 h3.innerHTML = `<a href="index.html#${id}">${longty}</a>`;
451 const ul = document.createElement("ul");
453 for (const item of filtered) {
454 const name = item[0];
455 const desc = item[1]; // can be null
459 if (shortty === "mod") {
460 path = name + "/index.html";
462 path = shortty + "." + name + ".html";
464 const current_page = document.location.href.split("/").pop();
465 if (path === current_page) {
468 const link = document.createElement("a");
471 link.className = klass;
472 link.textContent = name;
473 const li = document.createElement("li");
474 li.appendChild(link);
478 sidebar.appendChild(div);
482 block("primitive", "primitives", "Primitive Types");
483 block("mod", "modules", "Modules");
484 block("macro", "macros", "Macros");
485 block("struct", "structs", "Structs");
486 block("enum", "enums", "Enums");
487 block("union", "unions", "Unions");
488 block("constant", "constants", "Constants");
489 block("static", "static", "Statics");
490 block("trait", "traits", "Traits");
491 block("fn", "functions", "Functions");
492 block("type", "types", "Type Definitions");
493 block("foreigntype", "foreign-types", "Foreign Types");
494 block("keyword", "keywords", "Keywords");
495 block("traitalias", "trait-aliases", "Trait Aliases");
499 window.register_implementors = imp => {
500 const implementors = document.getElementById("implementors-list");
501 const synthetic_implementors = document.getElementById("synthetic-implementors-list");
502 const inlined_types = new Set();
505 const SYNTHETIC_IDX = 1;
508 if (synthetic_implementors) {
509 // This `inlined_types` variable is used to avoid having the same implementation
510 // showing up twice. For example "String" in the "Sync" doc page.
512 // By the way, this is only used by and useful for traits implemented automatically
513 // (like "Send" and "Sync").
514 onEachLazy(synthetic_implementors.getElementsByClassName("impl"), el => {
515 const aliases = el.getAttribute("data-aliases");
519 aliases.split(",").forEach(alias => {
520 inlined_types.add(alias);
525 let currentNbImpls = implementors.getElementsByClassName("impl").length;
526 const traitName = document.querySelector("h1.fqn > .in-band > .trait").textContent;
527 const baseIdName = "impl-" + traitName + "-";
528 const libs = Object.getOwnPropertyNames(imp);
529 // We don't want to include impls from this JS file, when the HTML already has them.
530 // The current crate should always be ignored. Other crates that should also be
531 // ignored are included in the attribute `data-ignore-extern-crates`.
532 const ignoreExternCrates = document
533 .querySelector("script[data-ignore-extern-crates]")
534 .getAttribute("data-ignore-extern-crates");
535 for (const lib of libs) {
536 if (lib === window.currentCrate || ignoreExternCrates.indexOf(lib) !== -1) {
539 const structs = imp[lib];
542 for (const struct of structs) {
543 const list = struct[SYNTHETIC_IDX] ? synthetic_implementors : implementors;
545 // The types list is only used for synthetic impls.
546 // If this changes, `main.js` and `write_shared.rs` both need changed.
547 if (struct[SYNTHETIC_IDX]) {
548 for (const struct_type of struct[TYPES_IDX]) {
549 if (inlined_types.has(struct_type)) {
550 continue struct_loop;
552 inlined_types.add(struct_type);
556 const code = document.createElement("h3");
557 code.innerHTML = struct[TEXT_IDX];
558 addClass(code, "code-header");
559 addClass(code, "in-band");
561 onEachLazy(code.getElementsByTagName("a"), elem => {
562 const href = elem.getAttribute("href");
564 if (href && href.indexOf("http") !== 0) {
565 elem.setAttribute("href", window.rootPath + href);
569 const currentId = baseIdName + currentNbImpls;
570 const anchor = document.createElement("a");
571 anchor.href = "#" + currentId;
572 addClass(anchor, "anchor");
574 const display = document.createElement("div");
575 display.id = currentId;
576 addClass(display, "impl");
577 display.appendChild(anchor);
578 display.appendChild(code);
579 list.appendChild(display);
584 if (window.pending_implementors) {
585 window.register_implementors(window.pending_implementors);
588 function addSidebarCrates() {
589 if (!window.ALL_CRATES) {
592 const sidebarElems = document.getElementsByClassName("sidebar-elems")[0];
596 // Draw a convenient sidebar of known crates if we have a listing
597 const div = document.createElement("div");
598 div.className = "block crate";
599 div.innerHTML = "<h3>Crates</h3>";
600 const ul = document.createElement("ul");
603 for (const crate of window.ALL_CRATES) {
605 if (window.rootPath !== "./" && crate === window.currentCrate) {
608 const link = document.createElement("a");
609 link.href = window.rootPath + crate + "/index.html";
610 link.className = klass;
611 link.textContent = crate;
613 const li = document.createElement("li");
614 li.appendChild(link);
617 sidebarElems.appendChild(div);
621 function labelForToggleButton(sectionIsCollapsed) {
622 if (sectionIsCollapsed) {
623 // button will expand the section
626 // button will collapse the section
627 // note that this text is also set in the HTML template in ../render/mod.rs
628 return "\u2212"; // "\u2212" is "−" minus sign
631 function toggleAllDocs() {
632 const innerToggle = document.getElementById(toggleAllDocsId);
636 let sectionIsCollapsed = false;
637 if (hasClass(innerToggle, "will-expand")) {
638 removeClass(innerToggle, "will-expand");
639 onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
640 if (!hasClass(e, "type-contents-toggle")) {
644 innerToggle.title = "collapse all docs";
646 addClass(innerToggle, "will-expand");
647 onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
648 if (e.parentNode.id !== "implementations-list" ||
649 (!hasClass(e, "implementors-toggle") &&
650 !hasClass(e, "type-contents-toggle"))
655 sectionIsCollapsed = true;
656 innerToggle.title = "expand all docs";
658 innerToggle.children[0].innerText = labelForToggleButton(sectionIsCollapsed);
662 const toggles = document.getElementById(toggleAllDocsId);
664 toggles.onclick = toggleAllDocs;
667 const hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
668 const hideImplementations = getSettingValue("auto-hide-trait-implementations") === "true";
669 const hideLargeItemContents = getSettingValue("auto-hide-large-items") !== "false";
671 function setImplementorsTogglesOpen(id, open) {
672 const list = document.getElementById(id);
674 onEachLazy(list.getElementsByClassName("implementors-toggle"), e => {
680 if (hideImplementations) {
681 setImplementorsTogglesOpen("trait-implementations-list", false);
682 setImplementorsTogglesOpen("blanket-implementations-list", false);
685 onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
686 if (!hideLargeItemContents && hasClass(e, "type-contents-toggle")) {
689 if (hideMethodDocs && hasClass(e, "method-toggle")) {
695 const pageId = getPageId();
696 if (pageId !== null) {
697 expandSection(pageId);
702 // To avoid checking on "rustdoc-line-numbers" value on every loop...
703 let lineNumbersFunc = () => {};
704 if (getSettingValue("line-numbers") === "true") {
705 lineNumbersFunc = x => {
706 const count = x.textContent.split("\n").length;
708 for (let i = 0; i < count; ++i) {
711 const node = document.createElement("pre");
712 addClass(node, "line-number");
713 node.innerHTML = elems.join("\n");
714 x.parentNode.insertBefore(node, x);
717 onEachLazy(document.getElementsByClassName("rust-example-rendered"), e => {
718 if (hasClass(e, "compile_fail")) {
719 e.addEventListener("mouseover", function() {
720 this.parentElement.previousElementSibling.childNodes[0].style.color = "#f00";
722 e.addEventListener("mouseout", function() {
723 this.parentElement.previousElementSibling.childNodes[0].style.color = "";
725 } else if (hasClass(e, "ignore")) {
726 e.addEventListener("mouseover", function() {
727 this.parentElement.previousElementSibling.childNodes[0].style.color = "#ff9200";
729 e.addEventListener("mouseout", function() {
730 this.parentElement.previousElementSibling.childNodes[0].style.color = "";
737 function hideSidebar() {
738 const sidebar = document.getElementsByClassName("sidebar")[0];
739 removeClass(sidebar, "shown");
742 function handleClick(id, f) {
743 const elem = document.getElementById(id);
745 elem.addEventListener("click", f);
748 handleClick(MAIN_ID, () => {
752 onEachLazy(document.getElementsByTagName("a"), el => {
753 // For clicks on internal links (<A> tags with a hash property), we expand the section we're
754 // jumping to *before* jumping there. We can't do this in onHashChange, because it changes
755 // the height of the document so we wind up scrolled to the wrong place.
757 el.addEventListener("click", () => {
758 expandSection(el.hash.slice(1));
764 onEachLazy(document.querySelectorAll(".rustdoc-toggle > summary:not(.hideme)"), el => {
765 el.addEventListener("click", e => {
766 if (e.target.tagName !== "SUMMARY" && e.target.tagName !== "A") {
772 onEachLazy(document.getElementsByClassName("notable-traits"), e => {
773 e.onclick = function() {
774 this.getElementsByClassName("notable-traits-tooltiptext")[0]
775 .classList.toggle("force-tooltip");
779 const sidebar_menu_toggle = document.getElementsByClassName("sidebar-menu-toggle")[0];
780 if (sidebar_menu_toggle) {
781 sidebar_menu_toggle.addEventListener("click", () => {
782 const sidebar = document.getElementsByClassName("sidebar")[0];
783 if (!hasClass(sidebar, "shown")) {
784 addClass(sidebar, "shown");
786 removeClass(sidebar, "shown");
791 function helpBlurHandler(event) {
792 blurHandler(event, getHelpButton(), window.hidePopoverMenus);
795 function buildHelpMenu() {
796 const book_info = document.createElement("span");
797 book_info.className = "top";
798 book_info.innerHTML = "You can find more information in \
799 <a href=\"https://doc.rust-lang.org/rustdoc/\">the rustdoc book</a>.";
802 ["?", "Show this help dialog"],
803 ["S", "Focus the search field"],
804 ["↑", "Move up in search results"],
805 ["↓", "Move down in search results"],
806 ["← / →", "Switch result tab (when results focused)"],
807 ["⏎", "Go to active search result"],
808 ["+", "Expand all sections"],
809 ["-", "Collapse all sections"],
812 .map((y, index) => ((index & 1) === 0 ? "<kbd>" + y + "</kbd>" : " " + y + " "))
813 .join("") + "</dt><dd>" + x[1] + "</dd>").join("");
814 const div_shortcuts = document.createElement("div");
815 addClass(div_shortcuts, "shortcuts");
816 div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
819 "Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to \
820 restrict the search to a given item kind.",
821 "Accepted kinds are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \
822 <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, \
823 and <code>const</code>.",
824 "Search functions by type signature (e.g., <code>vec -> usize</code> or \
825 <code>-> vec</code>)",
826 "Search multiple things at once by splitting your query with comma (e.g., \
827 <code>str,u8</code> or <code>String,struct:Vec,test</code>)",
828 "You can look for items with an exact name by putting double quotes around \
829 your request: <code>\"string\"</code>",
830 "Look for items inside another one by searching for a path: <code>vec::Vec</code>",
831 ].map(x => "<p>" + x + "</p>").join("");
832 const div_infos = document.createElement("div");
833 addClass(div_infos, "infos");
834 div_infos.innerHTML = "<h2>Search Tricks</h2>" + infos;
836 const rustdoc_version = document.createElement("span");
837 rustdoc_version.className = "bottom";
838 const rustdoc_version_code = document.createElement("code");
839 rustdoc_version_code.innerText = "rustdoc " + getVar("rustdoc-version");
840 rustdoc_version.appendChild(rustdoc_version_code);
842 const container = document.createElement("div");
843 container.className = "popover";
844 container.style.display = "none";
846 const side_by_side = document.createElement("div");
847 side_by_side.className = "side-by-side";
848 side_by_side.appendChild(div_shortcuts);
849 side_by_side.appendChild(div_infos);
851 container.appendChild(book_info);
852 container.appendChild(side_by_side);
853 container.appendChild(rustdoc_version);
855 const help_button = getHelpButton();
856 help_button.appendChild(container);
858 container.onblur = helpBlurHandler;
859 container.onclick = event => {
860 event.preventDefault();
862 help_button.onblur = helpBlurHandler;
863 help_button.children[0].onblur = helpBlurHandler;
869 * Hide all the popover menus.
871 window.hidePopoverMenus = function() {
872 onEachLazy(document.querySelectorAll(".search-container .popover"), elem => {
873 elem.style.display = "none";
878 * Returns the help menu element (not the button).
880 * @param {boolean} buildNeeded - If this argument is `false`, the help menu element won't be
881 * built if it doesn't exist.
883 * @return {HTMLElement}
885 function getHelpMenu(buildNeeded) {
886 let menu = getHelpButton().querySelector(".popover");
887 if (!menu && buildNeeded) {
888 menu = buildHelpMenu();
894 * Show the help popup menu.
896 function showHelp() {
897 const menu = getHelpMenu(true);
898 if (menu.style.display === "none") {
899 window.hidePopoverMenus();
900 menu.style.display = "";
904 document.querySelector(`#${HELP_BUTTON_ID} > button`).addEventListener("click", event => {
905 const target = event.target;
906 if (target.tagName !== "BUTTON" || target.parentElement.id !== HELP_BUTTON_ID) {
909 const menu = getHelpMenu(true);
910 const shouldShowHelp = menu.style.display === "none";
911 if (shouldShowHelp) {
914 window.hidePopoverMenus();
922 window.addEventListener("hashchange", onHashChange);
927 let reset_button_timeout = null;
929 window.copy_path = but => {
930 const parent = but.parentElement;
933 onEach(parent.childNodes, child => {
934 if (child.tagName === "A") {
935 path.push(child.textContent);
939 const el = document.createElement("textarea");
940 el.value = path.join("::");
941 el.setAttribute("readonly", "");
942 // To not make it appear on the screen.
943 el.style.position = "absolute";
944 el.style.left = "-9999px";
946 document.body.appendChild(el);
948 document.execCommand("copy");
949 document.body.removeChild(el);
951 // There is always one children, but multiple childNodes.
952 but.children[0].style.display = "none";
955 if (but.childNodes.length < 2) {
956 tmp = document.createTextNode("✓");
957 but.appendChild(tmp);
959 onEachLazy(but.childNodes, e => {
960 if (e.nodeType === Node.TEXT_NODE) {
965 tmp.textContent = "✓";
968 if (reset_button_timeout !== null) {
969 window.clearTimeout(reset_button_timeout);
972 function reset_button() {
973 tmp.textContent = "";
974 reset_button_timeout = null;
975 but.children[0].style.display = "";
978 reset_button_timeout = window.setTimeout(reset_button, 1000);