Fix bug that brakes the 'jquery.tabIndex > firstTabIndex' test in IE6/IE7 (Thanks...
[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 if ( i === 0 ) {
15 minTabIndex = tabIndex;
16 // In IE6/IE7 the above jQuery selector returns all elements,
17 // becuase it has a default value for tabIndex in IE6/IE7 of 0
18 // (rather than null/undefined). Therefore check "> 0" as well
19 } else if ( tabIndex > 0 && tabIndex < minTabIndex ) {
20 minTabIndex = tabIndex;
21 }
22 } );
23 return minTabIndex;
24 };
25
26 /**
27 * Finds the highest tabindex in use within a selection
28 *
29 * @return number Highest tabindex on the page
30 */
31 $.fn.lastTabIndex = function() {
32 var maxTabIndex = null;
33 $(this).find( '[tabindex]' ).each( function( i ) {
34 var tabIndex = parseInt( $(this).attr( 'tabindex' ), 10 );
35 if ( i === 0 ) {
36 maxTabIndex = tabIndex;
37 } else if ( tabIndex > maxTabIndex ) {
38 maxTabIndex = tabIndex;
39 }
40 } );
41 return maxTabIndex;
42 };
43 } )( jQuery );