web/wp-includes/js/hoverIntent.dev.js
changeset 194 32102edaa81b
parent 136 bde1974c263b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     2 * hoverIntent is similar to jQuery's built-in "hover" function except that
     2 * hoverIntent is similar to jQuery's built-in "hover" function except that
     3 * instead of firing the onMouseOver event immediately, hoverIntent checks
     3 * instead of firing the onMouseOver event immediately, hoverIntent checks
     4 * to see if the user's mouse has slowed down (beneath the sensitivity
     4 * to see if the user's mouse has slowed down (beneath the sensitivity
     5 * threshold) before firing the onMouseOver event.
     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 * <http://cherne.net/brian/resources/jquery.hoverIntent.html>
     8 * <http://cherne.net/brian/resources/jquery.hoverIntent.html>
     9 * 
     9 * 
    10 * hoverIntent is currently available for use in all personal or commercial 
    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 
    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.
    12 * the license that best suits your project, and use it accordingly.
    23 *	out: hideNav    // function = onMouseOut callback (required)
    23 *	out: hideNav    // function = onMouseOut callback (required)
    24 * });
    24 * });
    25 * 
    25 * 
    26 * @param  f  onMouseOver function || An object with configuration options
    26 * @param  f  onMouseOver function || An object with configuration options
    27 * @param  g  onMouseOut function  || Nothing (use configuration options object)
    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 (function($) {
    30 (function($) {
    31 	$.fn.hoverIntent = function(f,g) {
    31 	$.fn.hoverIntent = function(f,g) {
    32 		// default configuration options
    32 		// default configuration options
    33 		var cfg = {
    33 		var cfg = {
    70 		var delay = function(ev,ob) {
    70 		var delay = function(ev,ob) {
    71 			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
    71 			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
    72 			ob.hoverIntent_s = 0;
    72 			ob.hoverIntent_s = 0;
    73 			return cfg.out.apply(ob,[ev]);
    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 		// A private function for handling mouse 'hovering'
    76 		// A private function for handling mouse 'hovering'
    99 		var doHover = function(e,ob) {
    77 		var handleHover = function(e) {
   100 
       
   101 			// copy objects to be passed into t (required for event object to be passed in IE)
    78 			// copy objects to be passed into t (required for event object to be passed in IE)
   102 			var ev = jQuery.extend({},e);
    79 			var ev = jQuery.extend({},e);
       
    80 			var ob = this;
   103 
    81 
   104 			// cancel hoverIntent timer if it exists
    82 			// cancel hoverIntent timer if it exists
   105 			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
    83 			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
   106 
    84 
   107 			// else e.type == "onmouseover"
    85 			// if e.type == "mouseenter"
   108 			if (e.type == "mouseover") {
    86 			if (e.type == "mouseenter") {
   109 				// set "previous" X and Y position based on initial entry point
    87 				// set "previous" X and Y position based on initial entry point
   110 				pX = ev.pageX; pY = ev.pageY;
    88 				pX = ev.pageX; pY = ev.pageY;
   111 				// update "current" X and Y position based on mousemove
    89 				// update "current" X and Y position based on mousemove
   112 				$(ob).bind("mousemove",track);
    90 				$(ob).bind("mousemove",track);
   113 				// start polling interval (self-calling timeout) to compare mouse coordinates over time
    91 				// start polling interval (self-calling timeout) to compare mouse coordinates over time
   114 				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
    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 			} else {
    95 			} else {
   118 				// unbind expensive mousemove event
    96 				// unbind expensive mousemove event
   119 				$(ob).unbind("mousemove",track);
    97 				$(ob).unbind("mousemove",track);
   120 				// if hoverIntent state is true, then call the mouseOut function after the specified delay
    98 				// if hoverIntent state is true, then call the mouseOut function after the specified delay
   121 				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
    99 				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
   122 			}
   100 			}
   123 		};
   101 		};
   124 
   102 
   125 		// bind the function to the two event listeners
   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 })(jQuery);
   106 })(jQuery);