Permalink
Browse files
Check document focus and type/href attributes when determining :focus…
…. Fixes #10809. Add support for the :active pseudo selector.
- Loading branch information...
Showing
with
18 additions
and 4 deletions.
- +7 −1 sizzle.js
- +11 −3 test/unit/selector.js
| @@ -752,7 +752,7 @@ var Expr = Sizzle.selectors = { | ||
| match[3] = select(match[3], document, [], curLoop, isXML); | ||
| } else { | ||
| - var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not); | ||
| + var ret = Sizzle.filter(match[3], curLoop, inplace, !not); | ||
| if ( !inplace ) { | ||
| result.push.apply( result, ret ); | ||
| @@ -861,9 +861,15 @@ var Expr = Sizzle.selectors = { | ||
| }, | ||
| focus: function( elem ) { | ||
|
timmywil
Elements that support tabindex have a type or href property. As far as accessing activeElement throwing an error, I wonder if it is worth adding a try/catch in core for such an edge case.
aFarkas
timmywil
aFarkas
I think, you can build a simple test by testing $('input').is(':focus'); inside an iframed document as soon as possible.
The error is thrown, if the "parentDocument" hasn't finished loading or the iframed document has no focus (I'm not really sure). Normally this bug occurs, if you check :focus on DOM ready. Something about 1: Microsoft has introduced this with IE5 and all other browsers have integrated this feature about 2-3 years ago. |
||
| + var doc = elem.ownerDocument; | ||
| + return elem === doc.activeElement && (!doc.hasFocus || doc.hasFocus()) && !!(elem.type || elem.href); | ||
| + }, | ||
| + | ||
| + active: function( elem ) { | ||
| return elem === elem.ownerDocument.activeElement; | ||
| } | ||
| }, | ||
| + | ||
| setFilters: { | ||
| first: function( elem, i ) { | ||
| return i === 0; | ||
I'm not sure wether this fix is right.