Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions jquery.menu-aim.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
* https://github.com/kamens/jQuery-menu-aim
*/
(function($) {
var mouseLocs = [],
MOUSE_LOCS_TRACKED = 3, // number of past mouse locations to track
DELAY = 300; // ms delay when user appears to be entering submenu;

$.fn.menuAim = function(opts) {
// Initialize menu-aim for all elements in jQuery collection
Expand All @@ -83,7 +86,6 @@
function init(opts) {
var $menu = $(this),
activeRow = null,
mouseLocs = [],
lastDelayLoc = null,
timeoutId = null,
options = $.extend({
Expand All @@ -98,20 +100,6 @@
exitMenu: $.noop
}, opts);

var MOUSE_LOCS_TRACKED = 3, // number of past mouse locations to track
DELAY = 300; // ms delay when user appears to be entering submenu

/**
* Keep track of the last few locations of the mouse.
*/
var mousemoveDocument = function(e) {
mouseLocs.push({x: e.pageX, y: e.pageY});

if (mouseLocs.length > MOUSE_LOCS_TRACKED) {
mouseLocs.shift();
}
};

/**
* Cancel possible row activations when leaving the menu entirely
*/
Expand Down Expand Up @@ -315,9 +303,17 @@
.mouseenter(mouseenterRow)
.mouseleave(mouseleaveRow)
.click(clickRow);
};

$(document).mousemove(mousemoveDocument);
/**
* Keep track of the last few locations of the mouse.
*/
$(document).mousemove(function(e) {
mouseLocs.push({x: e.pageX, y: e.pageY});

};
if (mouseLocs.length > MOUSE_LOCS_TRACKED) {
mouseLocs.shift();
}
});
})(jQuery);