Created
February 14, 2014 16:17
-
-
Save camerond/9003958 to your computer and use it in GitHub Desktop.
$(':absfocus') selector for inactive windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Finds focused elements on page even if the browser window isn't active. | |
// Useful for headless testing or QUnit tests or whatever. | |
// | |
// I couldn't get https://github.com/mattheworiordan/jquery-focus-selenium-webkit-fix | |
// to behave in jQuery 2.0, so this is a secondary selector created using | |
// Sizzle's (relatively) new createPseudo method. | |
// | |
// I'd prefer to rewrite :focus but couldn't get that to work either. | |
// Look, this works and I'm moving on. | |
jQuery.expr[":"].absfocus = jQuery.expr.createPseudo(function() { | |
return function(elem) { | |
var doc = elem.ownerDocument; | |
return elem === doc.activeElement && !!(elem.type || elem.href); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment