Index: trunk/phase3/tests/qunit/index.html |
— | — | @@ -47,6 +47,7 @@ |
48 | 48 | <script src="suites/resources/jquery/jquery.mwPrototypes.js"></script> |
49 | 49 | <script src="suites/resources/mediawiki.util/mediawiki.util.js"></script> |
50 | 50 | <script src="suites/resources/jquery/jquery.autoEllipsis.js"></script> |
| 51 | + <script src="suites/resources/jquery/jquery.colorUtil.js"></script> |
51 | 52 | <script src="suites/resources/jquery/jquery.tabIndex.js"></script> |
52 | 53 | |
53 | 54 | <!-- TestSwarm: If a test swarm is running this, |
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tabIndex.js |
— | — | @@ -12,15 +12,20 @@ |
13 | 13 | var testEnvironment = |
14 | 14 | '<form>\ |
15 | 15 | <input tabindex="7" />\ |
16 | | - <input tabindex="2" />\ |
17 | | - <textarea tabindex="9">Foobar</textarea>\ |
| 16 | + <input tabindex="9" />\ |
| 17 | + <textarea tabindex="2">Foobar</textarea>\ |
| 18 | + <textarea tabindex="5">Foobar</textarea>\ |
18 | 19 | </form>'; |
19 | | - var $test = $( '<div />' ).html( testEnvironment ).appendTo( 'body' ); |
| 20 | + var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' ); |
20 | 21 | |
21 | | - deepEqual( $test.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' ); |
| 22 | + deepEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' ); |
22 | 23 | |
| 24 | + var $testB = $( '<div />' ); |
| 25 | + |
| 26 | + deepEqual( $testB.firstTabIndex(), null, 'Return null if none available.' ); |
| 27 | + |
23 | 28 | // Clean up |
24 | | - $test.remove(); |
| 29 | + $testA.add( $testB).remove(); |
25 | 30 | }); |
26 | 31 | |
27 | 32 | test( 'lastTabIndex', function(){ |
— | — | @@ -28,13 +33,18 @@ |
29 | 34 | var testEnvironment = |
30 | 35 | '<form>\ |
31 | 36 | <input tabindex="7" />\ |
32 | | - <input tabindex="2" />\ |
33 | | - <textarea tabindex="9">Foobar</textarea>\ |
| 37 | + <input tabindex="9" />\ |
| 38 | + <textarea tabindex="2">Foobar</textarea>\ |
| 39 | + <textarea tabindex="5">Foobar</textarea>\ |
34 | 40 | </form>'; |
35 | | - var $test = $( '<div />' ).html( testEnvironment ).appendTo( 'body' ); |
| 41 | + var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' ); |
36 | 42 | |
37 | | - deepEqual( $test.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' ); |
| 43 | + deepEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' ); |
38 | 44 | |
| 45 | + var $testB = $( '<div />' ); |
| 46 | + |
| 47 | + deepEqual( $testB.lastTabIndex(), null, 'Return null if none available.' ); |
| 48 | + |
39 | 49 | // Clean up |
40 | | - $test.remove(); |
| 50 | + $testA.add( $testB).remove(); |
41 | 51 | }); |
\ No newline at end of file |
Index: trunk/phase3/resources/jquery/jquery.tabIndex.js |
— | — | @@ -8,11 +8,13 @@ |
9 | 9 | * @return number Lowest tabindex on the page |
10 | 10 | */ |
11 | 11 | $.fn.firstTabIndex = function() { |
12 | | - var minTabIndex = 0; |
13 | | - $(this).find( '[tabindex]' ).each( function() { |
| 12 | + var minTabIndex = null; |
| 13 | + $(this).find( '[tabindex]' ).each( function( i ) { |
14 | 14 | var tabIndex = parseInt( $(this).attr( 'tabindex' ), 10 ); |
15 | | - if ( tabIndex > minTabIndex ) { |
| 15 | + if ( i === 0 ) { |
16 | 16 | minTabIndex = tabIndex; |
| 17 | + } else if ( tabIndex < minTabIndex ) { |
| 18 | + minTabIndex = tabIndex; |
17 | 19 | } |
18 | 20 | } ); |
19 | 21 | return minTabIndex; |
— | — | @@ -24,13 +26,15 @@ |
25 | 27 | * @return number Highest tabindex on the page |
26 | 28 | */ |
27 | 29 | $.fn.lastTabIndex = function() { |
28 | | - var maxTabIndex = 0; |
29 | | - $(this).find( '[tabindex]' ).each( function() { |
| 30 | + var maxTabIndex = null; |
| 31 | + $(this).find( '[tabindex]' ).each( function( i ) { |
30 | 32 | var tabIndex = parseInt( $(this).attr( 'tabindex' ), 10 ); |
31 | | - if ( tabIndex > maxTabIndex ) { |
| 33 | + if ( i === 0 ) { |
32 | 34 | maxTabIndex = tabIndex; |
| 35 | + } else if ( tabIndex > maxTabIndex ) { |
| 36 | + maxTabIndex = tabIndex; |
33 | 37 | } |
34 | 38 | } ); |
35 | 39 | return maxTabIndex; |
36 | 40 | }; |
37 | | -} )( jQuery ); |
\ No newline at end of file |
| 41 | +} )( jQuery ); |