Skip to content

Commit e4b2b41

Browse files
Merge all popover hide functions into one
1 parent 3eb9e1a commit e4b2b41

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

src/librustdoc/html/static/js/main.js

+13-20
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ function getNakedUrl() {
137137
return window.location.href.split("?")[0].split("#")[0];
138138
}
139139

140-
window.hideSettings = () => {
141-
// Does nothing by default.
142-
};
143-
144140
/**
145141
* This function inserts `newNode` after `referenceNode`. It doesn't work if `referenceNode`
146142
* doesn't have a parent node.
@@ -413,8 +409,7 @@ function loadCss(cssFileName) {
413409
}
414410
ev.preventDefault();
415411
searchState.defocus();
416-
window.hideSettings();
417-
hideHelp();
412+
window.hidePopoverMenus();
418413
}
419414

420415
const disableShortcuts = getSettingValue("disable-shortcuts") === "true";
@@ -824,7 +819,7 @@ function loadCss(cssFileName) {
824819
}
825820

826821
function helpBlurHandler(event) {
827-
blurHandler(event, getHelpButton(), hideHelp);
822+
blurHandler(event, getHelpButton(), window.hidePopoverMenus);
828823
}
829824

830825
function buildHelpMenu() {
@@ -900,6 +895,15 @@ function loadCss(cssFileName) {
900895
return container;
901896
}
902897

898+
/**
899+
* Hide all the popover menus.
900+
*/
901+
window.hidePopoverMenus = function() {
902+
onEachLazy(document.querySelectorAll(".search-container .popover"), elem => {
903+
elem.style.display = "none";
904+
});
905+
};
906+
903907
/**
904908
* Returns the help menu element (not the button).
905909
*
@@ -926,25 +930,14 @@ function loadCss(cssFileName) {
926930
}
927931
}
928932

929-
/**
930-
* Hide the help popup menu.
931-
*/
932-
function hideHelp() {
933-
const menu = getHelpMenu(false);
934-
if (menu && menu.style.display !== "none") {
935-
menu.style.display = "none";
936-
}
937-
}
938-
939933
document.querySelector(`#${HELP_BUTTON_ID} > button`).addEventListener("click", event => {
940934
const target = event.target;
941935
if (target.tagName !== "BUTTON" || target.parentElement.id !== HELP_BUTTON_ID) {
942936
return;
943937
}
944938
const menu = getHelpMenu(true);
945-
if (menu.style.display !== "none") {
946-
hideHelp();
947-
} else {
939+
const shouldShowHelp = menu.style.display === "none";
940+
if (shouldShowHelp) {
948941
showHelp();
949942
}
950943
});

src/librustdoc/html/static/js/settings.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
}
229229

230230
function settingsBlurHandler(event) {
231-
blurHandler(event, getSettingsButton(), window.hideSettings);
231+
blurHandler(event, getSettingsButton(), window.hidePopoverMenus);
232232
}
233233

234234
if (isSettingsPage) {
@@ -240,17 +240,15 @@
240240
// We replace the existing "onclick" callback.
241241
const settingsButton = getSettingsButton();
242242
const settingsMenu = document.getElementById("settings");
243-
window.hideSettings = function() {
244-
settingsMenu.style.display = "none";
245-
};
246243
settingsButton.onclick = function(event) {
247244
if (elemIsInParent(event.target, settingsMenu)) {
248245
return;
249246
}
250247
event.preventDefault();
251-
if (settingsMenu.style.display !== "none") {
252-
window.hideSettings();
253-
} else {
248+
const shouldDisplaySettings = settingsMenu.style.display === "none";
249+
250+
window.hidePopoverMenus();
251+
if (shouldDisplaySettings) {
254252
displaySettings();
255253
}
256254
};

0 commit comments

Comments
 (0)