]> source.dussan.org Git - jquery-ui.git/commitdiff
Core: reuse tabindex value. Fixed #7257 - optimize :tabbable.
authoradambaratz <adam.baratz@gmail.com>
Fri, 15 Apr 2011 14:51:56 +0000 (07:51 -0700)
committerScott González <scott.gonzalez@gmail.com>
Mon, 2 May 2011 12:36:55 +0000 (08:36 -0400)
(cherry picked from commit fe3b36b8efcabf3d1f1d60523cae87c69a882f27)

ui/jquery.ui.core.js

index 4c199931090139c30080c7f62081535bfa908a36..59fa4d73a2f9c901539290e88b5d74ebbfb8d196 100644 (file)
@@ -174,6 +174,27 @@ $.each( [ "Width", "Height" ], function( i, name ) {
 });
 
 // selectors
+function focusable( element, isTabIndexNotNaN ) {
+       var nodeName = element.nodeName.toLowerCase();
+       if ( "area" === nodeName ) {
+               var map = element.parentNode,
+                       mapName = map.name,
+                       img;
+               if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
+                       return false;
+               }
+               img = $( "img[usemap=#" + mapName + "]" )[0];
+               return !!img && visible( img );
+       }
+       return ( /input|select|textarea|button|object/.test( nodeName )
+               ? !element.disabled
+               : "a" == nodeName
+                       ? element.href || isTabIndexNotNaN
+                       : isTabIndexNotNaN)
+               // the element and all of its ancestors must be visible
+               && visible( element );
+}
+
 function visible( element ) {
        return !$( element ).parents().andSelf().filter(function() {
                return $.curCSS( this, "visibility" ) === "hidden" ||
@@ -187,30 +208,13 @@ $.extend( $.expr[ ":" ], {
        },
 
        focusable: function( element ) {
-               var nodeName = element.nodeName.toLowerCase(),
-                       tabIndex = $.attr( element, "tabindex" );
-               if ( "area" === nodeName ) {
-                       var map = element.parentNode,
-                               mapName = map.name,
-                               img;
-                       if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
-                               return false;
-                       }
-                       img = $( "img[usemap=#" + mapName + "]" )[0];
-                       return !!img && visible( img );
-               }
-               return ( /input|select|textarea|button|object/.test( nodeName )
-                       ? !element.disabled
-                       : "a" == nodeName
-                               ? element.href || !isNaN( tabIndex )
-                               : !isNaN( tabIndex ))
-                       // the element and all of its ancestors must be visible
-                       && visible( element );
+               return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
        },
 
        tabbable: function( element ) {
-               var tabIndex = $.attr( element, "tabindex" );
-               return ( isNaN( tabIndex ) || tabIndex >= 0 ) && $( element ).is( ":focusable" );
+               var tabIndex = $.attr( element, "tabindex" ),
+                       isTabIndexNaN = isNaN( tabIndex );
+               return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
        }
 });