From 0b771b43c6aa28a9ccbcb23c826351ea10da5383 Mon Sep 17 00:00:00 2001 From: Scott González Date: Sat, 6 Sep 2008 03:44:32 +0000 Subject: 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 --- ui/ui.core.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'ui') 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) ); } }); -- cgit v1.2.3