From b406daccca53af4600c42bcba50ff1c14f752de0 Mon Sep 17 00:00:00 2001 From: Matthias Redmann Date: Tue, 6 Jun 2017 10:52:39 +0200 Subject: [PATCH 1/2] add exitMenu delay --- jquery.menu-aim.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/jquery.menu-aim.js b/jquery.menu-aim.js index 0c32941..7f1169f 100644 --- a/jquery.menu-aim.js +++ b/jquery.menu-aim.js @@ -95,7 +95,8 @@ exit: $.noop, activate: $.noop, deactivate: $.noop, - exitMenu: $.noop + exitMenu: $.noop, + exitDelay: 0 }, opts); var MOUSE_LOCS_TRACKED = 3, // number of past mouse locations to track @@ -120,15 +121,16 @@ clearTimeout(timeoutId); } - // If exitMenu is supplied and returns true, deactivate the - // currently active row on menu exit. - if (options.exitMenu(this)) { - if (activeRow) { - options.deactivate(activeRow); + window.setTimeout(function () { + // If exitMenu is supplied and returns true, deactivate the + // currently active row on menu exit. + if (options.exitMenu(this)) { + if (activeRow) { + options.deactivate(activeRow); + } + activeRow = null; } - - activeRow = null; - } + }, options.exitDelay); }; /** From c8736b0c59d9017e6af050df4fd07427938058cd Mon Sep 17 00:00:00 2001 From: Matthias Redmann Date: Tue, 6 Jun 2017 11:36:33 +0200 Subject: [PATCH 2/2] Do not close the submenu if the cursor come back within exitMenu-delay --- jquery.menu-aim.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jquery.menu-aim.js b/jquery.menu-aim.js index 7f1169f..78fab4b 100644 --- a/jquery.menu-aim.js +++ b/jquery.menu-aim.js @@ -102,6 +102,8 @@ var MOUSE_LOCS_TRACKED = 3, // number of past mouse locations to track DELAY = 300; // ms delay when user appears to be entering submenu + var mouseleaveTimer; + /** * Keep track of the last few locations of the mouse. */ @@ -121,7 +123,7 @@ clearTimeout(timeoutId); } - window.setTimeout(function () { + mouseleaveTimer = window.setTimeout(function () { // If exitMenu is supplied and returns true, deactivate the // currently active row on menu exit. if (options.exitMenu(this)) { @@ -142,6 +144,8 @@ clearTimeout(timeoutId); } + window.clearTimeout(mouseleaveTimer); + options.enter(this); possiblyActivate(this); },