aboutsummaryrefslogtreecommitdiffstats
path: root/ui/ui.core.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2009-01-21 03:25:02 +0000
committerScott González <scott.gonzalez@gmail.com>2009-01-21 03:25:02 +0000
commitf80d9eb465e428b3900bc0b741392f14ecd859f0 (patch)
treed7e62555d0ebc4c05bf3ec881bff78428ade71c5 /ui/ui.core.js
parentdebb342662dd669224e56e358e87fc37605b9d70 (diff)
downloadjquery-ui-f80d9eb465e428b3900bc0b741392f14ecd859f0.tar.gz
jquery-ui-f80d9eb465e428b3900bc0b741392f14ecd859f0.zip
Core: Partial fix for #3559: Proper implementation for :focusable and :tabbable selectors.
Diffstat (limited to 'ui/ui.core.js')
-rw-r--r--ui/ui.core.js38
1 files changed, 15 insertions, 23 deletions
diff --git a/ui/ui.core.js b/ui/ui.core.js
index 7185ee38e..ce93ee778 100644
--- a/ui/ui.core.js
+++ b/ui/ui.core.js
@@ -199,30 +199,22 @@ $.extend($.expr[':'], {
return !!$.data(elem, match[3]);
},
- // TODO: add support for object, area
- tabbable: function(elem) {
- var nodeName = elem.nodeName.toLowerCase();
- function isVisible(element) {
- return !($(element).is(':hidden') || $(element).parents(':hidden').length);
- }
-
- return (
- // in tab order
- elem.tabIndex >= 0 &&
-
- ( // filter node types that participate in the tab order
-
- // anchor tag
- ('a' == nodeName && elem.href) ||
-
- // enabled form element
- (/input|select|textarea|button/.test(nodeName) &&
- 'hidden' != elem.type && !elem.disabled)
- ) &&
+ focusable: function(element) {
+ var nodeName = element.nodeName.toLowerCase(),
+ tabIndex = $.attr(element, 'tabindex');
+ return (/input|select|textarea|button|object/.test(nodeName)
+ ? !element.disabled
+ : 'a' == nodeName || 'area' == nodeName
+ ? element.href || !isNaN(tabIndex)
+ : !isNaN(tabIndex))
+ // the element and all of its ancestors must be visible
+ // the browser may report that the area is hidden
+ && !$(element)['area' == nodeName ? 'parents' : 'closest'](':hidden').length;
+ },
- // visible on page
- isVisible(elem)
- );
+ tabbable: function(element) {
+ var tabIndex = $.attr(element, 'tabindex');
+ return (isNaN(tabIndex) || tabIndex >= 0) && $(element).is(':focusable');
}
});