From ab78385833b47aac21c9289ec5ae99264a65013b Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 8 Mar 2022 16:59:56 -0800 Subject: [PATCH] Improve use of clientX instead of offsetX. --- .../etiquette_flask/static/js/contextmenus.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/frontends/etiquette_flask/static/js/contextmenus.js b/frontends/etiquette_flask/static/js/contextmenus.js index d4fb32f..fb2ce86 100644 --- a/frontends/etiquette_flask/static/js/contextmenus.js +++ b/frontends/etiquette_flask/static/js/contextmenus.js @@ -11,18 +11,17 @@ function hide_open_menus() } contextmenus.show_menu = -function show_menu(event, element) +function show_menu(event, menu) { contextmenus.hide_open_menus(); - console.log(event); - element.classList.add("open_contextmenu"); + menu.classList.add("open_contextmenu"); const html = document.documentElement; - const over_right = Math.max(0, event.clientX + element.offsetWidth - html.clientWidth); - const over_bottom = Math.max(0, event.clientY + element.offsetHeight - html.clientHeight); - const left = event.target.offsetLeft + event.offsetX - over_right; - const top = event.target.offsetTop + event.offsetY - over_bottom; - element.style.left = left + "px"; - element.style.top = top + "px"; + const over_right = Math.max(0, event.clientX + menu.offsetWidth - html.clientWidth); + const over_bottom = Math.max(0, event.clientY + menu.offsetHeight - html.clientHeight); + const left = event.pageX - over_right; + const top = event.pageY - over_bottom; + menu.style.left = left + "px"; + menu.style.top = top + "px"; } function on_pageload()