1
Fork 0

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]; 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` * This function inserts `newNode` after `referenceNode`. It doesn't work if `referenceNode`
* doesn't have a parent node. * doesn't have a parent node.
@ -413,8 +409,7 @@ function loadCss(cssFileName) {
} }
ev.preventDefault(); ev.preventDefault();
searchState.defocus(); searchState.defocus();
window.hideSettings(); window.hidePopoverMenus();
hideHelp();
} }
const disableShortcuts = getSettingValue("disable-shortcuts") === "true"; const disableShortcuts = getSettingValue("disable-shortcuts") === "true";
@ -824,7 +819,7 @@ function loadCss(cssFileName) {
} }
function helpBlurHandler(event) { function helpBlurHandler(event) {
blurHandler(event, getHelpButton(), hideHelp); blurHandler(event, getHelpButton(), window.hidePopoverMenus);
} }
function buildHelpMenu() { function buildHelpMenu() {
@ -900,6 +895,15 @@ function loadCss(cssFileName) {
return container; 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). * 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 => { document.querySelector(`#${HELP_BUTTON_ID} > button`).addEventListener("click", event => {
const target = event.target; const target = event.target;
if (target.tagName !== "BUTTON" || target.parentElement.id !== HELP_BUTTON_ID) { if (target.tagName !== "BUTTON" || target.parentElement.id !== HELP_BUTTON_ID) {
return; return;
} }
const menu = getHelpMenu(true); const menu = getHelpMenu(true);
if (menu.style.display !== "none") { const shouldShowHelp = menu.style.display === "none";
hideHelp(); if (shouldShowHelp) {
} else {
showHelp(); showHelp();
} }
}); });

View file

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