* @return number Lowest tabindex on the page
*/
$.fn.firstTabIndex = function() {
- var minTabIndex = 0;
- $(this).find( '[tabindex]' ).each( function() {
+ var minTabIndex = null;
+ $(this).find( '[tabindex]' ).each( function( i ) {
var tabIndex = parseInt( $(this).attr( 'tabindex' ), 10 );
- if ( tabIndex > minTabIndex ) {
+ if ( i === 0 ) {
+ minTabIndex = tabIndex;
+ } else if ( tabIndex < minTabIndex ) {
minTabIndex = tabIndex;
}
} );
* @return number Highest tabindex on the page
*/
$.fn.lastTabIndex = function() {
- var maxTabIndex = 0;
- $(this).find( '[tabindex]' ).each( function() {
+ var maxTabIndex = null;
+ $(this).find( '[tabindex]' ).each( function( i ) {
var tabIndex = parseInt( $(this).attr( 'tabindex' ), 10 );
- if ( tabIndex > maxTabIndex ) {
+ if ( i === 0 ) {
+ maxTabIndex = tabIndex;
+ } else if ( tabIndex > maxTabIndex ) {
maxTabIndex = tabIndex;
}
} );
return maxTabIndex;
};
-} )( jQuery );
\ No newline at end of file
+} )( jQuery );
<script src="suites/resources/jquery/jquery.mwPrototypes.js"></script>
<script src="suites/resources/mediawiki.util/mediawiki.util.js"></script>
<script src="suites/resources/jquery/jquery.autoEllipsis.js"></script>
+ <script src="suites/resources/jquery/jquery.colorUtil.js"></script>
<script src="suites/resources/jquery/jquery.tabIndex.js"></script>
<!-- TestSwarm: If a test swarm is running this,
var testEnvironment =
'<form>\
<input tabindex="7" />\
- <input tabindex="2" />\
- <textarea tabindex="9">Foobar</textarea>\
+ <input tabindex="9" />\
+ <textarea tabindex="2">Foobar</textarea>\
+ <textarea tabindex="5">Foobar</textarea>\
</form>';
- var $test = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
+ var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
- deepEqual( $test.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
+ deepEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
+
+ var $testB = $( '<div />' );
+
+ deepEqual( $testB.firstTabIndex(), null, 'Return null if none available.' );
// Clean up
- $test.remove();
+ $testA.add( $testB).remove();
});
test( 'lastTabIndex', function(){
var testEnvironment =
'<form>\
<input tabindex="7" />\
- <input tabindex="2" />\
- <textarea tabindex="9">Foobar</textarea>\
+ <input tabindex="9" />\
+ <textarea tabindex="2">Foobar</textarea>\
+ <textarea tabindex="5">Foobar</textarea>\
</form>';
- var $test = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
+ var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
+
+ deepEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
+
+ var $testB = $( '<div />' );
- deepEqual( $test.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
+ deepEqual( $testB.lastTabIndex(), null, 'Return null if none available.' );
// Clean up
- $test.remove();
+ $testA.add( $testB).remove();
});
\ No newline at end of file