WordPress.org

Make WordPress Core

Changeset 19605


Ignore:
Timestamp:
12/20/2011 08:54:54 PM (7 years ago)
Author:
nacin
Message:

hoverIntent r6. fixes #19311.

Location:
trunk/wp-includes/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/hoverIntent.dev.js

    r10291 r19605  
    55* threshold) before firing the onMouseOver event.
    66*
    7 * hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
     7* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
    88* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
    99*
     
    2626* @param  f  onMouseOver function || An object with configuration options
    2727* @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
    2929*/
    3030(function($) {
     
    7373            return cfg.out.apply(ob,[ev]);
    7474        };
    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         };
    9775
    9876        // A private function for handling mouse 'hovering'
    99         var doHover = function(e,ob) {
    100 
     77        var handleHover = function(e) {
    10178            // copy objects to be passed into t (required for event object to be passed in IE)
    10279            var ev = jQuery.extend({},e);
     80            var ob = this;
    10381
    10482            // cancel hoverIntent timer if it exists
    10583            if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
    10684
    107             // else e.type == "onmouseover"
    108             if (e.type == "mouseover") {
     85            // if e.type == "mouseenter"
     86            if (e.type == "mouseenter") {
    10987                // set "previous" X and Y position based on initial entry point
    11088                pX = ev.pageX; pY = ev.pageY;
     
    11492                if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
    11593
    116             // else e.type == "onmouseout"
     94            // else e.type == "mouseleave"
    11795            } else {
    11896                // unbind expensive mousemove event
     
    124102
    125103        // bind the function to the two event listeners
    126         return this.mouseover(handleHover).mouseout(handleHover);
     104        return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover);
    127105    };
    128106})(jQuery);
  • trunk/wp-includes/js/hoverIntent.js

    r10291 r19605  
    1 (function(a){a.fn.hoverIntent=function(l,j){var m={sensitivity:7,interval:100,timeout:0};m=a.extend(m,j?{over:l,out:j}:l);var o,n,h,d;var e=function(f){o=f.pageX;n=f.pageY};var c=function(g,f){f.hoverIntent_t=clearTimeout(f.hoverIntent_t);if((Math.abs(h-o)+Math.abs(d-n))<m.sensitivity){a(f).unbind("mousemove",e);f.hoverIntent_s=1;return m.over.apply(f,[g])}else{h=o;d=n;f.hoverIntent_t=setTimeout(function(){c(g,f)},m.interval)}};var i=function(g,f){f.hoverIntent_t=clearTimeout(f.hoverIntent_t);f.hoverIntent_s=0;return m.out.apply(f,[g])};var b=function(q){var f=this;var g=(q.type=="mouseover"?q.fromElement:q.toElement)||q.relatedTarget;while(g&&g!=this){try{g=g.parentNode}catch(q){g=this}}if(g==this){if(a.browser.mozilla){if(q.type=="mouseout"){f.mtout=setTimeout(function(){k(q,f)},30)}else{if(f.mtout){f.mtout=clearTimeout(f.mtout)}}}return}else{if(f.mtout){f.mtout=clearTimeout(f.mtout)}k(q,f)}};var k=function(p,f){var g=jQuery.extend({},p);if(f.hoverIntent_t){f.hoverIntent_t=clearTimeout(f.hoverIntent_t)}if(p.type=="mouseover"){h=g.pageX;d=g.pageY;a(f).bind("mousemove",e);if(f.hoverIntent_s!=1){f.hoverIntent_t=setTimeout(function(){c(g,f)},m.interval)}}else{a(f).unbind("mousemove",e);if(f.hoverIntent_s==1){f.hoverIntent_t=setTimeout(function(){i(g,f)},m.timeout)}}};return this.mouseover(b).mouseout(b)}})(jQuery);
     1(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);
Note: See TracChangeset for help on using the changeset viewer.