global: add custom context menu, fix js not working when swapping through htmx

This commit is contained in:
Agahnim 2026-03-24 16:33:32 +01:00
parent d5e6c8a82c
commit b483e5dc12
5 changed files with 89 additions and 20 deletions

BIN
static/assets/gifs/helo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

42
static/contextmenu.js Normal file
View file

@ -0,0 +1,42 @@
(function() {
if (window._contextMenuInitialized) return;
window._contextMenuInitialized = true;
const menu = document.createElement('div');
menu.className = 'context-menu';
menu.innerHTML = `
<img src="/static/assets/gifs/helo.gif"/>
`;
menu.style.display = 'none';
document.body.appendChild(menu);
const showMenu = (x, y) => {
menu.style.display = 'block';
menu.style.left = `${x}px`;
menu.style.top = `${y}px`;
const rect = menu.getBoundingClientRect();
if (x + rect.width > window.innerWidth) {
menu.style.left = `${window.innerWidth - rect.width - 10}px`;
}
if (y + rect.height > window.innerHeight) {
menu.style.top = `${window.innerHeight - rect.height - 10}px`;
}
};
const hideMenu = () => {
menu.style.display = 'none';
};
document.addEventListener('contextmenu', (e) => {
e.preventDefault();
showMenu(e.clientX, e.clientY);
}, false);
document.addEventListener('click', hideMenu);
document.addEventListener('scroll', hideMenu);
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') hideMenu();
});
})();

View file

@ -923,4 +923,23 @@ mini-player {
width: 90%;
}
}
}
/* Context Menu */
.context-menu {
position: fixed;
background: var(--win-bg-grey);
border: 2px solid;
border-color: #ffffff #808080 #808080 #ffffff;
box-shadow: 2px 2px 0 #000;
border-radius: 4px;
padding: 0.5rem 0;
min-width: 150px;
z-index: 9999;
font-family: 'VT323', monospace;
font-size: 1.2rem;
img {
width: 10svw;
}
}