WordPress.org

Make WordPress Core

Ticket #31505: 31505.patch

File 31505.patch, 3.7 KB (added by rachelbaker, 6 years ago)

hoverIntent v1.8.1

  • src/wp-includes/js/hoverIntent.js

     
    11/*!
    2  * hoverIntent r7 // 2013.03.11 // jQuery 1.9.1+
     2 * hoverIntent v1.8.1 // 2014.08.11 // jQuery v1.9.1+
    33 * http://cherne.net/brian/resources/jquery.hoverIntent.html
    44 *
    55 * You may use hoverIntent under the terms of the MIT license. Basically that
    66 * means you are free to use hoverIntent as long as this header is left intact.
    7  * Copyright 2007, 2013 Brian Cherne
     7 * Copyright 2007, 2014 Brian Cherne
    88 */
    99
    1010/* hoverIntent is similar to jQuery's built-in "hover" method except that
     
    3535        // default configuration values
    3636        var cfg = {
    3737            interval: 100,
    38             sensitivity: 7,
     38            sensitivity: 6,
    3939            timeout: 0
    4040        };
    4141
     
    6262        var compare = function(ev,ob) {
    6363            ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
    6464            // compare mouse positions to see if they've crossed the threshold
    65             if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
     65            if ( Math.sqrt( (pX-cX)*(pX-cX) + (pY-cY)*(pY-cY) ) < cfg.sensitivity ) {
    6666                $(ob).off("mousemove.hoverIntent",track);
    6767                // set hoverIntent state to true (so mouseOut can be called)
    68                 ob.hoverIntent_s = 1;
     68                ob.hoverIntent_s = true;
    6969                return cfg.over.apply(ob,[ev]);
    7070            } else {
    7171                // set previous coordinates for next time
     
    7878        // A private function for delaying the mouseOut function
    7979        var delay = function(ev,ob) {
    8080            ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
    81             ob.hoverIntent_s = 0;
     81            ob.hoverIntent_s = false;
    8282            return cfg.out.apply(ob,[ev]);
    8383        };
    8484
     
    8585        // A private function for handling mouse 'hovering'
    8686        var handleHover = function(e) {
    8787            // copy objects to be passed into t (required for event object to be passed in IE)
    88             var ev = jQuery.extend({},e);
     88            var ev = $.extend({},e);
    8989            var ob = this;
    9090
    9191            // cancel hoverIntent timer if it exists
    9292            if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
    9393
    94             // if e.type == "mouseenter"
    95             if (e.type == "mouseenter") {
     94            // if e.type === "mouseenter"
     95            if (e.type === "mouseenter") {
    9696                // set "previous" X and Y position based on initial entry point
    9797                pX = ev.pageX; pY = ev.pageY;
    9898                // update "current" X and Y position based on mousemove
    9999                $(ob).on("mousemove.hoverIntent",track);
    100100                // 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 );}
     101                if (!ob.hoverIntent_s) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
    102102
    103103                // else e.type == "mouseleave"
    104104            } else {
     
    105105                // unbind expensive mousemove event
    106106                $(ob).off("mousemove.hoverIntent",track);
    107107                // 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 );}
     108                if (ob.hoverIntent_s) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
    109109            }
    110110        };
    111111