Created
December 24, 2013 14:58
-
-
Save karlgroves/8114409 to your computer and use it in GitHub Desktop.
Found this and thought it looked interesting. I saw it at http://test.cita.illinois.edu/aria/tabpanel/tabpanel2.php#lsc1 and in that page they cite "ajpiano on the jQuery forums." Untested but seems sane
This file contains hidden or 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
// focusable is a small jQuery extension to add a :focusable selector. Credit to ajpiano on the jQuery forums. | |
// | |
$.extend($.expr[':'], { | |
focusable: function(element) { | |
var nodeName = element.nodeName.toLowerCase(); | |
var tabIndex = $(element).attr('tabindex'); | |
// the element and all of its ancestors must be visible | |
if (($(element)[(nodeName == 'area' ? 'parents' : 'closest')](':hidden').length) == true) { | |
return false; | |
} | |
// If tabindex is defined, its value must be greater than or equal to 0 | |
if (!isNaN(tabIndex) && tabIndex < 0) { | |
return false; | |
} | |
// if the element is a standard form control, it must not be disabled | |
if (/input|select|textarea|button|object/.test(nodeName) == true) { | |
return !element.disabled; | |
} | |
// if the element is a link, href must be defined | |
if ((nodeName == 'a' || nodeName == 'area') == true) { | |
return (element.href.length > 0); | |
} | |
// this is some other page element that is not normally focusable. | |
return false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment