Fixed tabindex normalization so that elements that natively support tabbing, but don't have a tabindex explicitly set return 0 instead of undefined.

Removed jQuery.support.tabindex since we're only normalizing non-XML right now and all browsers support tabIndex for HTML documents.
This commit is contained in:
Scott González 2009-01-07 14:36:30 +00:00
parent f9e0b1ed7a
commit 49d0d5b7a3
3 changed files with 17 additions and 17 deletions

View file

@ -968,11 +968,15 @@ jQuery.extend({
if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
return elem.getAttributeNode( name ).nodeValue; return elem.getAttributeNode( name ).nodeValue;
// elem.tabindex doesn't always return the correct value // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
if ( name == jQuery.props.tabindex ) { if ( name == "tabIndex" ) {
var attributeNode = elem.getAttributeNode(jQuery.props.tabindex); var attributeNode = elem.getAttributeNode( "tabIndex" );
return attributeNode && attributeNode.specified && attributeNode.value || undefined; return attributeNode && attributeNode.specified
? attributeNode.value
: elem.nodeName.match(/^(a|area|button|input|object|select|textarea)$/i)
? 0
: undefined;
} }
return elem[ name ]; return elem[ name ];

View file

@ -51,10 +51,6 @@
// (IE uses styleFloat instead of cssFloat) // (IE uses styleFloat instead of cssFloat)
cssFloat: !!a.style.cssFloat, cssFloat: !!a.style.cssFloat,
// Verify tabindex attribute existence
// (IE uses tabIndex instead of tabindex)
tabindex: !a.getAttributeNode('tabindex'),
// Will be defined later // Will be defined later
scriptEval: false, scriptEval: false,
noCloneEvent: true noCloneEvent: true
@ -101,5 +97,5 @@ jQuery.props = {
maxlength: "maxLength", maxlength: "maxLength",
cellspacing: "cellSpacing", cellspacing: "cellSpacing",
rowspan: "rowSpan", rowspan: "rowSpan",
tabindex: jQuery.support.tabindex ? "tabindex" : "tabIndex" tabindex: "tabIndex"
}; };

View file

@ -562,7 +562,7 @@ test("attr('tabindex')", function() {
equals(jQuery('#divWithNoTabIndex').attr('tabindex'), undefined, 'no tabindex, not tabbable by default'); equals(jQuery('#divWithNoTabIndex').attr('tabindex'), undefined, 'no tabindex, not tabbable by default');
// link without a tabindex // link without a tabindex
equals(jQuery('#linkWithNoTabIndex').attr('tabindex'), undefined, 'no tabindex, tabbable by default'); equals(jQuery('#linkWithNoTabIndex').attr('tabindex'), 0, 'no tabindex, tabbable by default');
}); });
test("attr('tabindex', value)", function() { test("attr('tabindex', value)", function() {