]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - resources/src/jquery/jquery.tabIndex.js
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / resources / src / jquery / jquery.tabIndex.js
1 /**
2  * @class jQuery.plugin.tabIndex
3  */
4 ( function ( $ ) {
5
6         /**
7          * Find the lowest tabindex in use within a selection.
8          *
9          * @return {number} Lowest tabindex on the page
10          */
11         $.fn.firstTabIndex = function () {
12                 var minTabIndex = null;
13                 $( this ).find( '[tabindex]' ).each( function () {
14                         var tabIndex = parseInt( $( this ).prop( 'tabindex' ), 10 );
15                         // In IE6/IE7 the above jQuery selector returns all elements,
16                         // becuase it has a default value for tabIndex in IE6/IE7 of 0
17                         // (rather than null/undefined). Therefore check "> 0" as well.
18                         // Under IE7 under Windows NT 5.2 is also capable of returning NaN.
19                         if ( tabIndex > 0 && !isNaN( tabIndex ) ) {
20                                 // Initial value
21                                 if ( minTabIndex === null ) {
22                                         minTabIndex = tabIndex;
23                                 } else if ( tabIndex < minTabIndex ) {
24                                         minTabIndex = tabIndex;
25                                 }
26                         }
27                 } );
28                 return minTabIndex;
29         };
30
31         /**
32          * Find the highest tabindex in use within a selection.
33          *
34          * @return {number} Highest tabindex on the page
35          */
36         $.fn.lastTabIndex = function () {
37                 var maxTabIndex = null;
38                 $( this ).find( '[tabindex]' ).each( function () {
39                         var tabIndex = parseInt( $( this ).prop( 'tabindex' ), 10 );
40                         if ( tabIndex > 0 && !isNaN( tabIndex ) ) {
41                                 // Initial value
42                                 if ( maxTabIndex === null ) {
43                                         maxTabIndex = tabIndex;
44                                 } else if ( tabIndex > maxTabIndex ) {
45                                         maxTabIndex = tabIndex;
46                                 }
47                         }
48                 } );
49                 return maxTabIndex;
50         };
51
52         /**
53          * @class jQuery
54          * @mixins jQuery.plugin.tabIndex
55          */
56
57 }( jQuery ) );