(bug 34702) More localised parentheses.
[mediawiki.git] / resources / jquery / jquery.tabIndex.js
blob75731d7ceeea3774b6fd903f902561a4cc62b4e9
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() {
13                 var tabIndex = parseInt( $(this).prop( '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                 // Under IE7 under Windows NT 5.2 is also capable of returning NaN.
18                 if ( tabIndex > 0 && !isNaN( tabIndex ) ) {
19                         // Initial value
20                         if ( minTabIndex === null ) {
21                                 minTabIndex = tabIndex;
22                         } else if ( tabIndex < minTabIndex ) {
23                                 minTabIndex = tabIndex;
24                         }
25                 }
26         } );
27         return minTabIndex;
30 /**
31  * Finds the highest tabindex in use within a selection
32  *
33  * @return number Highest tabindex on the page
34  */
35 $.fn.lastTabIndex = function() {
36         var maxTabIndex = null;
37         $(this).find( '[tabindex]' ).each( function() {
38                 var tabIndex = parseInt( $(this).prop( 'tabindex' ), 10 );
39                 if ( tabIndex > 0 && !isNaN( tabIndex ) ) {
40                         // Initial value
41                         if ( maxTabIndex === null ) {
42                                 maxTabIndex = tabIndex;
43                         } else if ( tabIndex > maxTabIndex ) {
44                                 maxTabIndex = tabIndex;
45                         }
46                 }
47         } );
48         return maxTabIndex;
50 } )( jQuery );