Skip to content

Commit 9b35de8

Browse files
committed
Implemented fixes from other peoples pull requests into one
1 parent 86ac9a0 commit 9b35de8

File tree

2 files changed

+59
-9
lines changed

2 files changed

+59
-9
lines changed

bower.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "jquery.menu-aim",
3+
"version": "1.0.0",
4+
"main": "jquery.menu-aim.js",
5+
"dependencies": {
6+
"jquery": "*"
7+
},
8+
"ignore": [
9+
"example",
10+
"*.png"
11+
]
12+
}

jquery.menu-aim.js

+47-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
22
* menu-aim is a jQuery plugin for dropdown menus that can differentiate
33
* between a user trying hover over a dropdown item vs trying to navigate into
4-
* a submenu's contents.
4+
* a submenu's contents. It will fire events when the user's mouse enters a
5+
* new dropdown item *and* when that item is being intentionally hovered over.
56
*
67
* menu-aim assumes that you have are using a menu with submenus that expand
78
* to the menu's right. It will fire events when the user's mouse enters a new
@@ -95,11 +96,11 @@
9596
exit: $.noop,
9697
activate: $.noop,
9798
deactivate: $.noop,
98-
exitMenu: $.noop
99+
exitMenu: $.noop,
100+
delay: 300
99101
}, opts);
100102

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

104105
/**
105106
* Keep track of the last few locations of the mouse.
@@ -144,6 +145,12 @@
144145
possiblyActivate(this);
145146
},
146147
mouseleaveRow = function() {
148+
149+
/* https://github.com/kamens/jQuery-menu-aim/pull/29/commits - thanks to magwo */
150+
if (timeoutId) {
151+
// Cancel any pending activation
152+
clearTimeout(timeoutId);
153+
}
147154
options.exit(this);
148155
};
149156

@@ -166,6 +173,12 @@
166173
options.deactivate(activeRow);
167174
}
168175

176+
/* https://github.com/kamens/jQuery-menu-aim/pull/33/commits */
177+
if (! $(row).is(options.submenuSelector)){
178+
activeRow = null;
179+
return;
180+
}
181+
169182
options.activate(row);
170183
activeRow = row;
171184
};
@@ -205,15 +218,15 @@
205218
var offset = $menu.offset(),
206219
upperLeft = {
207220
x: offset.left,
208-
y: offset.top - options.tolerance
221+
y: offset.top
209222
},
210223
upperRight = {
211224
x: offset.left + $menu.outerWidth(),
212225
y: upperLeft.y
213226
},
214227
lowerLeft = {
215228
x: offset.left,
216-
y: offset.top + $menu.outerHeight() + options.tolerance
229+
y: offset.top + $menu.outerHeight()
217230
},
218231
lowerRight = {
219232
x: offset.left + $menu.outerWidth(),
@@ -230,6 +243,22 @@
230243
prevLoc = loc;
231244
}
232245

246+
/* https://github.com/kamens/jQuery-menu-aim/pull/22/commits - thanks to tuckbick */
247+
// Adjust the corner points to enable tolerance.
248+
if (options.submenuDirection == "right") {
249+
upperRight.y -= options.tolerance;
250+
lowerRight.y += options.tolerance;
251+
} else if (options.submenuDirection == "left") {
252+
upperLeft.y -= options.tolerance;
253+
lowerLeft.y += options.tolerance;
254+
} else if (options.submenuDirection == "above") {
255+
upperLeft.x -= options.tolerance;
256+
upperRight.x += options.tolerance;
257+
} else if (options.submenuDirection == "below") {
258+
lowerLeft.x -= options.tolerance;
259+
lowerRight.x += options.tolerance;
260+
}
261+
233262
if (prevLoc.x < offset.left || prevLoc.x > lowerRight.x ||
234263
prevLoc.y < offset.top || prevLoc.y > lowerRight.y) {
235264
// If the previous mouse location was outside of the entire
@@ -299,7 +328,7 @@
299328
// currently activated submenu. Delay before activating a
300329
// new menu row, because user may be moving into submenu.
301330
lastDelayLoc = loc;
302-
return DELAY;
331+
return options.delay;
303332
}
304333

305334
lastDelayLoc = null;
@@ -316,8 +345,17 @@
316345
.mouseleave(mouseleaveRow)
317346
.click(clickRow);
318347

348+
/* https://github.com/kamens/jQuery-menu-aim/pull/31/commits - thanks to saralk */
349+
$menu.bind('DOMNodeInserted', function(e) {
350+
var $newEl = $(e.target);
351+
if ($newEl.is(options.rowSelector)) {
352+
$newEl.mouseenter(mouseenterRow)
353+
.mouseleave(mouseleaveRow)
354+
.click(clickRow);
355+
}
356+
});
357+
319358
$(document).mousemove(mousemoveDocument);
320359

321360
};
322-
})(jQuery);
323-
361+
})(jQuery);

0 commit comments

Comments
 (0)