rustdoc: make the help button a link to a page
This allows you to open the help section in a new browser tab, which is a pretty reasonable thing to want for a documentation page.
This commit is contained in:
parent
ee1c3b385b
commit
ae4ad9adb6
10 changed files with 127 additions and 46 deletions
|
@ -192,6 +192,8 @@ function loadCss(cssFileName) {
|
|||
}
|
||||
|
||||
(function() {
|
||||
const isHelpPage = window.location.pathname.endsWith("/help.html");
|
||||
|
||||
function loadScript(url) {
|
||||
const script = document.createElement("script");
|
||||
script.src = url;
|
||||
|
@ -873,7 +875,10 @@ function loadCss(cssFileName) {
|
|||
rustdoc_version.appendChild(rustdoc_version_code);
|
||||
|
||||
const container = document.createElement("div");
|
||||
container.className = "popover";
|
||||
if (!isHelpPage) {
|
||||
container.className = "popover";
|
||||
}
|
||||
container.id = "help";
|
||||
container.style.display = "none";
|
||||
|
||||
const side_by_side = document.createElement("div");
|
||||
|
@ -885,15 +890,22 @@ function loadCss(cssFileName) {
|
|||
container.appendChild(side_by_side);
|
||||
container.appendChild(rustdoc_version);
|
||||
|
||||
const help_button = getHelpButton();
|
||||
help_button.appendChild(container);
|
||||
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);
|
||||
|
||||
container.onblur = helpBlurHandler;
|
||||
container.onclick = event => {
|
||||
event.preventDefault();
|
||||
};
|
||||
help_button.onblur = helpBlurHandler;
|
||||
help_button.children[0].onblur = helpBlurHandler;
|
||||
container.onblur = helpBlurHandler;
|
||||
container.onclick = event => {
|
||||
event.preventDefault();
|
||||
};
|
||||
help_button.onblur = helpBlurHandler;
|
||||
help_button.children[0].onblur = helpBlurHandler;
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
@ -934,19 +946,24 @@ function loadCss(cssFileName) {
|
|||
}
|
||||
}
|
||||
|
||||
document.querySelector(`#${HELP_BUTTON_ID} > button`).addEventListener("click", event => {
|
||||
const target = event.target;
|
||||
if (target.tagName !== "BUTTON" || target.parentElement.id !== HELP_BUTTON_ID) {
|
||||
return;
|
||||
}
|
||||
const menu = getHelpMenu(true);
|
||||
const shouldShowHelp = menu.style.display === "none";
|
||||
if (shouldShowHelp) {
|
||||
showHelp();
|
||||
} else {
|
||||
window.hidePopoverMenus();
|
||||
}
|
||||
});
|
||||
if (isHelpPage) {
|
||||
showHelp();
|
||||
} else {
|
||||
document.querySelector(`#${HELP_BUTTON_ID} > a`).addEventListener("click", event => {
|
||||
const target = event.target;
|
||||
if (target.tagName !== "A" || target.parentElement.id !== HELP_BUTTON_ID) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
const menu = getHelpMenu(true);
|
||||
const shouldShowHelp = menu.style.display === "none";
|
||||
if (shouldShowHelp) {
|
||||
showHelp();
|
||||
} else {
|
||||
window.hidePopoverMenus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setMobileTopbar();
|
||||
addSidebarItems();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue