The code of Accessible-Mega-Menu doesn't use the .hover()
function, but it does have both a _mouseOverHandler
and _mouseOutHandler
. The following is untested, but I'll try to include the theory and explanation.
Add a new variable to hold a timer, I'll use navTimer
, into scope. Place this such that both _mouseOverHandler
and _mouseOutHandler
can see it.
In _mouseOverHandler
wrap the operative parts in window.setTimeout
:
navTimer = window.setTimeout(function(){
$(event.target)
.addClass(this.settings.hoverClass);
_togglePanel.call(this, event);
if ($(event.target).is(':tabbable')) {
$('html').on('keydown.accessible-megamenu', $.proxy(_keyDownHandler, event.target));
}
}, 300);
We don't modify the call to clearTimeout(this.mouseTimeoutID);
because we want that to trigger on the mouse activity as it is a separate timer.
Then in _mouseOutHandler
add the line window.clearTimeout(navTimer);
This has the effect that when you mouse in it starts a countdown of 300 milliseconds. If you mouse out it clears this timer. If you stay in the mouse in area for the full time then the events will trigger.
Step by Step
- open your copy of
jquery-accessibleMegaMenu.js
- at line 151 insert
this.navTimer = null;
- after line 650
clearTimeout(this.mouseTimeoutID);
insert this.navTimer = setTimeout(function(){
- before line 658
});
insert }, 300);
- after line 669 add
clearTimeout(this.navTimer);
These steps are a little more closely tied to the syntax and style that the file was using than the instructions above, but it is still untested.
Modified function
This was the intended edit:
_mouseOverHandler = function (event) {
clearTimeout(this.mouseTimeoutID);
this.navTimer = setTimeout(function () {
$(event.target).addClass(this.settings.hoverClass);
_togglePanel.call(this, event);
if ($(event.target).is(':tabbable')) {
$('html').on('keydown.accessible-megamenu', $.proxy(_keyDownHandler, event.target));
}
}, 300);
};