aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Gaidarenko <markelog@gmail.com>2013-04-08 21:33:17 -0400
committerTimmy Willison <timmywillisn@gmail.com>2013-04-08 21:33:17 -0400
commitf1ba486ee3faeb70faeec1688b79ed085dd6a102 (patch)
tree12eb4c8dd3ee88d4eb78e448c3c9e4c11caa1cd3
parent52394ba986794423e7855ece3b4f80a1f2fb7398 (diff)
downloadjquery-f1ba486ee3faeb70faeec1688b79ed085dd6a102.tar.gz
jquery-f1ba486ee3faeb70faeec1688b79ed085dd6a102.zip
Adjust tabIndex propHook for modern browsers and return -1 where appropriate. Close gh-1228.
-rw-r--r--src/attributes.js33
-rw-r--r--test/index.html6
-rw-r--r--test/unit/attributes.js13
3 files changed, 25 insertions, 27 deletions
diff --git a/src/attributes.js b/src/attributes.js
index b68f773d8..4aabcfc1b 100644
--- a/src/attributes.js
+++ b/src/attributes.js
@@ -1,8 +1,7 @@
var nodeHook, boolHook,
rclass = /[\t\r\n]/g,
rreturn = /\r/g,
- rfocusable = /^(?:input|select|textarea|button|object)$/i,
- rclickable = /^(?:a|area)$/i;
+ rfocusable = /^(?:input|select|textarea|button)$/i;
jQuery.fn.extend({
attr: function( name, value ) {
@@ -395,35 +394,23 @@ jQuery.extend({
}
if ( value !== undefined ) {
- if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
- return ret;
-
- } else {
- return ( elem[ name ] = value );
- }
+ return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
+ ret :
+ ( elem[ name ] = value );
} else {
- if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
- return ret;
-
- } else {
- return elem[ name ];
- }
+ return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
+ ret :
+ elem[ name ];
}
},
propHooks: {
tabIndex: {
get: function( elem ) {
- // 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/
- var attributeNode = elem.getAttributeNode("tabindex");
-
- return attributeNode && attributeNode.specified ?
- parseInt( attributeNode.value, 10 ) :
- rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
- 0 :
- undefined;
+ return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
+ elem.tabIndex :
+ -1;
}
}
}
diff --git a/test/index.html b/test/index.html
index cf9590a61..07cae2ccb 100644
--- a/test/index.html
+++ b/test/index.html
@@ -273,6 +273,12 @@ Z</textarea>
<span>...</span><a id="linkWithNoHrefWithNoTabIndex">Eat a burger</a><span>...</span>
<span>...</span><a id="linkWithNoHrefWithTabIndex" tabindex="1">Eat some funyuns</a><span>...</span>
<span>...</span><a id="linkWithNoHrefWithNegativeTabIndex" tabindex="-1">Eat some funyuns</a><span>...</span>
+ <input id="inputWithoutTabIndex"/>
+ <button id="buttonWithoutTabIndex"></button>
+ <textarea id="textareaWithoutTabIndex"></textarea>
+ <menu type="popup">
+ <menuitem id="menuitemWithoutTabIndex" command="submitbutton" default/>
+ </menu>
</div>
<div id="liveHandlerOrder">
diff --git a/test/unit/attributes.js b/test/unit/attributes.js
index e7145730b..335927b35 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -683,11 +683,16 @@ test( "prop(String, Object)", function() {
});
test( "prop('tabindex')", function() {
- expect( 8 );
+ expect( 11 );
+
+ // inputs without tabIndex attribute
+ equal( jQuery("#inputWithoutTabIndex").prop("tabindex"), 0, "input without tabindex" );
+ equal( jQuery("#buttonWithoutTabIndex").prop("tabindex"), 0, "button without tabindex" );
+ equal( jQuery("#textareaWithoutTabIndex").prop("tabindex"), 0, "textarea without tabindex" );
// elements not natively tabbable
equal( jQuery("#listWithTabIndex").prop("tabindex"), 5, "not natively tabbable, with tabindex set to 0" );
- equal( jQuery("#divWithNoTabIndex").prop("tabindex"), undefined, "not natively tabbable, no tabindex set" );
+ equal( jQuery("#divWithNoTabIndex").prop("tabindex"), -1, "not natively tabbable, no tabindex set" );
// anchor with href
equal( jQuery("#linkWithNoTabIndex").prop("tabindex"), 0, "anchor with href, no tabindex set" );
@@ -695,7 +700,7 @@ test( "prop('tabindex')", function() {
equal( jQuery("#linkWithNegativeTabIndex").prop("tabindex"), -1, "anchor with href, tabindex set to -1" );
// anchor without href
- equal( jQuery("#linkWithNoHrefWithNoTabIndex").prop("tabindex"), undefined, "anchor without href, no tabindex set" );
+ equal( jQuery("#linkWithNoHrefWithNoTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" );
equal( jQuery("#linkWithNoHrefWithTabIndex").prop("tabindex"), 1, "anchor without href, tabindex set to 2" );
equal( jQuery("#linkWithNoHrefWithNegativeTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" );
});
@@ -705,7 +710,7 @@ test( "prop('tabindex', value)", 10, function() {
var clone,
element = jQuery("#divWithNoTabIndex");
- equal( element.prop("tabindex"), undefined, "start with no tabindex" );
+ equal( element.prop("tabindex"), -1, "start with no tabindex" );
// set a positive string
element.prop( "tabindex", "1" );