// Local js definitions:
/* global addClass, getCurrentValue, hasClass */
/* global onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */
+/* global hideThemeButtonState, showThemeButtonState */
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position) {
return document.getElementById("search");
}
+function getThemesElement() {
+ return document.getElementById("theme-choices");
+}
+
+function getThemePickerElement() {
+ return document.getElementById("theme-picker");
+}
+
// Sets the focus on the search bar at the top of the page
function focusSearchBar() {
getSearchInput().focus();
"derive",
"traitalias"];
- var disableShortcuts = getCurrentValue("rustdoc-disable-shortcuts") === "true";
+ var disableShortcuts = getSettingValue("disable-shortcuts") === "true";
var search_input = getSearchInput();
var searchTimeout = null;
var toggleAllDocsId = "toggle-all-docs";
var mouseMovedAfterSearch = true;
var titleBeforeSearch = document.title;
+ var searchTitle = null;
function clearInputTimeout() {
if (searchTimeout !== null) {
sidebar.appendChild(div);
}
}
- var themePickers = document.getElementsByClassName("theme-picker");
- if (themePickers && themePickers.length > 0) {
- themePickers[0].style.display = "none";
- }
}
function hideSidebar() {
filler.remove();
}
document.getElementsByTagName("body")[0].style.marginTop = "";
- var themePickers = document.getElementsByClassName("theme-picker");
- if (themePickers && themePickers.length > 0) {
- themePickers[0].style.display = null;
- }
}
function showSearchResults(search) {
addClass(main, "hidden");
removeClass(search, "hidden");
mouseMovedAfterSearch = false;
+ document.title = searchTitle;
}
function hideSearchResults(search) {
}
addClass(search, "hidden");
removeClass(main, "hidden");
+ document.title = titleBeforeSearch;
}
// used for special search precedence
clearInputTimeout();
ev.preventDefault();
hideSearchResults(search);
- document.title = titleBeforeSearch;
}
defocusSearchBar();
+ hideThemeButtonState();
}
function handleShortcut(ev) {
case "?":
displayHelp(true, ev);
break;
+
+ default:
+ var themePicker = getThemePickerElement();
+ if (themePicker.parentNode.contains(ev.target)) {
+ handleThemeKeyDown(ev);
+ }
+ }
+ }
+ }
+
+ function handleThemeKeyDown(ev) {
+ var active = document.activeElement;
+ var themes = getThemesElement();
+ switch (getVirtualKey(ev)) {
+ case "ArrowUp":
+ ev.preventDefault();
+ if (active.previousElementSibling && ev.target.id !== "theme-picker") {
+ active.previousElementSibling.focus();
+ } else {
+ showThemeButtonState();
+ themes.lastElementChild.focus();
+ }
+ break;
+ case "ArrowDown":
+ ev.preventDefault();
+ if (active.nextElementSibling && ev.target.id !== "theme-picker") {
+ active.nextElementSibling.focus();
+ } else {
+ showThemeButtonState();
+ themes.firstElementChild.focus();
+ }
+ break;
+ case "Enter":
+ case "Return":
+ case "Space":
+ if (ev.target.id === "theme-picker" && themes.style.display === "none") {
+ ev.preventDefault();
+ showThemeButtonState();
+ themes.firstElementChild.focus();
}
+ break;
+ case "Home":
+ ev.preventDefault();
+ themes.firstElementChild.focus();
+ break;
+ case "End":
+ ev.preventDefault();
+ themes.lastElementChild.focus();
+ break;
+ // The escape key is handled in handleEscape, not here,
+ // so that pressing escape will close the menu even if it isn't focused
}
}
function showResults(results) {
var search = getSearchElement();
if (results.others.length === 1
- && getCurrentValue("rustdoc-go-to-only-result") === "true"
+ && getSettingValue("go-to-only-result") === "true"
// By default, the search DOM element is "empty" (meaning it has no children not
// text content). Once a search has been run, it won't be empty, even if you press
// ESC or empty the search input (which also "cancels" the search).
}
// Update document title to maintain a meaningful browser history
- document.title = "Results for " + query.query + " - Rust";
+ searchTitle = "Results for " + query.query + " - Rust";
// Because searching is incremental by character, only the most
// recent search query is added to the browser history.
function autoCollapse(pageId, collapse) {
if (collapse) {
toggleAllDocs(pageId, true);
- } else if (getCurrentValue("rustdoc-auto-hide-trait-implementations") !== "false") {
+ } else if (getSettingValue("auto-hide-trait-implementations") !== "false") {
var impl_list = document.getElementById("trait-implementations-list");
if (impl_list !== null) {
}
var toggle = createSimpleToggle(false);
- var hideMethodDocs = getCurrentValue("rustdoc-auto-hide-method-docs") === "true";
- var hideImplementors = getCurrentValue("rustdoc-auto-collapse-implementors") !== "false";
+ var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
+ var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false";
var pageId = getPageId();
var func = function(e) {
});
}
}
- var showItemDeclarations = getCurrentValue("rustdoc-auto-hide-" + className);
+ var showItemDeclarations = getSettingValue("auto-hide-" + className);
if (showItemDeclarations === null) {
if (className === "enum" || className === "macro") {
showItemDeclarations = "false";
showItemDeclarations = "true";
} else {
// In case we found an unknown type, we just use the "parent" value.
- showItemDeclarations = getCurrentValue("rustdoc-auto-hide-declarations");
+ showItemDeclarations = getSettingValue("auto-hide-declarations");
}
}
showItemDeclarations = showItemDeclarations === "false";
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
var pageId = getPageId();
- autoCollapse(pageId, getCurrentValue("rustdoc-collapse") === "true");
+ autoCollapse(pageId, getSettingValue("collapse") === "true");
if (pageId !== null) {
expandSection(pageId);
(function() {
// To avoid checking on "rustdoc-item-attributes" value on every loop...
var itemAttributesFunc = function() {};
- if (getCurrentValue("rustdoc-auto-hide-attributes") !== "false") {
+ if (getSettingValue("auto-hide-attributes") !== "false") {
itemAttributesFunc = function(x) {
collapseDocs(x.previousSibling.childNodes[0], "toggle");
};
(function() {
// To avoid checking on "rustdoc-line-numbers" value on every loop...
var lineNumbersFunc = function() {};
- if (getCurrentValue("rustdoc-line-numbers") === "true") {
+ if (getSettingValue("line-numbers") === "true") {
lineNumbersFunc = function(x) {
var count = x.textContent.split("\n").length;
var elems = [];
"",
"?search=" + encodeURIComponent(search_input.value));
}
+ document.title = searchTitle;
}
}
}
return 0;
});
- var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
+ var savedCrate = getSettingValue("saved-filter-crate");
for (var i = 0; i < crates_text.length; ++i) {
var option = document.createElement("option");
option.value = crates_text[i];