WordPress.org

Make WordPress Core

Ticket #23752: hoverintentr7.diff

File hoverintentr7.diff, 11.7 KB (added by mjbanks, 13 months ago)

upgrade hoverintent to r7, both full and minified version (via uglify)

  • wp-includes/js/hoverIntent.js

     
    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 r6 // 2011.02.26 // jQuery 1.5.1+ 
    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: 7, // number = sensitivity threshold (must be 1 or higher) 
    20 *       interval: 100,   // number = milliseconds of polling interval 
    21 *       over: showNav,  // function = onMouseOver callback (required) 
    22 *       timeout: 0,   // 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 * @author    Brian Cherne brian(at)cherne(dot)net 
    29 */ 
     1/*! 
     2 * hoverIntent r7 // 2013.03.11 // jQuery 1.9.1+ 
     3 * http://cherne.net/brian/resources/jquery.hoverIntent.html 
     4 * 
     5 * You may use hoverIntent under the terms of the MIT license. Basically that 
     6 * means you are free to use hoverIntent as long as this header is left intact. 
     7 * Copyright 2007, 2013 Brian Cherne 
     8 */ 
     9 
     10/* hoverIntent is similar to jQuery's built-in "hover" method except that 
     11 * instead of firing the handlerIn function immediately, hoverIntent checks 
     12 * to see if the user's mouse has slowed down (beneath the sensitivity 
     13 * threshold) before firing the event. The handlerOut function is only 
     14 * called after a matching handlerIn. 
     15 * 
     16 * // basic usage ... just like .hover() 
     17 * .hoverIntent( handlerIn, handlerOut ) 
     18 * .hoverIntent( handlerInOut ) 
     19 * 
     20 * // basic usage ... with event delegation! 
     21 * .hoverIntent( handlerIn, handlerOut, selector ) 
     22 * .hoverIntent( handlerInOut, selector ) 
     23 * 
     24 * // using a basic configuration object 
     25 * .hoverIntent( config ) 
     26 * 
     27 * @param  handlerIn   function OR configuration object 
     28 * @param  handlerOut  function OR selector for delegation OR undefined 
     29 * @param  selector    selector OR undefined 
     30 * @author Brian Cherne <brian(at)cherne(dot)net> 
     31 */ 
    3032(function($) { 
    31         $.fn.hoverIntent = function(f,g) { 
    32                 // default configuration options 
    33                 var cfg = { 
    34                         sensitivity: 7, 
    35                         interval: 100, 
    36                         timeout: 0 
    37                 }; 
    38                 // override configuration options with user supplied object 
    39                 cfg = $.extend(cfg, g ? { over: f, out: g } : f ); 
     33    $.fn.hoverIntent = function(handlerIn,handlerOut,selector) { 
    4034 
    41                 // instantiate variables 
    42                 // cX, cY = current X and Y position of mouse, updated by mousemove event 
    43                 // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval 
    44                 var cX, cY, pX, pY; 
     35        // default configuration values 
     36        var cfg = { 
     37            interval: 100, 
     38            sensitivity: 7, 
     39            timeout: 0 
     40        }; 
    4541 
    46                 // A private function for getting mouse position 
    47                 var track = function(ev) { 
    48                         cX = ev.pageX; 
    49                         cY = ev.pageY; 
    50                 }; 
     42        if ( typeof handlerIn === "object" ) { 
     43            cfg = $.extend(cfg, handlerIn ); 
     44        } else if ($.isFunction(handlerOut)) { 
     45            cfg = $.extend(cfg, { over: handlerIn, out: handlerOut, selector: selector } ); 
     46        } else { 
     47            cfg = $.extend(cfg, { over: handlerIn, out: handlerIn, selector: handlerOut } ); 
     48        } 
    5149 
    52                 // A private function for comparing current and previous mouse position 
    53                 var compare = function(ev,ob) { 
    54                         ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); 
    55                         // compare mouse positions to see if they've crossed the threshold 
    56                         if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) { 
    57                                 $(ob).unbind("mousemove",track); 
    58                                 // set hoverIntent state to true (so mouseOut can be called) 
    59                                 ob.hoverIntent_s = 1; 
    60                                 return cfg.over.apply(ob,[ev]); 
    61                         } else { 
    62                                 // set previous coordinates for next time 
    63                                 pX = cX; pY = cY; 
    64                                 // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs) 
    65                                 ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval ); 
    66                         } 
    67                 }; 
     50        // instantiate variables 
     51        // cX, cY = current X and Y position of mouse, updated by mousemove event 
     52        // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval 
     53        var cX, cY, pX, pY; 
    6854 
    69                 // A private function for delaying the mouseOut function 
    70                 var delay = function(ev,ob) { 
    71                         ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); 
    72                         ob.hoverIntent_s = 0; 
    73                         return cfg.out.apply(ob,[ev]); 
    74                 }; 
     55        // A private function for getting mouse position 
     56        var track = function(ev) { 
     57            cX = ev.pageX; 
     58            cY = ev.pageY; 
     59        }; 
    7560 
    76                 // A private function for handling mouse 'hovering' 
    77                 var handleHover = function(e) { 
    78                         // copy objects to be passed into t (required for event object to be passed in IE) 
    79                         var ev = jQuery.extend({},e); 
    80                         var ob = this; 
     61        // A private function for comparing current and previous mouse position 
     62        var compare = function(ev,ob) { 
     63            ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); 
     64            // compare mouse positions to see if they've crossed the threshold 
     65            if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) { 
     66                $(ob).off("mousemove.hoverIntent",track); 
     67                // set hoverIntent state to true (so mouseOut can be called) 
     68                ob.hoverIntent_s = 1; 
     69                return cfg.over.apply(ob,[ev]); 
     70            } else { 
     71                // set previous coordinates for next time 
     72                pX = cX; pY = cY; 
     73                // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs) 
     74                ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval ); 
     75            } 
     76        }; 
    8177 
    82                         // cancel hoverIntent timer if it exists 
    83                         if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } 
     78        // A private function for delaying the mouseOut function 
     79        var delay = function(ev,ob) { 
     80            ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); 
     81            ob.hoverIntent_s = 0; 
     82            return cfg.out.apply(ob,[ev]); 
     83        }; 
    8484 
    85                         // if e.type == "mouseenter" 
    86                         if (e.type == "mouseenter") { 
    87                                 // set "previous" X and Y position based on initial entry point 
    88                                 pX = ev.pageX; pY = ev.pageY; 
    89                                 // update "current" X and Y position based on mousemove 
    90                                 $(ob).bind("mousemove",track); 
    91                                 // start polling interval (self-calling timeout) to compare mouse coordinates over time 
    92                                 if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );} 
     85        // A private function for handling mouse 'hovering' 
     86        var handleHover = function(e) { 
     87            // copy objects to be passed into t (required for event object to be passed in IE) 
     88            var ev = jQuery.extend({},e); 
     89            var ob = this; 
    9390 
    94                         // else e.type == "mouseleave" 
    95                         } else { 
    96                                 // unbind expensive mousemove event 
    97                                 $(ob).unbind("mousemove",track); 
    98                                 // if hoverIntent state is true, then call the mouseOut function after the specified delay 
    99                                 if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );} 
    100                         } 
    101                 }; 
     91            // cancel hoverIntent timer if it exists 
     92            if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } 
    10293 
    103                 // bind the function to the two event listeners 
    104                 return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover); 
    105         }; 
    106 })(jQuery); 
    107  No newline at end of file 
     94            // if e.type == "mouseenter" 
     95            if (e.type == "mouseenter") { 
     96                // set "previous" X and Y position based on initial entry point 
     97                pX = ev.pageX; pY = ev.pageY; 
     98                // update "current" X and Y position based on mousemove 
     99                $(ob).on("mousemove.hoverIntent",track); 
     100                // start polling interval (self-calling timeout) to compare mouse coordinates over time 
     101                if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );} 
     102 
     103                // else e.type == "mouseleave" 
     104            } else { 
     105                // unbind expensive mousemove event 
     106                $(ob).off("mousemove.hoverIntent",track); 
     107                // if hoverIntent state is true, then call the mouseOut function after the specified delay 
     108                if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );} 
     109            } 
     110        }; 
     111 
     112        // listen for mouseenter and mouseleave 
     113        return this.on({'mouseenter.hoverIntent':handleHover,'mouseleave.hoverIntent':handleHover}, cfg.selector); 
     114    }; 
     115})(jQuery); 
  • wp-includes/js/hoverIntent.min.js

     
    1 (function(a){a.fn.hoverIntent=function(k,j){var l={sensitivity:7,interval:100,timeout:0};l=a.extend(l,j?{over:k,out:j}:k);var n,m,h,d;var e=function(f){n=f.pageX;m=f.pageY};var c=function(g,f){f.hoverIntent_t=clearTimeout(f.hoverIntent_t);if((Math.abs(h-n)+Math.abs(d-m))<l.sensitivity){a(f).unbind("mousemove",e);f.hoverIntent_s=1;return l.over.apply(f,[g])}else{h=n;d=m;f.hoverIntent_t=setTimeout(function(){c(g,f)},l.interval)}};var i=function(g,f){f.hoverIntent_t=clearTimeout(f.hoverIntent_t);f.hoverIntent_s=0;return l.out.apply(f,[g])};var b=function(o){var g=jQuery.extend({},o);var f=this;if(f.hoverIntent_t){f.hoverIntent_t=clearTimeout(f.hoverIntent_t)}if(o.type=="mouseenter"){h=g.pageX;d=g.pageY;a(f).bind("mousemove",e);if(f.hoverIntent_s!=1){f.hoverIntent_t=setTimeout(function(){c(g,f)},l.interval)}}else{a(f).unbind("mousemove",e);if(f.hoverIntent_s==1){f.hoverIntent_t=setTimeout(function(){i(g,f)},l.timeout)}}};return this.bind("mouseenter",b).bind("mouseleave",b)}})(jQuery); 
    2  No newline at end of file 
     1(function(a){a.fn.hoverIntent=function(b,c,d){var e={interval:100,sensitivity:7,timeout:0};e="object"==typeof b?a.extend(e,b):a.isFunction(c)?a.extend(e,{over:b,out:c,selector:d}):a.extend(e,{over:b,out:b,selector:c});var f,g,h,i,j=function(a){f=a.pageX,g=a.pageY},k=function(b,c){return c.hoverIntent_t=clearTimeout(c.hoverIntent_t),Math.abs(h-f)+Math.abs(i-g)<e.sensitivity?(a(c).off("mousemove.hoverIntent",j),c.hoverIntent_s=1,e.over.apply(c,[b])):(h=f,i=g,c.hoverIntent_t=setTimeout(function(){k(b,c)},e.interval),void 0)},l=function(a,b){return b.hoverIntent_t=clearTimeout(b.hoverIntent_t),b.hoverIntent_s=0,e.out.apply(b,[a])},m=function(b){var c=jQuery.extend({},b),d=this;d.hoverIntent_t&&(d.hoverIntent_t=clearTimeout(d.hoverIntent_t)),"mouseenter"==b.type?(h=c.pageX,i=c.pageY,a(d).on("mousemove.hoverIntent",j),1!=d.hoverIntent_s&&(d.hoverIntent_t=setTimeout(function(){k(c,d)},e.interval))):(a(d).off("mousemove.hoverIntent",j),1==d.hoverIntent_s&&(d.hoverIntent_t=setTimeout(function(){l(c,d)},e.timeout)))};return this.on({"mouseenter.hoverIntent":m,"mouseleave.hoverIntent":m},e.selector)}})(jQuery);