Merge all popover hide functions into one

This commit is contained in:
Guillaume Gomez 2022-06-22 20:49:26 +02:00
parent 3eb9e1a7ae
commit e4b2b41290
2 changed files with 18 additions and 27 deletions

View File

@ -137,10 +137,6 @@ function getNakedUrl() {
return window.location.href.split("?")[0].split("#")[0];
}
window.hideSettings = () => {
// Does nothing by default.
};
/**
* This function inserts `newNode` after `referenceNode`. It doesn't work if `referenceNode`
* doesn't have a parent node.
@ -413,8 +409,7 @@ function loadCss(cssFileName) {
}
ev.preventDefault();
searchState.defocus();
window.hideSettings();
hideHelp();
window.hidePopoverMenus();
}
const disableShortcuts = getSettingValue("disable-shortcuts") === "true";
@ -824,7 +819,7 @@ function loadCss(cssFileName) {
}
function helpBlurHandler(event) {
blurHandler(event, getHelpButton(), hideHelp);
blurHandler(event, getHelpButton(), window.hidePopoverMenus);
}
function buildHelpMenu() {
@ -900,6 +895,15 @@ function loadCss(cssFileName) {
return container;
}
/**
* Hide all the popover menus.
*/
window.hidePopoverMenus = function() {
onEachLazy(document.querySelectorAll(".search-container .popover"), elem => {
elem.style.display = "none";
});
};
/**
* Returns the help menu element (not the button).
*
@ -926,25 +930,14 @@ function loadCss(cssFileName) {
}
}
/**
* Hide the help popup menu.
*/
function hideHelp() {
const menu = getHelpMenu(false);
if (menu && menu.style.display !== "none") {
menu.style.display = "none";
}
}
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);
if (menu.style.display !== "none") {
hideHelp();
} else {
const shouldShowHelp = menu.style.display === "none";
if (shouldShowHelp) {
showHelp();
}
});

View File

@ -228,7 +228,7 @@
}
function settingsBlurHandler(event) {
blurHandler(event, getSettingsButton(), window.hideSettings);
blurHandler(event, getSettingsButton(), window.hidePopoverMenus);
}
if (isSettingsPage) {
@ -240,17 +240,15 @@
// We replace the existing "onclick" callback.
const settingsButton = getSettingsButton();
const settingsMenu = document.getElementById("settings");
window.hideSettings = function() {
settingsMenu.style.display = "none";
};
settingsButton.onclick = function(event) {
if (elemIsInParent(event.target, settingsMenu)) {
return;
}
event.preventDefault();
if (settingsMenu.style.display !== "none") {
window.hideSettings();
} else {
const shouldDisplaySettings = settingsMenu.style.display === "none";
window.hidePopoverMenus();
if (shouldDisplaySettings) {
displaySettings();
}
};