Merge branch 'fix-8456-lost-mouseenter' of https://github.com/dmethvin/jquery into...
authorjeresig <jeresig@gmail.com>
Mon, 21 Mar 2011 14:53:57 +0000 (10:53 -0400)
committerjeresig <jeresig@gmail.com>
Mon, 21 Mar 2011 14:53:57 +0000 (10:53 -0400)
1  2 
src/event.js
test/unit/event.js

diff --combined src/event.js
@@@ -70,10 -70,10 +70,10 @@@ jQuery.event = 
                }
  
                if ( !eventHandle ) {
 -                      elemData.handle = eventHandle = function() {
 +                      elemData.handle = eventHandle = function( e ) {
                                // Handle the second event of a trigger and when
                                // an event is called after a page has unloaded
 -                              return typeof jQuery !== "undefined" && !jQuery.event.triggered ?
 +                              return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ?
                                        jQuery.event.handle.apply( eventHandle.elem, arguments ) :
                                        undefined;
                        };
                                                        target[ "on" + targetType ] = null;
                                                }
  
 -                                              jQuery.event.triggered = true;
 +                                              jQuery.event.triggered = event.type;
                                                target[ targetType ]();
                                        }
  
                                        target[ "on" + targetType ] = old;
                                }
  
 -                              jQuery.event.triggered = false;
 +                              jQuery.event.triggered = undefined;
                        }
                }
        },
@@@ -661,7 -661,7 +661,7 @@@ var withinElement = function( event ) 
  
                // Chrome does something similar, the parentNode property
                // can be accessed but is null.
-               if ( parent !== document && !parent.parentNode ) {
+               if ( parent && parent !== document && !parent.parentNode ) {
                        return;
                }
                // Traverse up the tree
@@@ -868,33 -868,19 +868,33 @@@ function trigger( type, elem, args ) 
  // Create "bubbling" focus and blur events
  if ( document.addEventListener ) {
        jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
 +      
 +              // Attach a single capturing handler while someone wants focusin/focusout
 +              var attaches = 0;
 +              
                jQuery.event.special[ fix ] = {
                        setup: function() {
 -                              this.addEventListener( orig, handler, true );
 +                              if ( attaches++ === 0 ) {
 +                                      document.addEventListener( orig, handler, true );
 +                              }
                        },
                        teardown: function() {
 -                              this.removeEventListener( orig, handler, true );
 +                              if ( --attaches === 0 ) {
 +                                      document.removeEventListener( orig, handler, true );
 +                              }
                        }
                };
  
 -              function handler( e ) {
 -                      e = jQuery.event.fix( e );
 +              function handler( donor ) {
 +                      // Donor event is always a native one; fix it and switch its type.
 +                      // Let focusin/out handler cancel the donor focus/blur event.
 +                      var e = jQuery.event.fix( donor );
                        e.type = fix;
 -                      return jQuery.event.handle.call( this, e );
 +                      e.originalEvent = {};
 +                      jQuery.event.trigger( e, null, e.target );
 +                      if ( e.isDefaultPrevented() ) {
 +                              donor.preventDefault();
 +                      }
                }
        });
  }
diff --combined test/unit/event.js
@@@ -683,6 -683,20 +683,20 @@@ test("hover()", function() 
        equals( times, 4, "hover handlers fired" );
  });
  
+ test("mouseover triggers mouseenter", function() {
+       expect(1);
+       
+       var count = 0,
+               elem = jQuery("<a />");
+       elem.mouseenter(function () {
+         count++;
+       });
+       elem.trigger('mouseover');
+       equals(count, 1, "make sure mouseover triggers a mouseenter" );
+       
+       elem.remove();
+ });
  test("trigger() shortcuts", function() {
        expect(6);
  
@@@ -1966,31 -1980,6 +1980,31 @@@ test("window resize", function() 
        ok( !jQuery._data(window, "__events__"), "Make sure all the events are gone." );
  });
  
 +test("focusin bubbles", function() {
 +      expect(4);
 +      
 +      var input = jQuery( '<input type="text" />' ).prependTo( "body" ), 
 +              order = 0;
 +
 +      jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){
 +              equals( 1, order++, "focusin on the body second" );
 +      });
 +
 +      input.bind( "focusin.focusinBubblesTest", function(){
 +              equals( 0, order++, "focusin on the element first" );
 +      });
 +
 +      // DOM focus method
 +      input[0].focus();
 +      // jQuery trigger, which calls DOM focus
 +      order = 0;
 +      input[0].blur();
 +      input.trigger( "focus" );
 +
 +      input.remove();
 +      jQuery( "body" ).unbind( "focusin.focusinBubblesTest" );
 +});
 +
  /*
  test("jQuery(function($) {})", function() {
        stop();