From 7385de8cf8ca0d5cdcd8c4f65a35af6194d37ec3 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 9 Nov 2023 23:55:14 +0200 Subject: [PATCH] Adjust position if context menu is outside of viewport --- public/scripts/BulkEditOverlay.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/public/scripts/BulkEditOverlay.js b/public/scripts/BulkEditOverlay.js index bf9f1ddfd..bdbaf3189 100644 --- a/public/scripts/BulkEditOverlay.js +++ b/public/scripts/BulkEditOverlay.js @@ -159,6 +159,15 @@ class CharacterContextMenu { contextMenu.style.top = `${positionY}px`; document.getElementById(BulkEditOverlay.contextMenuId).classList.remove('hidden'); + + // Adjust position if context menu is outside of viewport + const boundingRect = contextMenu.getBoundingClientRect(); + if (boundingRect.right > window.innerWidth) { + contextMenu.style.left = `${positionX - (boundingRect.right - window.innerWidth)}px`; + } + if (boundingRect.bottom > window.innerHeight) { + contextMenu.style.top = `${positionY - (boundingRect.bottom - window.innerHeight)}px`; + } } /** @@ -378,7 +387,9 @@ class BulkEditOverlay { elements.forEach(element => element.addEventListener('dragend', this.handleLongPressEnd)); elements.forEach(element => element.addEventListener('touchmove', this.handleLongPressEnd)); - this.container.addEventListener('click', this.handleCancelClick); + // Cohee: It only triggers when clicking on a margin between the elements? + // Feel free to fix or remove this, I'm not sure how to. + //this.container.addEventListener('click', this.handleCancelClick); } /**