From f88cfc750f80e3f0ccca45662b23fc2bbe3d40d6 Mon Sep 17 00:00:00 2001 From: ayamoosa Date: Fri, 15 Mar 2024 09:15:40 -0700 Subject: [PATCH] need to work on submenuDirection reactivity --- src/UI/UIContextMenu.js | 44 ++++++++++++++++++++++++++++++-------- src/lib/jquery.menu-aim.js | 7 +++--- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/UI/UIContextMenu.js b/src/UI/UIContextMenu.js index bb86aa23..c4852dcc 100644 --- a/src/UI/UIContextMenu.js +++ b/src/UI/UIContextMenu.js @@ -149,23 +149,45 @@ function UIContextMenu(options){ return false; }); + // initialize menuAim plugin $(contextMenu).menuAim({ - submenuDirection: function (e){ - // if submenu will open to the left of menu item - if (e.getBoundingClientRect().left + e.getBoundingClientRect().width > window.innerWidth) { - return 'left'; - } else { - return 'right'; - } + submenuDirection: function(){ + //if this is not a submenu + // if(!options.is_submenu){ + // if submenu is going to be on the right of the main menu + if(x_pos + $(contextMenu).width() + 10 > window.innerWidth){ + console.log('right') + return "right"; + } else { + console.log('left') + return "left"; + } + // } }, activate: function (e) { + + //if submenu opens on right make submenuDirection right + // if($(contextMenu).offset().left + $(contextMenu).width() + 10 > window.innerWidth){ + // $(contextMenu).menuAim({ + // submenuDirection: 'right' + // }); + // } else { + // $(contextMenu).menuAim({ + // submenuDirection: 'left' + // }); + // } + // hover over an item + + + + let item = $(e).closest('.context-menu-item'); console.log('activate', e) // mark other items as inactive $(contextMenu).find('.context-menu-item').removeClass('context-menu-item-active'); // mark this item as active - $(e).addClass('context-menu-item-active'); + $(item).addClass('context-menu-item-active'); // close any submenu that doesn't belong to this item $(`.context-menu[data-parent-id="${menu_id}"]`).remove(); // mark this context menu as active @@ -173,6 +195,7 @@ function UIContextMenu(options){ // activate submenu + // open submenu if applicable if($(e).hasClass('context-menu-item-submenu')){ let item_rect_box = e.getBoundingClientRect(); @@ -193,6 +216,7 @@ function UIContextMenu(options){ }) } } + }, deactivate: function (e) { console.log('deactivate') @@ -284,4 +308,6 @@ window.select_ctxmenu_item = function ($ctxmenu_item){ $($ctxmenu_item).addClass('context-menu-item-active'); } -export default UIContextMenu; \ No newline at end of file +export default UIContextMenu; + + diff --git a/src/lib/jquery.menu-aim.js b/src/lib/jquery.menu-aim.js index 0c2f82ba..47105340 100644 --- a/src/lib/jquery.menu-aim.js +++ b/src/lib/jquery.menu-aim.js @@ -166,6 +166,7 @@ options.deactivate(activeRow); } + options.activate(row); activeRow = row; }; @@ -277,13 +278,13 @@ // corner to decrease over time, as explained above. If the // submenu opens in a different direction, we change our slope // expectations. - if (options.submenuDirection == "left") { + if (options.submenuDirection() == "left") { decreasingCorner = lowerLeft; increasingCorner = upperLeft; - } else if (options.submenuDirection == "below") { + } else if (options.submenuDirection() == "below") { decreasingCorner = lowerRight; increasingCorner = lowerLeft; - } else if (options.submenuDirection == "above") { + } else if (options.submenuDirection() == "above") { decreasingCorner = upperLeft; increasingCorner = upperRight; }