1
1
/**
2
2
* menu-aim is a jQuery plugin for dropdown menus that can differentiate
3
3
* 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.
5
6
*
6
7
* menu-aim assumes that you have are using a menu with submenus that expand
7
8
* to the menu's right. It will fire events when the user's mouse enters a new
95
96
exit : $ . noop ,
96
97
activate : $ . noop ,
97
98
deactivate : $ . noop ,
98
- exitMenu : $ . noop
99
+ exitMenu : $ . noop ,
100
+ delay : 300
99
101
} , opts ) ;
100
102
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
103
104
104
105
/**
105
106
* Keep track of the last few locations of the mouse.
144
145
possiblyActivate ( this ) ;
145
146
} ,
146
147
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
+ }
147
154
options . exit ( this ) ;
148
155
} ;
149
156
166
173
options . deactivate ( activeRow ) ;
167
174
}
168
175
176
+ /* https://github.com/kamens/jQuery-menu-aim/pull/33/commits */
177
+ if ( ! $ ( row ) . is ( options . submenuSelector ) ) {
178
+ activeRow = null ;
179
+ return ;
180
+ }
181
+
169
182
options . activate ( row ) ;
170
183
activeRow = row ;
171
184
} ;
205
218
var offset = $menu . offset ( ) ,
206
219
upperLeft = {
207
220
x : offset . left ,
208
- y : offset . top - options . tolerance
221
+ y : offset . top
209
222
} ,
210
223
upperRight = {
211
224
x : offset . left + $menu . outerWidth ( ) ,
212
225
y : upperLeft . y
213
226
} ,
214
227
lowerLeft = {
215
228
x : offset . left ,
216
- y : offset . top + $menu . outerHeight ( ) + options . tolerance
229
+ y : offset . top + $menu . outerHeight ( )
217
230
} ,
218
231
lowerRight = {
219
232
x : offset . left + $menu . outerWidth ( ) ,
230
243
prevLoc = loc ;
231
244
}
232
245
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
+
233
262
if ( prevLoc . x < offset . left || prevLoc . x > lowerRight . x ||
234
263
prevLoc . y < offset . top || prevLoc . y > lowerRight . y ) {
235
264
// If the previous mouse location was outside of the entire
299
328
// currently activated submenu. Delay before activating a
300
329
// new menu row, because user may be moving into submenu.
301
330
lastDelayLoc = loc ;
302
- return DELAY ;
331
+ return options . delay ;
303
332
}
304
333
305
334
lastDelayLoc = null ;
316
345
. mouseleave ( mouseleaveRow )
317
346
. click ( clickRow ) ;
318
347
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
+
319
358
$ ( document ) . mousemove ( mousemoveDocument ) ;
320
359
321
360
} ;
322
- } ) ( jQuery ) ;
323
-
361
+ } ) ( jQuery ) ;
0 commit comments