From da8351dc82d111ff8193676e6dad9fff7b570b9e Mon Sep 17 00:00:00 2001 From: vineethvk11 Date: Fri, 22 Mar 2024 01:34:17 +0530 Subject: [PATCH] handling context submenus on mobile devices --- src/UI/UIContextMenu.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/UI/UIContextMenu.js b/src/UI/UIContextMenu.js index 20491ed3..f05f89c2 100644 --- a/src/UI/UIContextMenu.js +++ b/src/UI/UIContextMenu.js @@ -185,6 +185,17 @@ function UIContextMenu(options){ if($(`.context-menu[data-id="${menu_id}-${$(e).attr('data-action')}"]`).length === 0){ // close other submenus $(`.context-menu[parent-element-id="${menu_id}"]`).remove(); + + // Calculate the position for the submenu + let submenu_x_pos, submenu_y_pos; + if (isMobile.phone || isMobile.tablet) { + submenu_y_pos = y_pos; + submenu_x_pos = x_pos; + } else { + submenu_y_pos = item_rect_box.top - 5; + submenu_x_pos = x_pos + item_rect_box.width + 15; + } + // open the new submenu UIContextMenu({ items: options.items[parseInt($(e).attr('data-action'))].items, @@ -192,8 +203,8 @@ function UIContextMenu(options){ is_submenu: true, id: menu_id + '-' + $(e).attr('data-action'), position:{ - top: item_rect_box.top - 5, - left: x_pos + item_rect_box.width + 15, + top: submenu_y_pos, + left: submenu_x_pos, } }) }