Redo r89605 in a better way.
[lhc/web/wiklou.git] / resources / jquery / jquery.tabIndex.js
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 ( i === 0 ) {
19 minTabIndex = tabIndex;
20 } else if ( tabIndex < minTabIndex ) {
21 minTabIndex = tabIndex;
22 }
23 }
24 } );
25 return minTabIndex;
26 };
27
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 ( i === 0 ) {
38 maxTabIndex = tabIndex;
39 } else if ( tabIndex > maxTabIndex ) {
40 maxTabIndex = tabIndex;
41 }
42 } );
43 return maxTabIndex;
44 };
45 } )( jQuery );