Add a dedicated background_click function.

This commit is contained in:
voussoir 2022-03-08 17:02:50 -08:00
parent 635bf27c1e
commit da0e6a59f7
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
2 changed files with 15 additions and 2 deletions

View file

@ -250,7 +250,8 @@ function create(photo, view)
photo_card.appendChild(toolbutton);
const photo_card_tools = document.createElement("div");
photo_card_tools.className = "photo_card_tools";
photo_card_tools.classList.add("photo_card_tools");
photo_card_tools.classList.add("contextmenu");
photo_card_tools.onclick = "event.stopPropagation(); return;";
photo_card.appendChild(photo_card_tools);

View file

@ -1,5 +1,17 @@
const contextmenus = {};
contextmenus.background_click =
function background_click(event)
{
const contextmenu = event.target.closest(".contextmenu");
if (! contextmenu)
{
contextmenus.hide_open_menus();
return;
}
event.stopPropagation();
}
contextmenus.hide_open_menus =
function hide_open_menus()
{
@ -32,6 +44,6 @@ function show_menu(event, menu)
function on_pageload()
{
document.body.addEventListener("click", contextmenus.hide_open_menus);
document.body.addEventListener("click", contextmenus.background_click);
}
document.addEventListener("DOMContentLoaded", on_pageload);