-
+ EB320C34C6B4C630A27566249D5A81F6EE91E9D5A59F350A60E638BD41209AD2D931B57DD3902664FFB12074E771E60B99C10E53AD953EA541158B1FA51A9B08
mp-wp/wp-includes/js/hoverIntent.js
(0 . 0)(1 . 128)
101057 /**
101058 * hoverIntent is similar to jQuery's built-in "hover" function except that
101059 * instead of firing the onMouseOver event immediately, hoverIntent checks
101060 * to see if the user's mouse has slowed down (beneath the sensitivity
101061 * threshold) before firing the onMouseOver event.
101062 *
101063 * hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
101064 * <http://cherne.net/brian/resources/jquery.hoverIntent.html>
101065 *
101066 * hoverIntent is currently available for use in all personal or commercial
101067 * projects under both MIT and GPL licenses. This means that you can choose
101068 * the license that best suits your project, and use it accordingly.
101069 *
101070 * // basic usage (just like .hover) receives onMouseOver and onMouseOut functions
101071 * $("ul li").hoverIntent( showNav , hideNav );
101072 *
101073 * // advanced usage receives configuration object only
101074 * $("ul li").hoverIntent({
101075 * sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
101076 * interval: 100, // number = milliseconds of polling interval
101077 * over: showNav, // function = onMouseOver callback (required)
101078 * timeout: 0, // number = milliseconds delay before onMouseOut function call
101079 * out: hideNav // function = onMouseOut callback (required)
101080 * });
101081 *
101082 * @param f onMouseOver function || An object with configuration options
101083 * @param g onMouseOut function || Nothing (use configuration options object)
101084 * @author Brian Cherne <brian@cherne.net>
101085 */
101086 (function($) {
101087 $.fn.hoverIntent = function(f,g) {
101088 // default configuration options
101089 var cfg = {
101090 sensitivity: 7,
101091 interval: 100,
101092 timeout: 0
101093 };
101094 // override configuration options with user supplied object
101095 cfg = $.extend(cfg, g ? { over: f, out: g } : f );
101096
101097 // instantiate variables
101098 // cX, cY = current X and Y position of mouse, updated by mousemove event
101099 // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
101100 var cX, cY, pX, pY;
101101
101102 // A private function for getting mouse position
101103 var track = function(ev) {
101104 cX = ev.pageX;
101105 cY = ev.pageY;
101106 };
101107
101108 // A private function for comparing current and previous mouse position
101109 var compare = function(ev,ob) {
101110 ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
101111 // compare mouse positions to see if they've crossed the threshold
101112 if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
101113 $(ob).unbind("mousemove",track);
101114 // set hoverIntent state to true (so mouseOut can be called)
101115 ob.hoverIntent_s = 1;
101116 return cfg.over.apply(ob,[ev]);
101117 } else {
101118 // set previous coordinates for next time
101119 pX = cX; pY = cY;
101120 // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
101121 ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
101122 }
101123 };
101124
101125 // A private function for delaying the mouseOut function
101126 var delay = function(ev,ob) {
101127 ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
101128 ob.hoverIntent_s = 0;
101129 return cfg.out.apply(ob,[ev]);
101130 };
101131
101132 // workaround for Mozilla bug: not firing mouseout/mouseleave on absolute positioned elements over textareas and input type="text"
101133 var handleHover = function(e) {
101134 var t = this;
101135
101136 // next two lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
101137 var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
101138 while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
101139 if ( p == this ) {
101140 if ( $.browser.mozilla ) {
101141 if ( e.type == "mouseout" ) {
101142 t.mtout = setTimeout( function(){doHover(e,t);}, 30 );
101143 } else {
101144 if (t.mtout) { t.mtout = clearTimeout(t.mtout); }
101145 }
101146 }
101147 return;
101148 } else {
101149 if (t.mtout) { t.mtout = clearTimeout(t.mtout); }
101150 doHover(e,t);
101151 }
101152 };
101153
101154 // A private function for handling mouse 'hovering'
101155 var doHover = function(e,ob) {
101156
101157 // copy objects to be passed into t (required for event object to be passed in IE)
101158 var ev = jQuery.extend({},e);
101159
101160 // cancel hoverIntent timer if it exists
101161 if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
101162
101163 // else e.type == "onmouseover"
101164 if (e.type == "mouseover") {
101165 // set "previous" X and Y position based on initial entry point
101166 pX = ev.pageX; pY = ev.pageY;
101167 // update "current" X and Y position based on mousemove
101168 $(ob).bind("mousemove",track);
101169 // start polling interval (self-calling timeout) to compare mouse coordinates over time
101170 if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
101171
101172 // else e.type == "onmouseout"
101173 } else {
101174 // unbind expensive mousemove event
101175 $(ob).unbind("mousemove",track);
101176 // if hoverIntent state is true, then call the mouseOut function after the specified delay
101177 if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
101178 }
101179 };
101180
101181 // bind the function to the two event listeners
101182 return this.mouseover(handleHover).mouseout(handleHover);
101183 };
101184 })(jQuery);