1/** 2* hoverIntent is similar to jQuery's built-in "hover" function except that 3* instead of firing the onMouseOver event immediately, hoverIntent checks 4* to see if the user's mouse has slowed down (beneath the sensitivity 5* threshold) before firing the onMouseOver event. 6* 7* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2 8* <http://cherne.net/brian/resources/jquery.hoverIntent.html> 9* 10* hoverIntent is currently available for use in all personal or commercial 11* projects under both MIT and GPL licenses. This means that you can choose 12* the license that best suits your project, and use it accordingly. 13* 14* // basic usage (just like .hover) receives onMouseOver and onMouseOut functions 15* $("ul li").hoverIntent( showNav , hideNav ); 16* 17* // advanced usage receives configuration object only 18* $("ul li").hoverIntent({ 19* sensitivity: 2, // number = sensitivity threshold (must be 1 or higher) 20* interval: 50, // number = milliseconds of polling interval 21* over: showNav, // function = onMouseOver callback (required) 22* timeout: 100, // number = milliseconds delay before onMouseOut function call 23* out: hideNav // function = onMouseOut callback (required) 24* }); 25* 26* @param f onMouseOver function || An object with configuration options 27* @param g onMouseOut function || Nothing (use configuration options object) 28* @return The object (aka "this") that called hoverIntent, and the event object 29* @author Brian Cherne <[email protected]> 30* 31* modified by Karl Swedberg. Namespaced events in order to work better with clueTip plugin 32*/ 33(function($) { 34 $.fn.hoverIntent = function(f,g) { 35 // default configuration options 36 var cfg = { 37 sensitivity: 7, 38 interval: 100, 39 timeout: 0 40 }; 41 // override configuration options with user supplied object 42 cfg = $.extend(cfg, g ? { over: f, out: g } : f ); 43 44 // instantiate variables 45 // cX, cY = current X and Y position of mouse, updated by mousemove event 46 // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval 47 var cX, cY, pX, pY; 48 49 // A private function for getting mouse position 50 var track = function(ev) { 51 cX = ev.pageX; 52 cY = ev.pageY; 53 }; 54 55 // A private function for comparing current and previous mouse position 56 var compare = function(ev,ob) { 57 ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); 58 // compare mouse positions to see if they've crossed the threshold 59 if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) { 60 $(ob).unbind("mousemove",track); 61 // set hoverIntent state to true (so mouseOut can be called) 62 ob.hoverIntent_s = 1; 63 return cfg.over.apply(ob,[ev]); 64 } else { 65 // set previous coordinates for next time 66 pX = cX; pY = cY; 67 // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs) 68 ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval ); 69 } 70 }; 71 72 // A private function for delaying the mouseOut function 73 var delay = function(ev,ob) { 74 ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); 75 ob.hoverIntent_s = 0; 76 return cfg.out.apply(ob,[ev]); 77 }; 78 79 // A private function for handling mouse 'hovering' 80 var handleHover = function(e) { 81 // next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut 82 var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; 83 while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } } 84 if ( p == this ) { return false; } 85 86 // copy objects to be passed into t (required for event object to be passed in IE) 87 var ev = jQuery.extend({},e); 88 var ob = this; 89 90 // cancel hoverIntent timer if it exists 91 if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } 92 93 // else e.type == "onmouseover" 94 if (e.type == "mouseover") { 95 // set "previous" X and Y position based on initial entry point 96 pX = ev.pageX; pY = ev.pageY; 97 // update "current" X and Y position based on mousemove 98 $(ob).bind("mousemove.cluetip",track); 99 // start polling interval (self-calling timeout) to compare mouse coordinates over time 100 if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );} 101 102 // else e.type == "onmouseout" 103 } else { 104 // unbind expensive mousemove event 105 $(ob).unbind("mousemove.cluetip",track); 106 // if hoverIntent state is true, then call the mouseOut function after the specified delay 107 if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );} 108 } 109 }; 110 111 // bind the function to the two event listeners 112 return this.bind('mouseover.cluetip', handleHover).bind('mouseout.cluetip', handleHover); 113 }; 114})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.