From e6c17de6d4e4ab414c763444622544ea140ba169 Mon Sep 17 00:00:00 2001 From: "Fei.TH" Date: Mon, 31 Mar 2014 16:44:26 -0500 Subject: [PATCH] improvement for getting correct submenu's height added an option to set submenu's max height so it gets the correct height, rather than always using menu's height (in some cases, menu's height is less than submenu's); added leaveMenuTimeoutId, for not deactivating submenu if mouse is moving to submenu but has exited menu. --- jquery.menu-aim.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/jquery.menu-aim.js b/jquery.menu-aim.js index 0c32941..9dcc356 100644 --- a/jquery.menu-aim.js +++ b/jquery.menu-aim.js @@ -86,10 +86,12 @@ mouseLocs = [], lastDelayLoc = null, timeoutId = null, + leaveMenuTimeoutId = null, options = $.extend({ rowSelector: "> li", submenuSelector: "*", submenuDirection: "right", + submenuMaxHeight: $(this).outerHeight(), // submenu maximum height tolerance: 75, // bigger = more forgivey when entering submenu enter: $.noop, exit: $.noop, @@ -116,6 +118,13 @@ * Cancel possible row activations when leaving the menu entirely */ var mouseleaveMenu = function() { + // don't deactivate if mouse is moving to submenu, delay and check again later + var delay = activationDelay(); + if(delay){ + leaveMenuTimeoutId = setTimeout(function() { + mouseleaveMenu(); + }, delay); + } else { if (timeoutId) { clearTimeout(timeoutId); } @@ -127,8 +136,12 @@ options.deactivate(activeRow); } - activeRow = null; + activeRow = null; + } + } + + }; /** @@ -139,6 +152,9 @@ // Cancel any previous activation delays clearTimeout(timeoutId); } + if(leaveMenuTimeoutId) { + clearTimeout(leaveMenuTimeoutId); + } options.enter(this); possiblyActivate(this); @@ -208,7 +224,7 @@ y: offset.top - options.tolerance }, upperRight = { - x: offset.left + $menu.outerWidth(), + x: offset.left + $menu.find(options.rowSelector).outerWidth(), y: upperLeft.y }, lowerLeft = { @@ -216,8 +232,8 @@ y: offset.top + $menu.outerHeight() + options.tolerance }, lowerRight = { - x: offset.left + $menu.outerWidth(), - y: lowerLeft.y + x: upperRight.x, + y: offset.top + options.submenuMaxHeight + options.tolerance }, loc = mouseLocs[mouseLocs.length - 1], prevLoc = mouseLocs[0];