4
4
* to see if the user's mouse has slowed down (beneath the sensitivity
5
5
* threshold) before firing the onMouseOver event.
6
6
*
7
- * hoverIntent r5 // 2007.03.27 // jQuery 1.1.2 +
7
+ * hoverIntent r6 // 2011.02.26 // jQuery 1.5.1 +
8
8
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
9
9
*
10
10
* hoverIntent is currently available for use in all personal or commercial
25
25
*
26
26
* @param f onMouseOver function || An object with configuration options
27
27
* @param g onMouseOut function || Nothing (use configuration options object)
28
- * @author Brian Cherne < brian@ cherne. net>
28
+ * @author Brian Cherne brian(at) cherne(dot) net
29
29
*/
30
30
( function ( $ ) {
31
31
$ . fn . hoverIntent = function ( f , g ) {
72
72
ob . hoverIntent_s = 0 ;
73
73
return cfg . out . apply ( ob , [ ev ] ) ;
74
74
} ;
75
-
76
- // workaround for Mozilla bug: not firing mouseout/mouseleave on absolute positioned elements over textareas and input type="text"
77
- var handleHover = function ( e ) {
78
- var t = this ;
79
-
80
- // next two lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
81
- var p = ( e . type == "mouseover" ? e . fromElement : e . toElement ) || e . relatedTarget ;
82
- while ( p && p != this ) { try { p = p . parentNode ; } catch ( e ) { p = this ; } }
83
- if ( p == this ) {
84
- if ( $ . browser . mozilla ) {
85
- if ( e . type == "mouseout" ) {
86
- t . mtout = setTimeout ( function ( ) { doHover ( e , t ) ; } , 30 ) ;
87
- } else {
88
- if ( t . mtout ) { t . mtout = clearTimeout ( t . mtout ) ; }
89
- }
90
- }
91
- return ;
92
- } else {
93
- if ( t . mtout ) { t . mtout = clearTimeout ( t . mtout ) ; }
94
- doHover ( e , t ) ;
95
- }
96
- } ;
97
75
98
76
// A private function for handling mouse 'hovering'
99
- var doHover = function ( e , ob ) {
100
-
77
+ var handleHover = function ( e ) {
101
78
// copy objects to be passed into t (required for event object to be passed in IE)
102
79
var ev = jQuery . extend ( { } , e ) ;
80
+ var ob = this ;
103
81
104
82
// cancel hoverIntent timer if it exists
105
83
if ( ob . hoverIntent_t ) { ob . hoverIntent_t = clearTimeout ( ob . hoverIntent_t ) ; }
106
84
107
- // else e.type == "onmouseover "
108
- if ( e . type == "mouseover " ) {
85
+ // if e.type == "mouseenter "
86
+ if ( e . type == "mouseenter " ) {
109
87
// set "previous" X and Y position based on initial entry point
110
88
pX = ev . pageX ; pY = ev . pageY ;
111
89
// update "current" X and Y position based on mousemove
112
90
$ ( ob ) . bind ( "mousemove" , track ) ;
113
91
// start polling interval (self-calling timeout) to compare mouse coordinates over time
114
92
if ( ob . hoverIntent_s != 1 ) { ob . hoverIntent_t = setTimeout ( function ( ) { compare ( ev , ob ) ; } , cfg . interval ) ; }
115
93
116
- // else e.type == "onmouseout "
94
+ // else e.type == "mouseleave "
117
95
} else {
118
96
// unbind expensive mousemove event
119
97
$ ( ob ) . unbind ( "mousemove" , track ) ;
123
101
} ;
124
102
125
103
// bind the function to the two event listeners
126
- return this . mouseover ( handleHover ) . mouseout ( handleHover ) ;
104
+ return this . bind ( 'mouseenter' , handleHover ) . bind ( 'mouseleave' , handleHover ) ;
127
105
} ;
128
106
} ) ( jQuery ) ;
0 commit comments