Skip to content
Permalink
Browse files
Narrow the invisible-element embargo to focus/blur events.
  • Loading branch information
dmethvin authored and timmywil committed Sep 19, 2011
1 parent 4030de9 commit 06e56ac
Showing 1 changed file with 6 additions and 5 deletions.
@@ -35,8 +35,9 @@ var rnamespaces = /\.(.*)$/,
},
useNativeMethod = function( event ) {
// IE throws error on focus/blur of a hidden element (#1486)
if ( !event.isDefaultPrevented() && this[ event.type ] && event.target && event.target.offsetWidth !== 0 ) {
this[ event.type ]();
var type = event.type;
if ( !event.isDefaultPrevented() && this[ type ] && ((type !== "focus" && type !== "blur") || event.target.offsetWidth !== 0) ) {
this[ type ]();
return false;
}
};
@@ -385,10 +386,10 @@ jQuery.event = {
!(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) {

// Call a native DOM method on the target with the same name name as the event.
// Can't use an .isFunction)() check here because IE6/7 fails that test.
// Can't use an .isFunction() check here because IE6/7 fails that test.
// Don't do default actions on window, that's where global variables be (#6170)
// IE<9 dies on focus to hidden element (#1486)
if ( ontype && elem[ type ] && elem.offsetWidth !== 0 && !jQuery.isWindow( elem ) ) {
// IE<9 dies on focus/blur to hidden element (#1486)
if ( ontype && elem[ type ] && ((type !== "focus" && type !== "blur") || event.target.offsetWidth !== 0) && !jQuery.isWindow( elem ) ) {
// Don't re-trigger an onFOO event when we call its FOO() method
old = elem[ ontype ];

4 comments on commit 06e56ac

@jquave
Copy link

@jquave jquave commented on 06e56ac Feb 5, 2012

Choose a reason for hiding this comment

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

What is the purpose of including the condition 'event.target.offsetWidth !== 0'?
IE<9 is crashing on this function due to invisible objects attempting to gain focus, but that's only happening because offsetWidth is non-zero. I don't understand why the embargo is only included if offsetWidth is not 0.

@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.

if offsetWidth is 0 the element is hidden from the user's view and cannot be focused in oldIE. Some other browsers disregard this but it doesn't make sense as far as I can tell.

What is the useful purpose of focusing a non-visible element?

@jquave
Copy link

@jquave jquave commented on 06e56ac Feb 5, 2012

Choose a reason for hiding this comment

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

Of course there is no useful purpose of focusing a non-visible element. The issue I'm having is that this is crashing IE<9 because jquery mobile attempts to focus hidden elements somewhere. (I understand this is not the fault of jquery) I was just curious as to what purpose the offsetWidth condition served. Thank you for explaining.

@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.

I thought that Mobile had fixed the problem in 1.01, I worked with them to find a case where they were first trying to focus an element and then showing it. If you're experiencing a problem be sure there is a ticket with a test case in their tracker.

Please sign in to comment.