Make WordPress Core

Changeset 24259


Ignore:
Timestamp:
05/14/2013 07:53:05 PM (12 years ago)
Author:
ocean90
Message:

hoverIntent r7. props mjbanks. fixes #23752.

Location:
trunk/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/admin-bar.js

    r23683 r24259  
    33    if ( typeof(jQuery.fn.hoverIntent) == 'undefined' ) {
    44        // hoverIntent r6 - Copy of wp-includes/js/hoverIntent.min.js
    5         (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);
     5        (function(a){a.fn.hoverIntent=function(m,d,h){var j={interval:100,sensitivity:7,timeout:0};if(typeof m==="object"){j=a.extend(j,m)}else{if(a.isFunction(d)){j=a.extend(j,{over:m,out:d,selector:h})}else{j=a.extend(j,{over:m,out:m,selector:d})}}var l,k,g,f;var e=function(n){l=n.pageX;k=n.pageY};var c=function(o,n){n.hoverIntent_t=clearTimeout(n.hoverIntent_t);if((Math.abs(g-l)+Math.abs(f-k))<j.sensitivity){a(n).off("mousemove.hoverIntent",e);n.hoverIntent_s=1;return j.over.apply(n,[o])}else{g=l;f=k;n.hoverIntent_t=setTimeout(function(){c(o,n)},j.interval)}};var i=function(o,n){n.hoverIntent_t=clearTimeout(n.hoverIntent_t);n.hoverIntent_s=0;return j.out.apply(n,[o])};var b=function(p){var o=jQuery.extend({},p);var n=this;if(n.hoverIntent_t){n.hoverIntent_t=clearTimeout(n.hoverIntent_t)}if(p.type=="mouseenter"){g=o.pageX;f=o.pageY;a(n).on("mousemove.hoverIntent",e);if(n.hoverIntent_s!=1){n.hoverIntent_t=setTimeout(function(){c(o,n)},j.interval)}}else{a(n).off("mousemove.hoverIntent",e);if(n.hoverIntent_s==1){n.hoverIntent_t=setTimeout(function(){i(o,n)},j.timeout)}}};return this.on({"mouseenter.hoverIntent":b,"mouseleave.hoverIntent":b},j.selector)}})(jQuery);
    66    }
    77    jQuery(document).ready(function($){
  • trunk/wp-includes/js/hoverIntent.js

    r21592 r24259  
    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     };
     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    };
    106115})(jQuery);
  • trunk/wp-includes/script-loader.php

    r24252 r24259  
    322322    $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox', 'shortcode' ), false, 1 );
    323323
    324     $scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array('jquery'), 'r6', 1 );
     324    $scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array('jquery'), 'r7', 1 );
    325325
    326326    $scripts->add( 'customize-base',     "/wp-includes/js/customize-base$suffix.js",     array( 'jquery', 'json2' ), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.