mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Selector: Wrap activeElement access in try-catch
In IE 9 accessing `document.activeElement` may throw; see https://bugs.jquery.com/ticket/13393. We've already guarded against this in event code but not in selector. Closes gh-5229
This commit is contained in:
parent
754108fbbf
commit
3936cf3ef3
@ -163,6 +163,17 @@ var i,
|
|||||||
{ dir: "parentNode", next: "legend" }
|
{ dir: "parentNode", next: "legend" }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Support: IE <=9 only
|
||||||
|
// Accessing document.activeElement can throw unexpectedly
|
||||||
|
// https://bugs.jquery.com/ticket/13393
|
||||||
|
// An identical function exists in `src/event.js` but they use different
|
||||||
|
// `documents` so it cannot be easily extracted.
|
||||||
|
function safeActiveElement() {
|
||||||
|
try {
|
||||||
|
return document.activeElement;
|
||||||
|
} catch ( err ) { }
|
||||||
|
}
|
||||||
|
|
||||||
// Optimize for push.apply( _, NodeList )
|
// Optimize for push.apply( _, NodeList )
|
||||||
try {
|
try {
|
||||||
push.apply(
|
push.apply(
|
||||||
@ -1316,7 +1327,7 @@ Expr = jQuery.expr = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
focus: function( elem ) {
|
focus: function( elem ) {
|
||||||
return elem === document.activeElement &&
|
return elem === safeActiveElement() &&
|
||||||
document.hasFocus() &&
|
document.hasFocus() &&
|
||||||
!!( elem.type || elem.href || ~elem.tabIndex );
|
!!( elem.type || elem.href || ~elem.tabIndex );
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user