From 54a3e46b3db87ab8529b2ec4297bc9b37e838132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=9D=D0=B0=D0=B4=D0=B5?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Fri, 5 Dec 2025 17:01:33 +0300 Subject: [PATCH] fix: prevent calendar context menu from going off-screen - Added smart positioning logic to keep menu within viewport bounds - Menu now adjusts horizontal position if it would overflow right edge - Menu moves above cursor if it would overflow bottom edge - Changed position from absolute to fixed for consistent behavior - Added 10px safety margins from all edges - Menu is temporarily hidden during position calculation for smooth appearance --- .../static/js/components/calendarWidget.js | 41 +++++++++++++++++-- .../components/calendar_context_menu.html | 2 +- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/backend/static/js/components/calendarWidget.js b/backend/static/js/components/calendarWidget.js index 68b336f2..3b12578e 100644 --- a/backend/static/js/components/calendarWidget.js +++ b/backend/static/js/components/calendarWidget.js @@ -741,10 +741,45 @@ export function initCalendarWidget(options = {}) { divider.classList.toggle('d-none', !perms.can_delete); } - // Позиционируем меню - contextMenu.style.left = x + 'px'; - contextMenu.style.top = y + 'px'; + // Сначала показываем меню для получения его размеров contextMenu.style.display = 'block'; + contextMenu.style.visibility = 'hidden'; + + // Получаем размеры меню и окна + const menuRect = contextMenu.getBoundingClientRect(); + const menuWidth = menuRect.width; + const menuHeight = menuRect.height; + const windowWidth = window.innerWidth; + const windowHeight = window.innerHeight; + + // Корректируем позицию по горизонтали + let finalX = x; + if (x + menuWidth > windowWidth) { + // Меню выходит за правый край - сдвигаем влево + finalX = windowWidth - menuWidth - 10; // 10px отступ от края + } + if (finalX < 10) { + finalX = 10; // Минимальный отступ слева + } + + // Корректируем позицию по вертикали + let finalY = y; + if (y + menuHeight > windowHeight) { + // Меню выходит за нижний край - показываем выше курсора + finalY = y - menuHeight; + // Если и сверху не помещается, прижимаем к нижнему краю + if (finalY < 10) { + finalY = windowHeight - menuHeight - 10; + } + } + if (finalY < 10) { + finalY = 10; // Минимальный отступ сверху + } + + // Применяем скорректированную позицию + contextMenu.style.left = finalX + 'px'; + contextMenu.style.top = finalY + 'px'; + contextMenu.style.visibility = 'visible'; }); } diff --git a/backend/templates/includes/components/calendar_context_menu.html b/backend/templates/includes/components/calendar_context_menu.html index ade972f0..0167295c 100644 --- a/backend/templates/includes/components/calendar_context_menu.html +++ b/backend/templates/includes/components/calendar_context_menu.html @@ -1,5 +1,5 @@ {# Контекстное меню для действий с событиями календаря #} -