2018-12-04 21:59:27 +00:00
|
|
|
|
// Local js definitions:
|
2021-05-14 11:56:15 +00:00
|
|
|
|
/* global addClass, getSettingValue, hasClass, searchState */
|
2023-01-15 18:34:58 +00:00
|
|
|
|
/* global onEach, onEachLazy, removeClass, getVar */
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2022-05-02 12:32:56 +00:00
|
|
|
|
"use strict";
|
|
|
|
|
|
2021-11-24 03:22:29 +00:00
|
|
|
|
// Given a basename (e.g. "storage") and an extension (e.g. ".js"), return a URL
|
|
|
|
|
// for a resource under the root-path, with the resource-suffix.
|
|
|
|
|
function resourcePath(basename, extension) {
|
|
|
|
|
return getVar("root-path") + basename + getVar("resource-suffix") + extension;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 21:36:15 +00:00
|
|
|
|
function hideMain() {
|
|
|
|
|
addClass(document.getElementById(MAIN_ID), "hidden");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showMain() {
|
|
|
|
|
removeClass(document.getElementById(MAIN_ID), "hidden");
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 14:28:52 +00:00
|
|
|
|
function elemIsInParent(elem, parent) {
|
|
|
|
|
while (elem && elem !== document.body) {
|
|
|
|
|
if (elem === parent) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
elem = elem.parentElement;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function blurHandler(event, parentElem, hideCallback) {
|
|
|
|
|
if (!elemIsInParent(document.activeElement, parentElem) &&
|
|
|
|
|
!elemIsInParent(event.relatedTarget, parentElem)
|
|
|
|
|
) {
|
|
|
|
|
hideCallback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-15 20:03:44 +00:00
|
|
|
|
window.rootPath = getVar("root-path");
|
|
|
|
|
window.currentCrate = getVar("current-crate");
|
2020-11-08 13:49:29 +00:00
|
|
|
|
|
2022-06-15 06:25:51 +00:00
|
|
|
|
function setMobileTopbar() {
|
|
|
|
|
// FIXME: It would be nicer to generate this text content directly in HTML,
|
|
|
|
|
// but with the current code it's hard to get the right information in the right place.
|
2022-10-18 18:14:01 +00:00
|
|
|
|
const mobileLocationTitle = document.querySelector(".mobile-topbar h2");
|
2022-06-15 06:25:51 +00:00
|
|
|
|
const locationTitle = document.querySelector(".sidebar h2.location");
|
|
|
|
|
if (mobileLocationTitle && locationTitle) {
|
|
|
|
|
mobileLocationTitle.innerHTML = locationTitle.innerHTML;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-08 13:49:29 +00:00
|
|
|
|
// Gets the human-readable string for the virtual-key code of the
|
|
|
|
|
// given KeyboardEvent, ev.
|
|
|
|
|
//
|
|
|
|
|
// This function is meant as a polyfill for KeyboardEvent#key,
|
2020-11-08 16:12:03 +00:00
|
|
|
|
// since it is not supported in IE 11 or Chrome for Android. We also test for
|
2020-11-08 13:49:29 +00:00
|
|
|
|
// KeyboardEvent#keyCode because the handleShortcut handler is
|
|
|
|
|
// also registered for the keydown event, because Blink doesn't fire
|
|
|
|
|
// keypress on hitting the Escape key.
|
|
|
|
|
//
|
|
|
|
|
// So I guess you could say things are getting pretty interoperable.
|
|
|
|
|
function getVirtualKey(ev) {
|
2022-05-27 20:30:19 +00:00
|
|
|
|
if ("key" in ev && typeof ev.key !== "undefined") {
|
2020-11-08 13:49:29 +00:00
|
|
|
|
return ev.key;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const c = ev.charCode || ev.keyCode;
|
2022-05-27 20:30:19 +00:00
|
|
|
|
if (c === 27) {
|
2020-11-08 13:49:29 +00:00
|
|
|
|
return "Escape";
|
|
|
|
|
}
|
|
|
|
|
return String.fromCharCode(c);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const MAIN_ID = "main-content";
|
2022-01-19 21:36:15 +00:00
|
|
|
|
const SETTINGS_BUTTON_ID = "settings-menu";
|
|
|
|
|
const ALTERNATIVE_DISPLAY_ID = "alternative-display";
|
|
|
|
|
const NOT_DISPLAYED_ID = "not-displayed";
|
2022-06-20 14:28:52 +00:00
|
|
|
|
const HELP_BUTTON_ID = "help-button";
|
2021-03-05 15:16:03 +00:00
|
|
|
|
|
2022-01-19 21:36:15 +00:00
|
|
|
|
function getSettingsButton() {
|
|
|
|
|
return document.getElementById(SETTINGS_BUTTON_ID);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 14:28:52 +00:00
|
|
|
|
function getHelpButton() {
|
|
|
|
|
return document.getElementById(HELP_BUTTON_ID);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-25 12:21:12 +00:00
|
|
|
|
// Returns the current URL without any query parameter or hash.
|
|
|
|
|
function getNakedUrl() {
|
|
|
|
|
return window.location.href.split("?")[0].split("#")[0];
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 21:36:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* This function inserts `newNode` after `referenceNode`. It doesn't work if `referenceNode`
|
|
|
|
|
* doesn't have a parent node.
|
|
|
|
|
*
|
2022-05-01 19:22:38 +00:00
|
|
|
|
* @param {HTMLElement} newNode
|
|
|
|
|
* @param {HTMLElement} referenceNode
|
2022-01-19 21:36:15 +00:00
|
|
|
|
*/
|
|
|
|
|
function insertAfter(newNode, referenceNode) {
|
|
|
|
|
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function creates a new `<section>` with the given `id` and `classes` if it doesn't already
|
|
|
|
|
* exist.
|
|
|
|
|
*
|
|
|
|
|
* More information about this in `switchDisplayedElement` documentation.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} id
|
|
|
|
|
* @param {string} classes
|
|
|
|
|
*/
|
|
|
|
|
function getOrCreateSection(id, classes) {
|
|
|
|
|
let el = document.getElementById(id);
|
|
|
|
|
|
|
|
|
|
if (!el) {
|
|
|
|
|
el = document.createElement("section");
|
|
|
|
|
el.id = id;
|
|
|
|
|
el.className = classes;
|
|
|
|
|
insertAfter(el, document.getElementById(MAIN_ID));
|
|
|
|
|
}
|
|
|
|
|
return el;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the `<section>` element which contains the displayed element.
|
|
|
|
|
*
|
2022-05-01 19:22:38 +00:00
|
|
|
|
* @return {HTMLElement}
|
2022-01-19 21:36:15 +00:00
|
|
|
|
*/
|
|
|
|
|
function getAlternativeDisplayElem() {
|
|
|
|
|
return getOrCreateSection(ALTERNATIVE_DISPLAY_ID, "content hidden");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the `<section>` element which contains the not-displayed elements.
|
|
|
|
|
*
|
2022-05-01 19:22:38 +00:00
|
|
|
|
* @return {HTMLElement}
|
2022-01-19 21:36:15 +00:00
|
|
|
|
*/
|
|
|
|
|
function getNotDisplayedElem() {
|
|
|
|
|
return getOrCreateSection(NOT_DISPLAYED_ID, "hidden");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* To nicely switch between displayed "extra" elements (such as search results or settings menu)
|
|
|
|
|
* and to alternate between the displayed and not displayed elements, we hold them in two different
|
2022-05-01 19:22:38 +00:00
|
|
|
|
* `<section>` elements. They work in pair: one holds the hidden elements while the other
|
2022-01-19 21:36:15 +00:00
|
|
|
|
* contains the displayed element (there can be only one at the same time!). So basically, we switch
|
|
|
|
|
* elements between the two `<section>` elements.
|
|
|
|
|
*
|
2022-05-01 19:22:38 +00:00
|
|
|
|
* @param {HTMLElement} elemToDisplay
|
2022-01-19 21:36:15 +00:00
|
|
|
|
*/
|
|
|
|
|
function switchDisplayedElement(elemToDisplay) {
|
|
|
|
|
const el = getAlternativeDisplayElem();
|
|
|
|
|
|
|
|
|
|
if (el.children.length > 0) {
|
|
|
|
|
getNotDisplayedElem().appendChild(el.firstElementChild);
|
|
|
|
|
}
|
|
|
|
|
if (elemToDisplay === null) {
|
|
|
|
|
addClass(el, "hidden");
|
|
|
|
|
showMain();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
el.appendChild(elemToDisplay);
|
|
|
|
|
hideMain();
|
|
|
|
|
removeClass(el, "hidden");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function browserSupportsHistoryApi() {
|
|
|
|
|
return window.history && typeof window.history.pushState === "function";
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-24 08:28:55 +00:00
|
|
|
|
function loadCss(cssUrl) {
|
2022-01-19 21:36:15 +00:00
|
|
|
|
const link = document.createElement("link");
|
2022-10-24 08:28:55 +00:00
|
|
|
|
link.href = cssUrl;
|
2022-01-19 21:36:15 +00:00
|
|
|
|
link.rel = "stylesheet";
|
|
|
|
|
document.getElementsByTagName("head")[0].appendChild(link);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-15 18:34:58 +00:00
|
|
|
|
function preLoadCss(cssUrl) {
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload
|
|
|
|
|
const link = document.createElement("link");
|
|
|
|
|
link.href = cssUrl;
|
|
|
|
|
link.rel = "preload";
|
|
|
|
|
link.as = "style";
|
|
|
|
|
document.getElementsByTagName("head")[0].appendChild(link);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-10 04:59:53 +00:00
|
|
|
|
(function() {
|
2022-10-14 16:48:19 +00:00
|
|
|
|
const isHelpPage = window.location.pathname.endsWith("/help.html");
|
|
|
|
|
|
2022-01-19 21:36:15 +00:00
|
|
|
|
function loadScript(url) {
|
2022-05-07 18:18:23 +00:00
|
|
|
|
const script = document.createElement("script");
|
2022-01-19 21:36:15 +00:00
|
|
|
|
script.src = url;
|
|
|
|
|
document.head.append(script);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-03 04:03:17 +00:00
|
|
|
|
getSettingsButton().onclick = event => {
|
2022-10-15 18:45:27 +00:00
|
|
|
|
if (event.ctrlKey || event.altKey || event.metaKey) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-26 21:32:57 +00:00
|
|
|
|
window.hideAllModals(false);
|
2022-05-04 13:39:18 +00:00
|
|
|
|
addClass(getSettingsButton(), "rotate");
|
2022-01-19 21:36:15 +00:00
|
|
|
|
event.preventDefault();
|
2022-05-05 18:19:40 +00:00
|
|
|
|
// Sending request for the CSS and the JS files at the same time so it will
|
|
|
|
|
// hopefully be loaded when the JS will generate the settings content.
|
2022-10-24 08:28:55 +00:00
|
|
|
|
loadCss(getVar("static-root-path") + getVar("settings-css"));
|
|
|
|
|
loadScript(getVar("static-root-path") + getVar("settings-js"));
|
2023-01-15 18:34:58 +00:00
|
|
|
|
preLoadCss(getVar("static-root-path") + getVar("theme-light-css"));
|
|
|
|
|
preLoadCss(getVar("static-root-path") + getVar("theme-dark-css"));
|
|
|
|
|
preLoadCss(getVar("static-root-path") + getVar("theme-ayu-css"));
|
|
|
|
|
// Pre-load all theme CSS files, so that switching feels seamless.
|
|
|
|
|
//
|
|
|
|
|
// When loading settings.html as a standalone page, the equivalent HTML is
|
|
|
|
|
// generated in context.rs.
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
const themes = getVar("themes").split(",");
|
|
|
|
|
for (const theme of themes) {
|
|
|
|
|
// if there are no themes, do nothing
|
|
|
|
|
// "".split(",") == [""]
|
|
|
|
|
if (theme !== "") {
|
|
|
|
|
preLoadCss(getVar("root-path") + theme + ".css");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, 0);
|
2022-01-19 21:36:15 +00:00
|
|
|
|
};
|
|
|
|
|
|
2021-04-13 06:50:18 +00:00
|
|
|
|
window.searchState = {
|
2021-05-11 09:47:39 +00:00
|
|
|
|
loadingText: "Loading search results...",
|
|
|
|
|
input: document.getElementsByClassName("search-input")[0],
|
2022-05-03 04:03:17 +00:00
|
|
|
|
outputElement: () => {
|
2022-01-19 21:36:15 +00:00
|
|
|
|
let el = document.getElementById("search");
|
|
|
|
|
if (!el) {
|
|
|
|
|
el = document.createElement("section");
|
|
|
|
|
el.id = "search";
|
|
|
|
|
getNotDisplayedElem().appendChild(el);
|
|
|
|
|
}
|
|
|
|
|
return el;
|
2021-05-11 09:47:39 +00:00
|
|
|
|
},
|
2021-05-20 14:01:08 +00:00
|
|
|
|
title: document.title,
|
2021-05-11 09:47:39 +00:00
|
|
|
|
titleBeforeSearch: document.title,
|
|
|
|
|
timeout: null,
|
|
|
|
|
// On the search screen, so you remain on the last tab you opened.
|
|
|
|
|
//
|
|
|
|
|
// 0 for "In Names"
|
|
|
|
|
// 1 for "In Parameters"
|
|
|
|
|
// 2 for "In Return Types"
|
|
|
|
|
currentTab: 0,
|
2021-05-09 19:56:21 +00:00
|
|
|
|
// tab and back preserves the element that was focused.
|
|
|
|
|
focusedByTab: [null, null, null],
|
2022-05-03 04:03:17 +00:00
|
|
|
|
clearInputTimeout: () => {
|
2021-05-11 09:47:39 +00:00
|
|
|
|
if (searchState.timeout !== null) {
|
|
|
|
|
clearTimeout(searchState.timeout);
|
|
|
|
|
searchState.timeout = null;
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-05-03 04:03:17 +00:00
|
|
|
|
isDisplayed: () => searchState.outputElement().parentElement.id === ALTERNATIVE_DISPLAY_ID,
|
2021-05-11 09:47:39 +00:00
|
|
|
|
// Sets the focus on the search bar at the top of the page
|
2022-05-03 04:03:17 +00:00
|
|
|
|
focus: () => {
|
2021-05-11 09:47:39 +00:00
|
|
|
|
searchState.input.focus();
|
|
|
|
|
},
|
|
|
|
|
// Removes the focus from the search bar.
|
2022-05-03 04:03:17 +00:00
|
|
|
|
defocus: () => {
|
2021-05-11 09:47:39 +00:00
|
|
|
|
searchState.input.blur();
|
|
|
|
|
},
|
2022-05-03 04:03:17 +00:00
|
|
|
|
showResults: search => {
|
2022-05-07 18:18:23 +00:00
|
|
|
|
if (search === null || typeof search === "undefined") {
|
2021-05-11 09:47:39 +00:00
|
|
|
|
search = searchState.outputElement();
|
2021-04-13 06:50:18 +00:00
|
|
|
|
}
|
2022-01-19 21:36:15 +00:00
|
|
|
|
switchDisplayedElement(search);
|
2021-05-11 09:47:39 +00:00
|
|
|
|
searchState.mouseMovedAfterSearch = false;
|
2021-04-13 06:50:18 +00:00
|
|
|
|
document.title = searchState.title;
|
2021-05-11 09:47:39 +00:00
|
|
|
|
},
|
2022-05-03 04:03:17 +00:00
|
|
|
|
hideResults: () => {
|
2022-01-19 21:36:15 +00:00
|
|
|
|
switchDisplayedElement(null);
|
2021-05-11 09:47:39 +00:00
|
|
|
|
document.title = searchState.titleBeforeSearch;
|
|
|
|
|
// We also remove the query parameter from the URL.
|
2022-01-19 21:36:15 +00:00
|
|
|
|
if (browserSupportsHistoryApi()) {
|
2023-04-14 23:09:20 +00:00
|
|
|
|
history.replaceState(null, "", getNakedUrl() + window.location.hash);
|
2021-05-11 09:47:39 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2022-05-03 04:03:17 +00:00
|
|
|
|
getQueryStringParams: () => {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const params = {};
|
2021-05-11 09:47:39 +00:00
|
|
|
|
window.location.search.substring(1).split("&").
|
2022-05-03 04:03:17 +00:00
|
|
|
|
map(s => {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const pair = s.split("=");
|
2021-05-11 09:47:39 +00:00
|
|
|
|
params[decodeURIComponent(pair[0])] =
|
|
|
|
|
typeof pair[1] === "undefined" ? null : decodeURIComponent(pair[1]);
|
|
|
|
|
});
|
|
|
|
|
return params;
|
|
|
|
|
},
|
2022-05-03 04:03:17 +00:00
|
|
|
|
setup: () => {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const search_input = searchState.input;
|
2021-05-11 09:47:39 +00:00
|
|
|
|
if (!searchState.input) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-04-25 12:23:17 +00:00
|
|
|
|
let searchLoaded = false;
|
2021-05-11 09:47:39 +00:00
|
|
|
|
function loadSearch() {
|
|
|
|
|
if (!searchLoaded) {
|
|
|
|
|
searchLoaded = true;
|
2022-10-24 08:28:55 +00:00
|
|
|
|
loadScript(getVar("static-root-path") + getVar("search-js"));
|
2022-06-15 06:25:51 +00:00
|
|
|
|
loadScript(resourcePath("search-index", ".js"));
|
2021-05-11 09:47:39 +00:00
|
|
|
|
}
|
2021-04-13 06:50:18 +00:00
|
|
|
|
}
|
2017-10-14 14:31:48 +00:00
|
|
|
|
|
2022-05-03 04:03:17 +00:00
|
|
|
|
search_input.addEventListener("focus", () => {
|
2022-01-10 13:57:43 +00:00
|
|
|
|
search_input.origPlaceholder = search_input.placeholder;
|
2021-05-11 09:47:39 +00:00
|
|
|
|
search_input.placeholder = "Type your search here.";
|
|
|
|
|
loadSearch();
|
|
|
|
|
});
|
2020-06-02 02:18:38 +00:00
|
|
|
|
|
2022-05-07 18:18:23 +00:00
|
|
|
|
if (search_input.value !== "") {
|
2021-10-27 01:50:07 +00:00
|
|
|
|
loadSearch();
|
|
|
|
|
}
|
2018-08-15 18:08:25 +00:00
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const params = searchState.getQueryStringParams();
|
2021-05-11 09:47:39 +00:00
|
|
|
|
if (params.search !== undefined) {
|
2022-11-28 16:23:50 +00:00
|
|
|
|
searchState.setLoadingSearch();
|
2021-05-11 09:47:39 +00:00
|
|
|
|
loadSearch();
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-11-28 16:23:50 +00:00
|
|
|
|
setLoadingSearch: () => {
|
|
|
|
|
const search = searchState.outputElement();
|
|
|
|
|
search.innerHTML = "<h3 class=\"search-loading\">" + searchState.loadingText + "</h3>";
|
|
|
|
|
searchState.showResults(search);
|
|
|
|
|
},
|
2021-04-13 07:35:36 +00:00
|
|
|
|
};
|
2020-05-31 12:27:33 +00:00
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const toggleAllDocsId = "toggle-all-docs";
|
|
|
|
|
let savedHash = "";
|
2018-11-26 16:17:38 +00:00
|
|
|
|
|
2019-11-05 16:41:40 +00:00
|
|
|
|
function handleHashes(ev) {
|
2022-01-19 21:36:15 +00:00
|
|
|
|
if (ev !== null && searchState.isDisplayed() && ev.newURL) {
|
2019-11-05 16:41:40 +00:00
|
|
|
|
// This block occurs when clicking on an element in the navbar while
|
|
|
|
|
// in a search.
|
2022-01-19 21:36:15 +00:00
|
|
|
|
switchDisplayedElement(null);
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1);
|
2022-01-19 21:36:15 +00:00
|
|
|
|
if (browserSupportsHistoryApi()) {
|
2021-01-25 12:21:12 +00:00
|
|
|
|
// `window.location.search`` contains all the query parameters, not just `search`.
|
2022-01-10 13:57:43 +00:00
|
|
|
|
history.replaceState(null, "",
|
2021-01-25 12:21:12 +00:00
|
|
|
|
getNakedUrl() + window.location.search + "#" + hash);
|
2017-11-10 18:40:46 +00:00
|
|
|
|
}
|
2022-01-19 21:36:15 +00:00
|
|
|
|
const elem = document.getElementById(hash);
|
2017-11-06 20:14:37 +00:00
|
|
|
|
if (elem) {
|
|
|
|
|
elem.scrollIntoView();
|
|
|
|
|
}
|
2013-10-02 17:32:13 +00:00
|
|
|
|
}
|
2019-11-05 16:41:40 +00:00
|
|
|
|
// This part is used in case an element is not visible.
|
2023-04-10 22:13:49 +00:00
|
|
|
|
const pageId = window.location.hash.replace(/^#/, "");
|
|
|
|
|
if (savedHash !== pageId) {
|
|
|
|
|
savedHash = pageId;
|
|
|
|
|
if (pageId !== "") {
|
|
|
|
|
expandSection(pageId);
|
2019-11-05 16:41:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-02 17:32:13 +00:00
|
|
|
|
}
|
2018-08-23 07:43:06 +00:00
|
|
|
|
|
2019-11-05 16:41:40 +00:00
|
|
|
|
function onHashChange(ev) {
|
|
|
|
|
// If we're in mobile mode, we should hide the sidebar in any case.
|
2022-07-01 00:28:29 +00:00
|
|
|
|
hideSidebar();
|
2019-11-07 09:16:14 +00:00
|
|
|
|
handleHashes(ev);
|
2019-11-05 16:41:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 21:01:47 +00:00
|
|
|
|
function openParentDetails(elem) {
|
|
|
|
|
while (elem) {
|
|
|
|
|
if (elem.tagName === "DETAILS") {
|
|
|
|
|
elem.open = true;
|
|
|
|
|
}
|
|
|
|
|
elem = elem.parentNode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-25 10:34:04 +00:00
|
|
|
|
function expandSection(id) {
|
2021-05-08 12:21:57 +00:00
|
|
|
|
openParentDetails(document.getElementById(id));
|
2018-08-23 07:43:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 15:04:28 +00:00
|
|
|
|
function handleEscape(ev) {
|
2022-01-19 21:36:15 +00:00
|
|
|
|
searchState.clearInputTimeout();
|
2022-06-20 14:28:52 +00:00
|
|
|
|
switchDisplayedElement(null);
|
|
|
|
|
if (browserSupportsHistoryApi()) {
|
2023-04-14 23:09:20 +00:00
|
|
|
|
history.replaceState(null, "", getNakedUrl() + window.location.hash);
|
2018-03-05 22:37:33 +00:00
|
|
|
|
}
|
2022-06-20 14:28:52 +00:00
|
|
|
|
ev.preventDefault();
|
2021-04-13 07:35:36 +00:00
|
|
|
|
searchState.defocus();
|
2023-01-26 20:32:33 +00:00
|
|
|
|
window.hideAllModals(true); // true = reset focus for tooltips
|
2018-03-18 15:32:41 +00:00
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2018-03-18 15:32:41 +00:00
|
|
|
|
function handleShortcut(ev) {
|
2015-11-05 10:39:02 +00:00
|
|
|
|
// Don't interfere with browser shortcuts
|
2022-06-28 21:56:24 +00:00
|
|
|
|
const disableShortcuts = getSettingValue("disable-shortcuts") === "true";
|
2021-05-09 20:49:22 +00:00
|
|
|
|
if (ev.ctrlKey || ev.altKey || ev.metaKey || disableShortcuts) {
|
2015-11-05 10:39:02 +00:00
|
|
|
|
return;
|
2018-03-05 22:37:33 +00:00
|
|
|
|
}
|
2015-11-05 10:39:02 +00:00
|
|
|
|
|
2022-06-28 22:06:48 +00:00
|
|
|
|
if (document.activeElement.tagName === "INPUT" &&
|
2023-01-18 18:52:31 +00:00
|
|
|
|
document.activeElement.type !== "checkbox" &&
|
|
|
|
|
document.activeElement.type !== "radio") {
|
2018-03-18 15:32:41 +00:00
|
|
|
|
switch (getVirtualKey(ev)) {
|
|
|
|
|
case "Escape":
|
2019-09-09 15:04:28 +00:00
|
|
|
|
handleEscape(ev);
|
2018-03-18 15:32:41 +00:00
|
|
|
|
break;
|
2015-04-11 22:32:53 +00:00
|
|
|
|
}
|
2018-03-18 15:32:41 +00:00
|
|
|
|
} else {
|
|
|
|
|
switch (getVirtualKey(ev)) {
|
|
|
|
|
case "Escape":
|
2019-09-09 15:04:28 +00:00
|
|
|
|
handleEscape(ev);
|
2018-03-18 15:32:41 +00:00
|
|
|
|
break;
|
2015-07-07 14:15:22 +00:00
|
|
|
|
|
2018-03-18 15:32:41 +00:00
|
|
|
|
case "s":
|
|
|
|
|
case "S":
|
|
|
|
|
ev.preventDefault();
|
2021-04-13 07:35:36 +00:00
|
|
|
|
searchState.focus();
|
2018-03-18 15:32:41 +00:00
|
|
|
|
break;
|
2015-07-07 14:15:22 +00:00
|
|
|
|
|
2018-03-18 15:32:41 +00:00
|
|
|
|
case "+":
|
2022-10-20 09:33:31 +00:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
expandAllDocs();
|
|
|
|
|
break;
|
2018-03-18 15:32:41 +00:00
|
|
|
|
case "-":
|
|
|
|
|
ev.preventDefault();
|
2022-10-20 09:33:31 +00:00
|
|
|
|
collapseAllDocs();
|
2018-03-18 15:32:41 +00:00
|
|
|
|
break;
|
2016-05-21 02:21:35 +00:00
|
|
|
|
|
2018-03-18 15:32:41 +00:00
|
|
|
|
case "?":
|
2022-06-20 14:28:52 +00:00
|
|
|
|
showHelp();
|
2018-03-18 15:32:41 +00:00
|
|
|
|
break;
|
2020-10-30 21:27:00 +00:00
|
|
|
|
|
|
|
|
|
default:
|
2022-05-11 21:11:18 +00:00
|
|
|
|
break;
|
2020-10-30 21:27:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-22 13:14:37 +00:00
|
|
|
|
document.addEventListener("keypress", handleShortcut);
|
|
|
|
|
document.addEventListener("keydown", handleShortcut);
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2022-06-15 06:25:51 +00:00
|
|
|
|
function addSidebarItems() {
|
|
|
|
|
if (!window.SIDEBAR_ITEMS) {
|
|
|
|
|
return;
|
2021-05-02 14:35:48 +00:00
|
|
|
|
}
|
2022-06-15 06:25:51 +00:00
|
|
|
|
const sidebar = document.getElementsByClassName("sidebar-elems")[0];
|
2015-03-05 07:35:43 +00:00
|
|
|
|
|
2022-02-04 06:50:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Append to the sidebar a "block" of links - a heading along with a list (`<ul>`) of items.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} shortty - A short type name, like "primitive", "mod", or "macro"
|
|
|
|
|
* @param {string} id - The HTML id of the corresponding section on the module page.
|
|
|
|
|
* @param {string} longty - A long, capitalized, plural name, like "Primitive Types",
|
|
|
|
|
* "Modules", or "Macros".
|
|
|
|
|
*/
|
|
|
|
|
function block(shortty, id, longty) {
|
2022-06-15 06:25:51 +00:00
|
|
|
|
const filtered = window.SIDEBAR_ITEMS[shortty];
|
2018-11-16 15:31:07 +00:00
|
|
|
|
if (!filtered) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-03-05 07:35:43 +00:00
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const h3 = document.createElement("h3");
|
2022-02-04 06:50:32 +00:00
|
|
|
|
h3.innerHTML = `<a href="index.html#${id}">${longty}</a>`;
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const ul = document.createElement("ul");
|
2022-10-10 18:37:19 +00:00
|
|
|
|
ul.className = "block " + shortty;
|
2015-03-05 07:35:43 +00:00
|
|
|
|
|
2023-01-30 22:55:47 +00:00
|
|
|
|
for (const name of filtered) {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
let path;
|
2018-11-16 15:31:07 +00:00
|
|
|
|
if (shortty === "mod") {
|
|
|
|
|
path = name + "/index.html";
|
2015-03-05 07:35:43 +00:00
|
|
|
|
} else {
|
2018-11-16 15:31:07 +00:00
|
|
|
|
path = shortty + "." + name + ".html";
|
2015-03-05 07:35:43 +00:00
|
|
|
|
}
|
2022-06-15 06:25:51 +00:00
|
|
|
|
const current_page = document.location.href.split("/").pop();
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const link = document.createElement("a");
|
2022-06-15 06:25:51 +00:00
|
|
|
|
link.href = path;
|
2022-10-11 15:50:41 +00:00
|
|
|
|
if (path === current_page) {
|
|
|
|
|
link.className = "current";
|
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
link.textContent = name;
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const li = document.createElement("li");
|
2017-04-14 14:37:09 +00:00
|
|
|
|
li.appendChild(link);
|
|
|
|
|
ul.appendChild(li);
|
2015-03-05 07:35:43 +00:00
|
|
|
|
}
|
2022-10-10 18:37:19 +00:00
|
|
|
|
sidebar.appendChild(h3);
|
|
|
|
|
sidebar.appendChild(ul);
|
2015-03-05 07:35:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-02 14:35:48 +00:00
|
|
|
|
if (sidebar) {
|
2022-07-13 12:43:52 +00:00
|
|
|
|
block("primitive", "primitives", "Primitive Types");
|
|
|
|
|
block("mod", "modules", "Modules");
|
|
|
|
|
block("macro", "macros", "Macros");
|
|
|
|
|
block("struct", "structs", "Structs");
|
|
|
|
|
block("enum", "enums", "Enums");
|
|
|
|
|
block("union", "unions", "Unions");
|
|
|
|
|
block("constant", "constants", "Constants");
|
|
|
|
|
block("static", "static", "Statics");
|
|
|
|
|
block("trait", "traits", "Traits");
|
|
|
|
|
block("fn", "functions", "Functions");
|
|
|
|
|
block("type", "types", "Type Definitions");
|
|
|
|
|
block("foreigntype", "foreign-types", "Foreign Types");
|
|
|
|
|
block("keyword", "keywords", "Keywords");
|
|
|
|
|
block("traitalias", "trait-aliases", "Trait Aliases");
|
2021-05-02 14:35:48 +00:00
|
|
|
|
}
|
2022-06-15 06:25:51 +00:00
|
|
|
|
}
|
2015-03-05 07:35:43 +00:00
|
|
|
|
|
2022-05-03 04:03:17 +00:00
|
|
|
|
window.register_implementors = imp => {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const implementors = document.getElementById("implementors-list");
|
|
|
|
|
const synthetic_implementors = document.getElementById("synthetic-implementors-list");
|
|
|
|
|
const inlined_types = new Set();
|
2018-02-15 23:45:52 +00:00
|
|
|
|
|
2022-08-04 19:13:16 +00:00
|
|
|
|
const TEXT_IDX = 0;
|
|
|
|
|
const SYNTHETIC_IDX = 1;
|
|
|
|
|
const TYPES_IDX = 2;
|
|
|
|
|
|
2020-01-28 12:48:08 +00:00
|
|
|
|
if (synthetic_implementors) {
|
|
|
|
|
// This `inlined_types` variable is used to avoid having the same implementation
|
|
|
|
|
// showing up twice. For example "String" in the "Sync" doc page.
|
|
|
|
|
//
|
|
|
|
|
// By the way, this is only used by and useful for traits implemented automatically
|
|
|
|
|
// (like "Send" and "Sync").
|
2022-05-03 04:03:17 +00:00
|
|
|
|
onEachLazy(synthetic_implementors.getElementsByClassName("impl"), el => {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const aliases = el.getAttribute("data-aliases");
|
2020-01-28 12:48:08 +00:00
|
|
|
|
if (!aliases) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-03 04:03:17 +00:00
|
|
|
|
aliases.split(",").forEach(alias => {
|
2020-01-28 12:48:08 +00:00
|
|
|
|
inlined_types.add(alias);
|
|
|
|
|
});
|
2020-01-13 22:28:34 +00:00
|
|
|
|
});
|
2020-01-28 12:48:08 +00:00
|
|
|
|
}
|
2020-01-13 22:28:34 +00:00
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
let currentNbImpls = implementors.getElementsByClassName("impl").length;
|
2023-01-13 17:09:25 +00:00
|
|
|
|
const traitName = document.querySelector(".main-heading h1 > .trait").textContent;
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const baseIdName = "impl-" + traitName + "-";
|
|
|
|
|
const libs = Object.getOwnPropertyNames(imp);
|
2022-05-06 00:20:14 +00:00
|
|
|
|
// We don't want to include impls from this JS file, when the HTML already has them.
|
|
|
|
|
// The current crate should always be ignored. Other crates that should also be
|
|
|
|
|
// ignored are included in the attribute `data-ignore-extern-crates`.
|
2022-08-26 21:49:06 +00:00
|
|
|
|
const script = document
|
|
|
|
|
.querySelector("script[data-ignore-extern-crates]");
|
|
|
|
|
const ignoreExternCrates = script ? script.getAttribute("data-ignore-extern-crates") : "";
|
2022-04-25 12:23:17 +00:00
|
|
|
|
for (const lib of libs) {
|
2022-05-06 00:20:14 +00:00
|
|
|
|
if (lib === window.currentCrate || ignoreExternCrates.indexOf(lib) !== -1) {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const structs = imp[lib];
|
2018-02-10 19:34:46 +00:00
|
|
|
|
|
|
|
|
|
struct_loop:
|
2022-04-25 12:23:17 +00:00
|
|
|
|
for (const struct of structs) {
|
2022-08-04 19:13:16 +00:00
|
|
|
|
const list = struct[SYNTHETIC_IDX] ? synthetic_implementors : implementors;
|
Generate documentation for auto-trait impls
A new section is added to both both struct and trait doc pages.
On struct/enum pages, a new 'Auto Trait Implementations' section displays any
synthetic implementations for auto traits. Currently, this is only done
for Send and Sync.
On trait pages, a new 'Auto Implementors' section displays all types
which automatically implement the trait. Effectively, this is a list of
all public types in the standard library.
Synthesized impls for a particular auto trait ('synthetic impls') take
into account generic bounds. For example, a type 'struct Foo<T>(T)' will
have 'impl<T> Send for Foo<T> where T: Send' generated for it.
Manual implementations of auto traits are also taken into account. If we have
the following types:
'struct Foo<T>(T)'
'struct Wrapper<T>(Foo<T>)'
'unsafe impl<T> Send for Wrapper<T>' // pretend that Wrapper<T> makes
this sound somehow
Then Wrapper will have the following impl generated:
'impl<T> Send for Wrapper<T>'
reflecting the fact that 'T: Send' need not hold for 'Wrapper<T>: Send'
to hold
Lifetimes, HRTBS, and projections (e.g. '<T as Iterator>::Item') are
taken into account by synthetic impls
However, if a type can *never* implement a particular auto trait
(e.g. 'struct MyStruct<T>(*const T)'), then a negative impl will be
generated (in this case, 'impl<T> !Send for MyStruct<T>')
All of this means that a user should be able to copy-paste a synthetic
impl into their code, without any observable changes in behavior
(assuming the rest of the program remains unchanged).
2017-11-22 21:16:55 +00:00
|
|
|
|
|
2022-08-04 19:13:16 +00:00
|
|
|
|
// The types list is only used for synthetic impls.
|
|
|
|
|
// If this changes, `main.js` and `write_shared.rs` both need changed.
|
|
|
|
|
if (struct[SYNTHETIC_IDX]) {
|
|
|
|
|
for (const struct_type of struct[TYPES_IDX]) {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
if (inlined_types.has(struct_type)) {
|
2018-02-15 23:45:52 +00:00
|
|
|
|
continue struct_loop;
|
|
|
|
|
}
|
2022-04-25 12:23:17 +00:00
|
|
|
|
inlined_types.add(struct_type);
|
Generate documentation for auto-trait impls
A new section is added to both both struct and trait doc pages.
On struct/enum pages, a new 'Auto Trait Implementations' section displays any
synthetic implementations for auto traits. Currently, this is only done
for Send and Sync.
On trait pages, a new 'Auto Implementors' section displays all types
which automatically implement the trait. Effectively, this is a list of
all public types in the standard library.
Synthesized impls for a particular auto trait ('synthetic impls') take
into account generic bounds. For example, a type 'struct Foo<T>(T)' will
have 'impl<T> Send for Foo<T> where T: Send' generated for it.
Manual implementations of auto traits are also taken into account. If we have
the following types:
'struct Foo<T>(T)'
'struct Wrapper<T>(Foo<T>)'
'unsafe impl<T> Send for Wrapper<T>' // pretend that Wrapper<T> makes
this sound somehow
Then Wrapper will have the following impl generated:
'impl<T> Send for Wrapper<T>'
reflecting the fact that 'T: Send' need not hold for 'Wrapper<T>: Send'
to hold
Lifetimes, HRTBS, and projections (e.g. '<T as Iterator>::Item') are
taken into account by synthetic impls
However, if a type can *never* implement a particular auto trait
(e.g. 'struct MyStruct<T>(*const T)'), then a negative impl will be
generated (in this case, 'impl<T> !Send for MyStruct<T>')
All of this means that a user should be able to copy-paste a synthetic
impl into their code, without any observable changes in behavior
(assuming the rest of the program remains unchanged).
2017-11-22 21:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const code = document.createElement("h3");
|
2022-08-04 19:13:16 +00:00
|
|
|
|
code.innerHTML = struct[TEXT_IDX];
|
2021-07-25 21:41:57 +00:00
|
|
|
|
addClass(code, "code-header");
|
2017-04-14 14:37:09 +00:00
|
|
|
|
|
2022-05-03 04:03:17 +00:00
|
|
|
|
onEachLazy(code.getElementsByTagName("a"), elem => {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const href = elem.getAttribute("href");
|
2020-12-31 12:21:27 +00:00
|
|
|
|
|
2023-01-04 02:46:40 +00:00
|
|
|
|
if (href && !/^(?:[a-z+]+:)?\/\//.test(href)) {
|
2021-01-18 11:03:53 +00:00
|
|
|
|
elem.setAttribute("href", window.rootPath + href);
|
2014-06-01 17:17:30 +00:00
|
|
|
|
}
|
2020-12-31 12:21:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const currentId = baseIdName + currentNbImpls;
|
|
|
|
|
const anchor = document.createElement("a");
|
2021-07-10 12:58:36 +00:00
|
|
|
|
anchor.href = "#" + currentId;
|
|
|
|
|
addClass(anchor, "anchor");
|
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const display = document.createElement("div");
|
2021-07-10 12:58:36 +00:00
|
|
|
|
display.id = currentId;
|
2018-07-01 14:11:14 +00:00
|
|
|
|
addClass(display, "impl");
|
2021-07-10 12:58:36 +00:00
|
|
|
|
display.appendChild(anchor);
|
|
|
|
|
display.appendChild(code);
|
2018-07-01 14:11:14 +00:00
|
|
|
|
list.appendChild(display);
|
2021-07-10 12:58:36 +00:00
|
|
|
|
currentNbImpls += 1;
|
2014-05-21 23:41:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
if (window.pending_implementors) {
|
|
|
|
|
window.register_implementors(window.pending_implementors);
|
|
|
|
|
}
|
2014-05-24 03:17:27 +00:00
|
|
|
|
|
2022-06-15 06:25:51 +00:00
|
|
|
|
function addSidebarCrates() {
|
|
|
|
|
if (!window.ALL_CRATES) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const sidebarElems = document.getElementsByClassName("sidebar-elems")[0];
|
|
|
|
|
if (!sidebarElems) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Draw a convenient sidebar of known crates if we have a listing
|
2022-10-10 18:37:19 +00:00
|
|
|
|
const h3 = document.createElement("h3");
|
|
|
|
|
h3.innerHTML = "Crates";
|
2022-06-15 06:25:51 +00:00
|
|
|
|
const ul = document.createElement("ul");
|
2022-10-10 18:37:19 +00:00
|
|
|
|
ul.className = "block crate";
|
2022-06-15 06:25:51 +00:00
|
|
|
|
|
|
|
|
|
for (const crate of window.ALL_CRATES) {
|
|
|
|
|
const link = document.createElement("a");
|
|
|
|
|
link.href = window.rootPath + crate + "/index.html";
|
2022-10-10 18:37:19 +00:00
|
|
|
|
if (window.rootPath !== "./" && crate === window.currentCrate) {
|
|
|
|
|
link.className = "current";
|
|
|
|
|
}
|
2022-06-15 06:25:51 +00:00
|
|
|
|
link.textContent = crate;
|
|
|
|
|
|
|
|
|
|
const li = document.createElement("li");
|
|
|
|
|
li.appendChild(link);
|
|
|
|
|
ul.appendChild(li);
|
|
|
|
|
}
|
2022-10-10 18:37:19 +00:00
|
|
|
|
sidebarElems.appendChild(h3);
|
|
|
|
|
sidebarElems.appendChild(ul);
|
2022-06-15 06:25:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-20 09:33:31 +00:00
|
|
|
|
function expandAllDocs() {
|
|
|
|
|
const innerToggle = document.getElementById(toggleAllDocsId);
|
|
|
|
|
removeClass(innerToggle, "will-expand");
|
2023-01-10 18:35:37 +00:00
|
|
|
|
onEachLazy(document.getElementsByClassName("toggle"), e => {
|
2022-11-27 19:11:21 +00:00
|
|
|
|
if (!hasClass(e, "type-contents-toggle") && !hasClass(e, "more-examples-toggle")) {
|
2022-10-20 09:33:31 +00:00
|
|
|
|
e.open = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
innerToggle.title = "collapse all docs";
|
|
|
|
|
innerToggle.children[0].innerText = "\u2212"; // "\u2212" is "−" minus sign
|
|
|
|
|
}
|
2022-06-15 06:25:51 +00:00
|
|
|
|
|
2022-10-20 09:33:31 +00:00
|
|
|
|
function collapseAllDocs() {
|
|
|
|
|
const innerToggle = document.getElementById(toggleAllDocsId);
|
|
|
|
|
addClass(innerToggle, "will-expand");
|
2023-01-10 18:35:37 +00:00
|
|
|
|
onEachLazy(document.getElementsByClassName("toggle"), e => {
|
2022-10-20 09:33:31 +00:00
|
|
|
|
if (e.parentNode.id !== "implementations-list" ||
|
|
|
|
|
(!hasClass(e, "implementors-toggle") &&
|
|
|
|
|
!hasClass(e, "type-contents-toggle"))
|
|
|
|
|
) {
|
|
|
|
|
e.open = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
innerToggle.title = "expand all docs";
|
|
|
|
|
innerToggle.children[0].innerText = "+";
|
2015-05-07 07:53:21 +00:00
|
|
|
|
}
|
2015-05-07 08:17:10 +00:00
|
|
|
|
|
2021-05-08 12:21:57 +00:00
|
|
|
|
function toggleAllDocs() {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const innerToggle = document.getElementById(toggleAllDocsId);
|
2018-11-26 16:17:38 +00:00
|
|
|
|
if (!innerToggle) {
|
2018-04-25 17:50:32 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-11-26 16:17:38 +00:00
|
|
|
|
if (hasClass(innerToggle, "will-expand")) {
|
2022-10-20 09:33:31 +00:00
|
|
|
|
expandAllDocs();
|
2015-05-07 07:53:21 +00:00
|
|
|
|
} else {
|
2022-10-20 09:33:31 +00:00
|
|
|
|
collapseAllDocs();
|
2015-04-22 16:50:19 +00:00
|
|
|
|
}
|
2016-05-21 02:21:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 12:49:04 +00:00
|
|
|
|
(function() {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const toggles = document.getElementById(toggleAllDocsId);
|
2020-08-28 11:30:21 +00:00
|
|
|
|
if (toggles) {
|
|
|
|
|
toggles.onclick = toggleAllDocs;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
|
|
|
|
|
const hideImplementations = getSettingValue("auto-hide-trait-implementations") === "true";
|
|
|
|
|
const hideLargeItemContents = getSettingValue("auto-hide-large-items") !== "false";
|
2021-04-18 21:33:33 +00:00
|
|
|
|
|
2021-06-13 05:19:26 +00:00
|
|
|
|
function setImplementorsTogglesOpen(id, open) {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const list = document.getElementById(id);
|
2021-05-22 04:24:03 +00:00
|
|
|
|
if (list !== null) {
|
2022-05-03 04:03:17 +00:00
|
|
|
|
onEachLazy(list.getElementsByClassName("implementors-toggle"), e => {
|
2021-06-13 05:19:26 +00:00
|
|
|
|
e.open = open;
|
2021-05-22 04:24:03 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-13 05:19:26 +00:00
|
|
|
|
if (hideImplementations) {
|
|
|
|
|
setImplementorsTogglesOpen("trait-implementations-list", false);
|
|
|
|
|
setImplementorsTogglesOpen("blanket-implementations-list", false);
|
2021-05-22 04:24:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-10 18:35:37 +00:00
|
|
|
|
onEachLazy(document.getElementsByClassName("toggle"), e => {
|
2021-05-22 04:24:03 +00:00
|
|
|
|
if (!hideLargeItemContents && hasClass(e, "type-contents-toggle")) {
|
2021-04-18 06:43:20 +00:00
|
|
|
|
e.open = true;
|
|
|
|
|
}
|
2021-05-10 23:41:41 +00:00
|
|
|
|
if (hideMethodDocs && hasClass(e, "method-toggle")) {
|
|
|
|
|
e.open = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 06:43:20 +00:00
|
|
|
|
});
|
2020-05-17 12:49:04 +00:00
|
|
|
|
}());
|
2017-04-14 14:37:09 +00:00
|
|
|
|
|
2022-09-21 22:43:38 +00:00
|
|
|
|
window.rustdoc_add_line_numbers_to_examples = () => {
|
|
|
|
|
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
|
|
|
|
|
const parent = x.parentNode;
|
2022-09-26 17:50:51 +00:00
|
|
|
|
const line_numbers = parent.querySelectorAll(".example-line-numbers");
|
2022-09-21 22:43:38 +00:00
|
|
|
|
if (line_numbers.length > 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const count = x.textContent.split("\n").length;
|
|
|
|
|
const elems = [];
|
|
|
|
|
for (let i = 0; i < count; ++i) {
|
|
|
|
|
elems.push(i + 1);
|
|
|
|
|
}
|
|
|
|
|
const node = document.createElement("pre");
|
2022-09-26 17:50:51 +00:00
|
|
|
|
addClass(node, "example-line-numbers");
|
2022-09-21 22:43:38 +00:00
|
|
|
|
node.innerHTML = elems.join("\n");
|
|
|
|
|
parent.insertBefore(node, x);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.rustdoc_remove_line_numbers_from_examples = () => {
|
|
|
|
|
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
|
|
|
|
|
const parent = x.parentNode;
|
2022-09-26 17:50:51 +00:00
|
|
|
|
const line_numbers = parent.querySelectorAll(".example-line-numbers");
|
2022-09-21 22:43:38 +00:00
|
|
|
|
for (const node of line_numbers) {
|
|
|
|
|
parent.removeChild(node);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-18 18:04:53 +00:00
|
|
|
|
if (getSettingValue("line-numbers") === "true") {
|
|
|
|
|
window.rustdoc_add_line_numbers_to_examples();
|
|
|
|
|
}
|
2017-11-10 18:40:46 +00:00
|
|
|
|
|
2022-10-17 18:41:39 +00:00
|
|
|
|
function showSidebar() {
|
2022-11-26 21:32:57 +00:00
|
|
|
|
window.hideAllModals(false);
|
2022-10-17 18:41:39 +00:00
|
|
|
|
const sidebar = document.getElementsByClassName("sidebar")[0];
|
|
|
|
|
addClass(sidebar, "shown");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hideSidebar() {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const sidebar = document.getElementsByClassName("sidebar")[0];
|
Simplify and unify rustdoc sidebar styles
This switches to just use size, weight, and spacing to distinguish
headings in the sidebar. We no longer use boxes, horizontal bars, or
centering to distinguish headings. This makes it much easier to
understand the hierarchy of headings, and reduces visual noise.
I also refactored how the mobile topbar works. Previously, we tried to
shift around elements from the sidebar to make the topbar. Now, the
topbar gets its own elements, which can be styled on their own. This
makes styling and reasoning about those elements simpler.
Because the heading font sizes are bigger, increase the sidebar width
slightly.
As a very minor change, removed version from the "All types" page. It's
now only on the crate page.
2022-01-07 00:48:24 +00:00
|
|
|
|
removeClass(sidebar, "shown");
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 00:28:29 +00:00
|
|
|
|
window.addEventListener("resize", () => {
|
2023-01-26 20:32:33 +00:00
|
|
|
|
if (window.CURRENT_TOOLTIP_ELEMENT) {
|
|
|
|
|
// As a workaround to the behavior of `contains: layout` used in doc togglers,
|
|
|
|
|
// tooltip popovers are positioned using javascript.
|
2022-11-07 22:53:30 +00:00
|
|
|
|
//
|
|
|
|
|
// This means when the window is resized, we need to redo the layout.
|
2023-01-26 20:32:33 +00:00
|
|
|
|
const base = window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE;
|
|
|
|
|
const force_visible = base.TOOLTIP_FORCE_VISIBLE;
|
|
|
|
|
hideTooltip(false);
|
2022-11-07 22:53:30 +00:00
|
|
|
|
if (force_visible) {
|
2023-01-26 20:32:33 +00:00
|
|
|
|
showTooltip(base);
|
|
|
|
|
base.TOOLTIP_FORCE_VISIBLE = true;
|
2022-11-07 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-01 00:28:29 +00:00
|
|
|
|
});
|
|
|
|
|
|
2023-01-18 00:22:05 +00:00
|
|
|
|
const mainElem = document.getElementById(MAIN_ID);
|
|
|
|
|
if (mainElem) {
|
|
|
|
|
mainElem.addEventListener("click", hideSidebar);
|
2021-05-09 18:21:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-21 20:28:42 +00:00
|
|
|
|
onEachLazy(document.querySelectorAll("a[href^='#']"), el => {
|
2021-05-09 18:21:38 +00:00
|
|
|
|
// For clicks on internal links (<A> tags with a hash property), we expand the section we're
|
|
|
|
|
// jumping to *before* jumping there. We can't do this in onHashChange, because it changes
|
|
|
|
|
// the height of the document so we wind up scrolled to the wrong place.
|
2022-12-21 20:28:42 +00:00
|
|
|
|
el.addEventListener("click", () => {
|
|
|
|
|
expandSection(el.hash.slice(1));
|
|
|
|
|
hideSidebar();
|
|
|
|
|
});
|
2021-05-09 18:21:38 +00:00
|
|
|
|
});
|
|
|
|
|
|
2023-01-10 18:35:37 +00:00
|
|
|
|
onEachLazy(document.querySelectorAll(".toggle > summary:not(.hideme)"), el => {
|
2022-05-03 04:03:17 +00:00
|
|
|
|
el.addEventListener("click", e => {
|
|
|
|
|
if (e.target.tagName !== "SUMMARY" && e.target.tagName !== "A") {
|
2021-11-21 08:24:38 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
2021-11-22 08:49:57 +00:00
|
|
|
|
});
|
2021-11-21 08:24:38 +00:00
|
|
|
|
});
|
|
|
|
|
|
2023-01-26 20:32:33 +00:00
|
|
|
|
function showTooltip(e) {
|
|
|
|
|
const notable_ty = e.getAttribute("data-notable-ty");
|
|
|
|
|
if (!window.NOTABLE_TRAITS && notable_ty) {
|
2022-11-07 22:53:30 +00:00
|
|
|
|
const data = document.getElementById("notable-traits-data");
|
|
|
|
|
if (data) {
|
|
|
|
|
window.NOTABLE_TRAITS = JSON.parse(data.innerText);
|
|
|
|
|
} else {
|
2023-01-26 20:32:33 +00:00
|
|
|
|
throw new Error("showTooltip() called with notable without any notable traits!");
|
2022-11-07 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-26 20:32:33 +00:00
|
|
|
|
if (window.CURRENT_TOOLTIP_ELEMENT && window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE === e) {
|
2022-11-07 22:53:30 +00:00
|
|
|
|
// Make this function idempotent.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-26 21:32:57 +00:00
|
|
|
|
window.hideAllModals(false);
|
2022-11-07 22:53:30 +00:00
|
|
|
|
const wrapper = document.createElement("div");
|
2023-01-26 20:32:33 +00:00
|
|
|
|
if (notable_ty) {
|
|
|
|
|
wrapper.innerHTML = "<div class=\"content\">" +
|
|
|
|
|
window.NOTABLE_TRAITS[notable_ty] + "</div>";
|
|
|
|
|
} else if (e.getAttribute("title") !== undefined) {
|
|
|
|
|
const titleContent = document.createElement("div");
|
|
|
|
|
titleContent.className = "content";
|
|
|
|
|
titleContent.appendChild(document.createTextNode(e.getAttribute("title")));
|
|
|
|
|
wrapper.appendChild(titleContent);
|
|
|
|
|
}
|
|
|
|
|
wrapper.className = "tooltip popover";
|
2022-11-09 01:00:22 +00:00
|
|
|
|
const focusCatcher = document.createElement("div");
|
|
|
|
|
focusCatcher.setAttribute("tabindex", "0");
|
2023-01-26 20:32:33 +00:00
|
|
|
|
focusCatcher.onfocus = hideTooltip;
|
2022-11-09 01:00:22 +00:00
|
|
|
|
wrapper.appendChild(focusCatcher);
|
|
|
|
|
const pos = e.getBoundingClientRect();
|
|
|
|
|
// 5px overlap so that the mouse can easily travel from place to place
|
|
|
|
|
wrapper.style.top = (pos.top + window.scrollY + pos.height) + "px";
|
|
|
|
|
wrapper.style.left = 0;
|
|
|
|
|
wrapper.style.right = "auto";
|
|
|
|
|
wrapper.style.visibility = "hidden";
|
2022-11-08 04:18:01 +00:00
|
|
|
|
const body = document.getElementsByTagName("body")[0];
|
|
|
|
|
body.appendChild(wrapper);
|
2022-11-09 01:00:22 +00:00
|
|
|
|
const wrapperPos = wrapper.getBoundingClientRect();
|
|
|
|
|
// offset so that the arrow points at the center of the "(i)"
|
|
|
|
|
const finalPos = pos.left + window.scrollX - wrapperPos.width + 24;
|
|
|
|
|
if (finalPos > 0) {
|
|
|
|
|
wrapper.style.left = finalPos + "px";
|
|
|
|
|
} else {
|
|
|
|
|
wrapper.style.setProperty(
|
|
|
|
|
"--popover-arrow-offset",
|
|
|
|
|
(wrapperPos.right - pos.right + 4) + "px"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
wrapper.style.visibility = "";
|
2023-01-26 20:32:33 +00:00
|
|
|
|
window.CURRENT_TOOLTIP_ELEMENT = wrapper;
|
|
|
|
|
window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE = e;
|
2022-11-07 22:53:30 +00:00
|
|
|
|
wrapper.onpointerleave = function(ev) {
|
|
|
|
|
// If this is a synthetic touch event, ignore it. A click event will be along shortly.
|
|
|
|
|
if (ev.pointerType !== "mouse") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-26 20:32:33 +00:00
|
|
|
|
if (!e.TOOLTIP_FORCE_VISIBLE && !elemIsInParent(event.relatedTarget, e)) {
|
|
|
|
|
hideTooltip(true);
|
2022-11-07 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-26 20:32:33 +00:00
|
|
|
|
function tooltipBlurHandler(event) {
|
|
|
|
|
if (window.CURRENT_TOOLTIP_ELEMENT &&
|
|
|
|
|
!elemIsInParent(document.activeElement, window.CURRENT_TOOLTIP_ELEMENT) &&
|
|
|
|
|
!elemIsInParent(event.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT) &&
|
|
|
|
|
!elemIsInParent(document.activeElement, window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE) &&
|
|
|
|
|
!elemIsInParent(event.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE)
|
2022-11-09 01:00:22 +00:00
|
|
|
|
) {
|
2022-11-09 00:59:03 +00:00
|
|
|
|
// Work around a difference in the focus behaviour between Firefox, Chrome, and Safari.
|
2023-01-26 20:32:33 +00:00
|
|
|
|
// When I click the button on an already-opened tooltip popover, Safari
|
2022-11-09 00:59:03 +00:00
|
|
|
|
// hides the popover and then immediately shows it again, while everyone else hides it
|
|
|
|
|
// and it stays hidden.
|
|
|
|
|
//
|
|
|
|
|
// To work around this, make sure the click finishes being dispatched before
|
2023-01-26 20:32:33 +00:00
|
|
|
|
// hiding the popover. Since `hideTooltip()` is idempotent, this makes Safari behave
|
2022-11-09 00:59:03 +00:00
|
|
|
|
// consistently with the other two.
|
2023-01-26 20:32:33 +00:00
|
|
|
|
setTimeout(() => hideTooltip(false), 0);
|
2022-11-09 01:00:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-26 20:32:33 +00:00
|
|
|
|
function hideTooltip(focus) {
|
|
|
|
|
if (window.CURRENT_TOOLTIP_ELEMENT) {
|
|
|
|
|
if (window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.TOOLTIP_FORCE_VISIBLE) {
|
2022-11-18 23:25:21 +00:00
|
|
|
|
if (focus) {
|
2023-01-26 20:32:33 +00:00
|
|
|
|
window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.focus();
|
2022-11-18 23:25:21 +00:00
|
|
|
|
}
|
2023-01-26 20:32:33 +00:00
|
|
|
|
window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.TOOLTIP_FORCE_VISIBLE = false;
|
2022-11-09 01:00:22 +00:00
|
|
|
|
}
|
2022-11-08 04:18:01 +00:00
|
|
|
|
const body = document.getElementsByTagName("body")[0];
|
2023-01-26 20:32:33 +00:00
|
|
|
|
body.removeChild(window.CURRENT_TOOLTIP_ELEMENT);
|
|
|
|
|
window.CURRENT_TOOLTIP_ELEMENT = null;
|
2022-11-07 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-26 20:32:33 +00:00
|
|
|
|
onEachLazy(document.getElementsByClassName("tooltip"), e => {
|
2020-07-06 19:53:44 +00:00
|
|
|
|
e.onclick = function() {
|
2023-01-26 20:32:33 +00:00
|
|
|
|
this.TOOLTIP_FORCE_VISIBLE = this.TOOLTIP_FORCE_VISIBLE ? false : true;
|
|
|
|
|
if (window.CURRENT_TOOLTIP_ELEMENT && !this.TOOLTIP_FORCE_VISIBLE) {
|
|
|
|
|
hideTooltip(true);
|
2022-11-07 22:53:30 +00:00
|
|
|
|
} else {
|
2023-01-26 20:32:33 +00:00
|
|
|
|
showTooltip(this);
|
|
|
|
|
window.CURRENT_TOOLTIP_ELEMENT.setAttribute("tabindex", "0");
|
|
|
|
|
window.CURRENT_TOOLTIP_ELEMENT.focus();
|
|
|
|
|
window.CURRENT_TOOLTIP_ELEMENT.onblur = tooltipBlurHandler;
|
2022-11-07 22:53:30 +00:00
|
|
|
|
}
|
2022-11-09 01:00:22 +00:00
|
|
|
|
return false;
|
2022-11-07 22:53:30 +00:00
|
|
|
|
};
|
|
|
|
|
e.onpointerenter = function(ev) {
|
|
|
|
|
// If this is a synthetic touch event, ignore it. A click event will be along shortly.
|
|
|
|
|
if (ev.pointerType !== "mouse") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-26 20:32:33 +00:00
|
|
|
|
showTooltip(this);
|
2022-11-07 22:53:30 +00:00
|
|
|
|
};
|
|
|
|
|
e.onpointerleave = function(ev) {
|
|
|
|
|
// If this is a synthetic touch event, ignore it. A click event will be along shortly.
|
|
|
|
|
if (ev.pointerType !== "mouse") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-26 20:32:33 +00:00
|
|
|
|
if (!this.TOOLTIP_FORCE_VISIBLE &&
|
|
|
|
|
!elemIsInParent(ev.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT)) {
|
|
|
|
|
hideTooltip(true);
|
2022-11-07 22:53:30 +00:00
|
|
|
|
}
|
2020-07-06 19:53:44 +00:00
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const sidebar_menu_toggle = document.getElementsByClassName("sidebar-menu-toggle")[0];
|
Simplify and unify rustdoc sidebar styles
This switches to just use size, weight, and spacing to distinguish
headings in the sidebar. We no longer use boxes, horizontal bars, or
centering to distinguish headings. This makes it much easier to
understand the hierarchy of headings, and reduces visual noise.
I also refactored how the mobile topbar works. Previously, we tried to
shift around elements from the sidebar to make the topbar. Now, the
topbar gets its own elements, which can be styled on their own. This
makes styling and reasoning about those elements simpler.
Because the heading font sizes are bigger, increase the sidebar width
slightly.
As a very minor change, removed version from the "All types" page. It's
now only on the crate page.
2022-01-07 00:48:24 +00:00
|
|
|
|
if (sidebar_menu_toggle) {
|
2022-05-03 04:03:17 +00:00
|
|
|
|
sidebar_menu_toggle.addEventListener("click", () => {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const sidebar = document.getElementsByClassName("sidebar")[0];
|
Simplify and unify rustdoc sidebar styles
This switches to just use size, weight, and spacing to distinguish
headings in the sidebar. We no longer use boxes, horizontal bars, or
centering to distinguish headings. This makes it much easier to
understand the hierarchy of headings, and reduces visual noise.
I also refactored how the mobile topbar works. Previously, we tried to
shift around elements from the sidebar to make the topbar. Now, the
topbar gets its own elements, which can be styled on their own. This
makes styling and reasoning about those elements simpler.
Because the heading font sizes are bigger, increase the sidebar width
slightly.
As a very minor change, removed version from the "All types" page. It's
now only on the crate page.
2022-01-07 00:48:24 +00:00
|
|
|
|
if (!hasClass(sidebar, "shown")) {
|
2022-07-01 00:28:29 +00:00
|
|
|
|
showSidebar();
|
2017-12-05 23:42:33 +00:00
|
|
|
|
} else {
|
2022-07-01 00:28:29 +00:00
|
|
|
|
hideSidebar();
|
2017-12-05 23:42:33 +00:00
|
|
|
|
}
|
Simplify and unify rustdoc sidebar styles
This switches to just use size, weight, and spacing to distinguish
headings in the sidebar. We no longer use boxes, horizontal bars, or
centering to distinguish headings. This makes it much easier to
understand the hierarchy of headings, and reduces visual noise.
I also refactored how the mobile topbar works. Previously, we tried to
shift around elements from the sidebar to make the topbar. Now, the
topbar gets its own elements, which can be styled on their own. This
makes styling and reasoning about those elements simpler.
Because the heading font sizes are bigger, increase the sidebar width
slightly.
As a very minor change, removed version from the "All types" page. It's
now only on the crate page.
2022-01-07 00:48:24 +00:00
|
|
|
|
});
|
2017-12-05 23:42:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 14:28:52 +00:00
|
|
|
|
function helpBlurHandler(event) {
|
2022-06-22 18:49:26 +00:00
|
|
|
|
blurHandler(event, getHelpButton(), window.hidePopoverMenus);
|
2022-06-20 14:28:52 +00:00
|
|
|
|
}
|
2021-05-09 18:21:38 +00:00
|
|
|
|
|
2022-06-20 14:28:52 +00:00
|
|
|
|
function buildHelpMenu() {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const book_info = document.createElement("span");
|
2021-09-15 11:37:29 +00:00
|
|
|
|
book_info.className = "top";
|
2020-10-19 11:44:27 +00:00
|
|
|
|
book_info.innerHTML = "You can find more information in \
|
|
|
|
|
<a href=\"https://doc.rust-lang.org/rustdoc/\">the rustdoc book</a>.";
|
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const shortcuts = [
|
2019-10-24 22:35:45 +00:00
|
|
|
|
["?", "Show this help dialog"],
|
|
|
|
|
["S", "Focus the search field"],
|
|
|
|
|
["↑", "Move up in search results"],
|
|
|
|
|
["↓", "Move down in search results"],
|
2021-05-09 19:56:21 +00:00
|
|
|
|
["← / →", "Switch result tab (when results focused)"],
|
2019-10-24 22:35:45 +00:00
|
|
|
|
["⏎", "Go to active search result"],
|
|
|
|
|
["+", "Expand all sections"],
|
|
|
|
|
["-", "Collapse all sections"],
|
2022-05-03 04:03:17 +00:00
|
|
|
|
].map(x => "<dt>" +
|
|
|
|
|
x[0].split(" ")
|
2022-06-06 11:57:54 +00:00
|
|
|
|
.map((y, index) => ((index & 1) === 0 ? "<kbd>" + y + "</kbd>" : " " + y + " "))
|
2022-05-03 04:03:17 +00:00
|
|
|
|
.join("") + "</dt><dd>" + x[1] + "</dd>").join("");
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const div_shortcuts = document.createElement("div");
|
2019-10-24 22:35:45 +00:00
|
|
|
|
addClass(div_shortcuts, "shortcuts");
|
|
|
|
|
div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
|
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const infos = [
|
2019-10-24 22:35:45 +00:00
|
|
|
|
"Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to \
|
2020-08-27 10:56:43 +00:00
|
|
|
|
restrict the search to a given item kind.",
|
|
|
|
|
"Accepted kinds are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \
|
2019-10-24 22:35:45 +00:00
|
|
|
|
<code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, \
|
|
|
|
|
and <code>const</code>.",
|
2020-01-12 23:37:47 +00:00
|
|
|
|
"Search functions by type signature (e.g., <code>vec -> usize</code> or \
|
2023-03-31 17:18:44 +00:00
|
|
|
|
<code>-> vec</code> or <code>String, enum:Cow -> bool</code>)",
|
2019-10-24 22:35:45 +00:00
|
|
|
|
"You can look for items with an exact name by putting double quotes around \
|
|
|
|
|
your request: <code>\"string\"</code>",
|
|
|
|
|
"Look for items inside another one by searching for a path: <code>vec::Vec</code>",
|
2022-05-03 04:03:17 +00:00
|
|
|
|
].map(x => "<p>" + x + "</p>").join("");
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const div_infos = document.createElement("div");
|
2019-10-24 22:35:45 +00:00
|
|
|
|
addClass(div_infos, "infos");
|
|
|
|
|
div_infos.innerHTML = "<h2>Search Tricks</h2>" + infos;
|
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const rustdoc_version = document.createElement("span");
|
2021-09-15 11:37:29 +00:00
|
|
|
|
rustdoc_version.className = "bottom";
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const rustdoc_version_code = document.createElement("code");
|
2021-11-24 03:22:29 +00:00
|
|
|
|
rustdoc_version_code.innerText = "rustdoc " + getVar("rustdoc-version");
|
2021-09-15 11:37:29 +00:00
|
|
|
|
rustdoc_version.appendChild(rustdoc_version_code);
|
|
|
|
|
|
2022-06-20 14:28:52 +00:00
|
|
|
|
const container = document.createElement("div");
|
2022-10-14 16:48:19 +00:00
|
|
|
|
if (!isHelpPage) {
|
|
|
|
|
container.className = "popover";
|
|
|
|
|
}
|
|
|
|
|
container.id = "help";
|
2022-06-20 14:28:52 +00:00
|
|
|
|
container.style.display = "none";
|
|
|
|
|
|
|
|
|
|
const side_by_side = document.createElement("div");
|
|
|
|
|
side_by_side.className = "side-by-side";
|
|
|
|
|
side_by_side.appendChild(div_shortcuts);
|
|
|
|
|
side_by_side.appendChild(div_infos);
|
|
|
|
|
|
|
|
|
|
container.appendChild(book_info);
|
|
|
|
|
container.appendChild(side_by_side);
|
2021-09-15 11:37:29 +00:00
|
|
|
|
container.appendChild(rustdoc_version);
|
|
|
|
|
|
2022-10-14 16:48:19 +00:00
|
|
|
|
if (isHelpPage) {
|
|
|
|
|
const help_section = document.createElement("section");
|
|
|
|
|
help_section.appendChild(container);
|
|
|
|
|
document.getElementById("main-content").appendChild(help_section);
|
|
|
|
|
container.style.display = "block";
|
|
|
|
|
} else {
|
|
|
|
|
const help_button = getHelpButton();
|
|
|
|
|
help_button.appendChild(container);
|
2022-06-20 14:28:52 +00:00
|
|
|
|
|
2022-10-14 16:48:19 +00:00
|
|
|
|
container.onblur = helpBlurHandler;
|
|
|
|
|
help_button.onblur = helpBlurHandler;
|
|
|
|
|
help_button.children[0].onblur = helpBlurHandler;
|
|
|
|
|
}
|
2022-06-20 14:28:52 +00:00
|
|
|
|
|
|
|
|
|
return container;
|
|
|
|
|
}
|
|
|
|
|
|
rustdoc: improve popover focus handling JS
This commit fixes a few inconsistencies and erratic behavior from the
notable traits, settings, and sidebar popups:
* It makes it so that pressing Escape closes the mobile sidebar.
This is a bit difficult to do on iPhone, but on other setups like
desktop tiling window managers, it's easy and makes sense.
* It makes sure that pressing escape while a notable trait popover is
open focuses the popover's toggle button, instead of leaving nothing
focused, since that makes more sense with keyboard navigation. Clicking
the settings, help, or sidebar buttons, however, will not focus the
notable trait popover toggle button.
* It ensures that notable trait and settings popovers are exclusive
with the mobile sidebar. Nothing should ever overlap a popover, and
there should never be more than one popover open at once.
2022-11-26 16:52:58 +00:00
|
|
|
|
/**
|
2023-01-26 20:32:33 +00:00
|
|
|
|
* Hide popover menus, clickable tooltips, and the sidebar (if applicable).
|
rustdoc: improve popover focus handling JS
This commit fixes a few inconsistencies and erratic behavior from the
notable traits, settings, and sidebar popups:
* It makes it so that pressing Escape closes the mobile sidebar.
This is a bit difficult to do on iPhone, but on other setups like
desktop tiling window managers, it's easy and makes sense.
* It makes sure that pressing escape while a notable trait popover is
open focuses the popover's toggle button, instead of leaving nothing
focused, since that makes more sense with keyboard navigation. Clicking
the settings, help, or sidebar buttons, however, will not focus the
notable trait popover toggle button.
* It ensures that notable trait and settings popovers are exclusive
with the mobile sidebar. Nothing should ever overlap a popover, and
there should never be more than one popover open at once.
2022-11-26 16:52:58 +00:00
|
|
|
|
*
|
2023-01-26 20:32:33 +00:00
|
|
|
|
* Pass "true" to reset focus for tooltip popovers.
|
rustdoc: improve popover focus handling JS
This commit fixes a few inconsistencies and erratic behavior from the
notable traits, settings, and sidebar popups:
* It makes it so that pressing Escape closes the mobile sidebar.
This is a bit difficult to do on iPhone, but on other setups like
desktop tiling window managers, it's easy and makes sense.
* It makes sure that pressing escape while a notable trait popover is
open focuses the popover's toggle button, instead of leaving nothing
focused, since that makes more sense with keyboard navigation. Clicking
the settings, help, or sidebar buttons, however, will not focus the
notable trait popover toggle button.
* It ensures that notable trait and settings popovers are exclusive
with the mobile sidebar. Nothing should ever overlap a popover, and
there should never be more than one popover open at once.
2022-11-26 16:52:58 +00:00
|
|
|
|
*/
|
2022-11-26 21:32:57 +00:00
|
|
|
|
window.hideAllModals = function(switchFocus) {
|
rustdoc: improve popover focus handling JS
This commit fixes a few inconsistencies and erratic behavior from the
notable traits, settings, and sidebar popups:
* It makes it so that pressing Escape closes the mobile sidebar.
This is a bit difficult to do on iPhone, but on other setups like
desktop tiling window managers, it's easy and makes sense.
* It makes sure that pressing escape while a notable trait popover is
open focuses the popover's toggle button, instead of leaving nothing
focused, since that makes more sense with keyboard navigation. Clicking
the settings, help, or sidebar buttons, however, will not focus the
notable trait popover toggle button.
* It ensures that notable trait and settings popovers are exclusive
with the mobile sidebar. Nothing should ever overlap a popover, and
there should never be more than one popover open at once.
2022-11-26 16:52:58 +00:00
|
|
|
|
hideSidebar();
|
|
|
|
|
window.hidePopoverMenus();
|
2023-01-26 20:32:33 +00:00
|
|
|
|
hideTooltip(switchFocus);
|
rustdoc: improve popover focus handling JS
This commit fixes a few inconsistencies and erratic behavior from the
notable traits, settings, and sidebar popups:
* It makes it so that pressing Escape closes the mobile sidebar.
This is a bit difficult to do on iPhone, but on other setups like
desktop tiling window managers, it's easy and makes sense.
* It makes sure that pressing escape while a notable trait popover is
open focuses the popover's toggle button, instead of leaving nothing
focused, since that makes more sense with keyboard navigation. Clicking
the settings, help, or sidebar buttons, however, will not focus the
notable trait popover toggle button.
* It ensures that notable trait and settings popovers are exclusive
with the mobile sidebar. Nothing should ever overlap a popover, and
there should never be more than one popover open at once.
2022-11-26 16:52:58 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-06-22 18:49:26 +00:00
|
|
|
|
/**
|
|
|
|
|
* Hide all the popover menus.
|
|
|
|
|
*/
|
|
|
|
|
window.hidePopoverMenus = function() {
|
2022-10-27 20:36:27 +00:00
|
|
|
|
onEachLazy(document.querySelectorAll(".search-form .popover"), elem => {
|
2022-06-22 18:49:26 +00:00
|
|
|
|
elem.style.display = "none";
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-20 14:28:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the help menu element (not the button).
|
|
|
|
|
*
|
|
|
|
|
* @param {boolean} buildNeeded - If this argument is `false`, the help menu element won't be
|
|
|
|
|
* built if it doesn't exist.
|
|
|
|
|
*
|
|
|
|
|
* @return {HTMLElement}
|
|
|
|
|
*/
|
|
|
|
|
function getHelpMenu(buildNeeded) {
|
|
|
|
|
let menu = getHelpButton().querySelector(".popover");
|
|
|
|
|
if (!menu && buildNeeded) {
|
|
|
|
|
menu = buildHelpMenu();
|
|
|
|
|
}
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the help popup menu.
|
|
|
|
|
*/
|
|
|
|
|
function showHelp() {
|
2023-01-18 18:41:34 +00:00
|
|
|
|
// Prevent `blur` events from being dispatched as a result of closing
|
|
|
|
|
// other modals.
|
|
|
|
|
getHelpButton().querySelector("a").focus();
|
2022-06-20 14:28:52 +00:00
|
|
|
|
const menu = getHelpMenu(true);
|
|
|
|
|
if (menu.style.display === "none") {
|
rustdoc: improve popover focus handling JS
This commit fixes a few inconsistencies and erratic behavior from the
notable traits, settings, and sidebar popups:
* It makes it so that pressing Escape closes the mobile sidebar.
This is a bit difficult to do on iPhone, but on other setups like
desktop tiling window managers, it's easy and makes sense.
* It makes sure that pressing escape while a notable trait popover is
open focuses the popover's toggle button, instead of leaving nothing
focused, since that makes more sense with keyboard navigation. Clicking
the settings, help, or sidebar buttons, however, will not focus the
notable trait popover toggle button.
* It ensures that notable trait and settings popovers are exclusive
with the mobile sidebar. Nothing should ever overlap a popover, and
there should never be more than one popover open at once.
2022-11-26 16:52:58 +00:00
|
|
|
|
window.hideAllModals();
|
2022-06-20 14:28:52 +00:00
|
|
|
|
menu.style.display = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-14 16:48:19 +00:00
|
|
|
|
if (isHelpPage) {
|
|
|
|
|
showHelp();
|
2022-10-16 04:02:57 +00:00
|
|
|
|
document.querySelector(`#${HELP_BUTTON_ID} > a`).addEventListener("click", event => {
|
|
|
|
|
// Already on the help page, make help button a no-op.
|
|
|
|
|
const target = event.target;
|
|
|
|
|
if (target.tagName !== "A" ||
|
|
|
|
|
target.parentElement.id !== HELP_BUTTON_ID ||
|
|
|
|
|
event.ctrlKey ||
|
|
|
|
|
event.altKey ||
|
|
|
|
|
event.metaKey) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
});
|
2022-10-14 16:48:19 +00:00
|
|
|
|
} else {
|
|
|
|
|
document.querySelector(`#${HELP_BUTTON_ID} > a`).addEventListener("click", event => {
|
2022-10-16 04:02:57 +00:00
|
|
|
|
// By default, have help button open docs in a popover.
|
|
|
|
|
// If user clicks with a moderator, though, use default browser behavior,
|
|
|
|
|
// probably opening in a new window or tab.
|
2022-10-14 16:48:19 +00:00
|
|
|
|
const target = event.target;
|
2022-10-15 18:45:27 +00:00
|
|
|
|
if (target.tagName !== "A" ||
|
|
|
|
|
target.parentElement.id !== HELP_BUTTON_ID ||
|
|
|
|
|
event.ctrlKey ||
|
|
|
|
|
event.altKey ||
|
|
|
|
|
event.metaKey) {
|
2022-10-14 16:48:19 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
const menu = getHelpMenu(true);
|
|
|
|
|
const shouldShowHelp = menu.style.display === "none";
|
|
|
|
|
if (shouldShowHelp) {
|
|
|
|
|
showHelp();
|
|
|
|
|
} else {
|
|
|
|
|
window.hidePopoverMenus();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-10-24 22:35:45 +00:00
|
|
|
|
|
2022-06-15 06:25:51 +00:00
|
|
|
|
setMobileTopbar();
|
|
|
|
|
addSidebarItems();
|
|
|
|
|
addSidebarCrates();
|
2019-12-15 20:27:25 +00:00
|
|
|
|
onHashChange(null);
|
2021-05-09 18:21:38 +00:00
|
|
|
|
window.addEventListener("hashchange", onHashChange);
|
2021-04-13 07:35:36 +00:00
|
|
|
|
searchState.setup();
|
2014-01-15 01:09:50 +00:00
|
|
|
|
}());
|
2021-03-31 20:13:47 +00:00
|
|
|
|
|
2022-05-25 11:55:09 +00:00
|
|
|
|
(function() {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
let reset_button_timeout = null;
|
2021-04-30 09:42:07 +00:00
|
|
|
|
|
2023-01-27 21:23:28 +00:00
|
|
|
|
const but = document.getElementById("copy-path");
|
|
|
|
|
if (!but) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
but.onclick = () => {
|
2022-04-25 12:23:17 +00:00
|
|
|
|
const parent = but.parentElement;
|
|
|
|
|
const path = [];
|
2021-04-30 09:42:07 +00:00
|
|
|
|
|
2022-05-03 04:03:17 +00:00
|
|
|
|
onEach(parent.childNodes, child => {
|
2022-05-07 18:18:23 +00:00
|
|
|
|
if (child.tagName === "A") {
|
2021-04-30 09:42:07 +00:00
|
|
|
|
path.push(child.textContent);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-05-07 18:18:23 +00:00
|
|
|
|
const el = document.createElement("textarea");
|
|
|
|
|
el.value = path.join("::");
|
|
|
|
|
el.setAttribute("readonly", "");
|
2021-04-30 09:42:07 +00:00
|
|
|
|
// To not make it appear on the screen.
|
2022-05-07 18:18:23 +00:00
|
|
|
|
el.style.position = "absolute";
|
|
|
|
|
el.style.left = "-9999px";
|
2021-04-30 08:18:14 +00:00
|
|
|
|
|
2021-04-30 09:42:07 +00:00
|
|
|
|
document.body.appendChild(el);
|
|
|
|
|
el.select();
|
2022-05-07 18:18:23 +00:00
|
|
|
|
document.execCommand("copy");
|
2021-04-30 09:42:07 +00:00
|
|
|
|
document.body.removeChild(el);
|
2021-03-31 20:13:47 +00:00
|
|
|
|
|
2021-05-09 18:41:24 +00:00
|
|
|
|
// There is always one children, but multiple childNodes.
|
2022-05-07 18:18:23 +00:00
|
|
|
|
but.children[0].style.display = "none";
|
2021-05-09 18:41:24 +00:00
|
|
|
|
|
2022-04-25 12:23:17 +00:00
|
|
|
|
let tmp;
|
2021-05-09 18:41:24 +00:00
|
|
|
|
if (but.childNodes.length < 2) {
|
2022-05-07 18:18:23 +00:00
|
|
|
|
tmp = document.createTextNode("✓");
|
2021-05-09 18:41:24 +00:00
|
|
|
|
but.appendChild(tmp);
|
|
|
|
|
} else {
|
2022-05-03 04:03:17 +00:00
|
|
|
|
onEachLazy(but.childNodes, e => {
|
2021-05-09 18:41:24 +00:00
|
|
|
|
if (e.nodeType === Node.TEXT_NODE) {
|
|
|
|
|
tmp = e;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-05-07 18:18:23 +00:00
|
|
|
|
tmp.textContent = "✓";
|
2021-05-09 18:41:24 +00:00
|
|
|
|
}
|
2021-04-30 09:42:07 +00:00
|
|
|
|
|
|
|
|
|
if (reset_button_timeout !== null) {
|
|
|
|
|
window.clearTimeout(reset_button_timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reset_button() {
|
2022-05-07 18:18:23 +00:00
|
|
|
|
tmp.textContent = "";
|
2021-04-30 09:42:07 +00:00
|
|
|
|
reset_button_timeout = null;
|
2021-05-09 18:41:24 +00:00
|
|
|
|
but.children[0].style.display = "";
|
2021-03-31 20:13:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-30 09:42:07 +00:00
|
|
|
|
reset_button_timeout = window.setTimeout(reset_button, 1000);
|
2021-04-30 10:06:15 +00:00
|
|
|
|
};
|
2021-04-30 09:42:07 +00:00
|
|
|
|
}());
|