From 10421c0ffc0f0c029a75bd6e1d4702f976bfbd61 Mon Sep 17 00:00:00 2001 From: Agahnim Date: Mon, 11 May 2026 15:48:47 +0200 Subject: [PATCH] context menu: fix go back removing context menu ? --- static/contextmenu.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/static/contextmenu.js b/static/contextmenu.js index 3daeb4f..8171e6e 100644 --- a/static/contextmenu.js +++ b/static/contextmenu.js @@ -1,25 +1,33 @@ (function() { - if (window._contextMenuInitialized) return; - window._contextMenuInitialized = true; - const menu = document.createElement('helo'); + menu.innerHTML = ` - - - + + + `; + menu.style.display = 'none'; - document.body.appendChild(menu); + + function ensureMenu() { + if (!document.body.contains(menu)) { + document.body.appendChild(menu); + } + } const showMenu = (x, y) => { + ensureMenu(); + 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`; } @@ -32,12 +40,14 @@ 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(); }); -})(); + document.body.addEventListener('htmx:historyRestore', ensureMenu); +})(); \ No newline at end of file