Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix #8732. Change feature detect for focusin event support, so IE9 wo…
…n't have duplicate events.
  • Loading branch information
dmethvin committed Apr 7, 2011
1 parent b7dd840 commit bbd9c77
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/event.js
Expand Up @@ -850,7 +850,7 @@ function trigger( type, elem, args ) {
}

// Create "bubbling" focus and blur events
if ( document.addEventListener ) {
if ( !jQuery.support.focusinBubbles ) {
jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {

// Attach a single capturing handler while someone wants focusin/focusout
Expand Down
1 change: 1 addition & 0 deletions src/support.js
Expand Up @@ -226,6 +226,7 @@

jQuery.support.submitBubbles = eventSupported("submit");
jQuery.support.changeBubbles = eventSupported("change");
jQuery.support.focusinBubbles = document.attachEvent && eventSupported("focusin");

This comment has been minimized.

Copy link
@jdalton

jdalton Apr 7, 2011

Member

I believe Opera has 'attachEvent' too. This is kind of a weak inference as non of them test bubbling. Also keep in mind focusin (bubble phase) is diff than focus (capture phase).

This comment has been minimized.

Copy link
@dmethvin

dmethvin Apr 7, 2011

Author Member

Opera does, and it's okay for it to go through this check. I agree these are all pretty weak inferences; I'm just checking to see if focusin is supported and bubbles, not whether the workaround (focus capture phase) can be implemented.

This comment has been minimized.

Copy link
@jdalton

jdalton Apr 7, 2011

Member

eventSupported doesn't check bubbling, just that a function value is created when setting an attribute

This comment has been minimized.

Copy link
@dmethvin

dmethvin Apr 7, 2011

Author Member

True, what I'm testing (is focusin supported on a div) and what I'm asserting as a result (focusin bubbles) are more than a few feet away from each other. However I think it's true for the set of browsers we support. I could nest elements and test for actual bubbling, but since we run this stuff on every page load I figured it was best to keep it light. If the feature detect is wrong I'll go to something more complex.

This comment has been minimized.

Copy link
@jdalton

jdalton Apr 7, 2011

Member

it might be avoided altogether if the workaround is tweaked to avoid focusin completely. Because jQuery can simulate bubbling and you all manage event handler execution order, you could simply set 1 real focus/blur event on an element and have it trigger simulated bubbling. To set the 1 real focus/blur you intercept the focus (capture) of the parent element (at when u call delegate on the parent) and grab the event.target element.


// release memory in IE
div = all = a = null;
Expand Down

2 comments on commit bbd9c77

@dmethvin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdalton, I'm not sure how that differs from what we're doing now at

@jdalton
Copy link
Member

@jdalton jdalton commented on bbd9c77 Apr 7, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool! Then it should be simple. Would break back compat but it would avoid trying to simulate a focusin and focusout. I did this by having like a delegate:focus event instead so it was something separate.

Please sign in to comment.