diff options
author | Scott González <scott.gonzalez@gmail.com> | 2008-09-06 03:44:32 +0000 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2008-09-06 03:44:32 +0000 |
commit | 0b771b43c6aa28a9ccbcb23c826351ea10da5383 (patch) | |
tree | 3c3283e819f044730d9f766603b2c3590702d555 /ui | |
parent | 54eccb6b04303cfaa27fbe3a3ddd1147e5220359 (diff) | |
download | jquery-ui-0b771b43c6aa28a9ccbcb23c826351ea10da5383.tar.gz jquery-ui-0b771b43c6aa28a9ccbcb23c826351ea10da5383.zip |
Core: Improved :tabbable selector
- check tabindex >= 0 instead of != -1
- check anchor tags for href
- check for hidden input types
- check styles (display and visibility; self and ancestors)
Added tests for :tabbable selector
Diffstat (limited to 'ui')
-rw-r--r-- | ui/ui.core.js | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/ui/ui.core.js b/ui/ui.core.js index f4ffb74cb..8507bb193 100644 --- a/ui/ui.core.js +++ b/ui/ui.core.js @@ -17,6 +17,21 @@ $.fn.remove = function() { return _remove.apply(this, arguments ); }; +function isVisible(element) { + function checkStyles(element) { + var style = element.style; + return (style.display != 'none' && style.visibility != 'hidden'); + } + + var visible = checkStyles(element); + + (visible && $.each($.dir(element, 'parentNode'), function() { + return (visible = checkStyles(this)); + })); + + return visible; +} + $.extend($.expr[':'], { data: function(a, i, m) { return $.data(a, m[3]); @@ -28,15 +43,20 @@ $.extend($.expr[':'], { return ( // in tab order - a.tabIndex != -1 && + a.tabIndex >= 0 && - ( // node type participates in tab order + ( // filter node types that participate in the tab order + // anchor tag - ('a' == nodeName) || + ('a' == nodeName && a.href) || // enabled form element - (/input|select|textarea|button/.test(nodeName) && !a.disabled) - ) + (/input|select|textarea|button/.test(nodeName) && + 'hidden' != a.type && !a.disabled) + ) && + + // visible on page + isVisible(a) ); } }); |