mediawiki.util.test.js: IE7 doesn't expose the CSSStyleSheet publicly (like it doesn...
[mediawiki.git] / resources / jquery / jquery.tabIndex.js
blob4c406772a46c96aa168bb7eb5b0cf9aead3ae457
1 /**
2  * jQuery tabIndex
3  */
4 ( function( $ ) {
5 /**
6  * Finds the lowerst tabindex in use within a selection
7  * 
8  * @return number Lowest tabindex on the page
9  */
10 $.fn.firstTabIndex = function() {
11         var minTabIndex = null;
12         $(this).find( '[tabindex]' ).each( function( i ) {
13                 var tabIndex = parseInt( $(this).attr( 'tabindex' ), 10 );
14                 // In IE6/IE7 the above jQuery selector returns all elements,
15                 // becuase it has a default value for tabIndex in IE6/IE7 of 0
16                 // (rather than null/undefined). Therefore check "> 0" as well
17                 if ( tabIndex > 0 ) {
18                         if ( minTabIndex === null ) {
19                                 minTabIndex = tabIndex;
20                         } else if ( tabIndex < minTabIndex ) {
21                                 minTabIndex = tabIndex;
22                         }
23                 }
24         } );
25         return minTabIndex;
28 /**
29  * Finds the highest tabindex in use within a selection
30  * 
31  * @return number Highest tabindex on the page
32  */
33 $.fn.lastTabIndex = function() {
34         var maxTabIndex = null;
35         $(this).find( '[tabindex]' ).each( function( i ) {
36                 var tabIndex = parseInt( $(this).attr( 'tabindex' ), 10 );
37                 if ( maxTabIndex === null ) {
38                         maxTabIndex = tabIndex;
39                 } else if ( tabIndex > maxTabIndex ) {
40                         maxTabIndex = tabIndex;
41                 }
42         } );
43         return maxTabIndex;
45 } )( jQuery );