wiki.techinc.nl/resources/jquery/jquery.tabIndex.js
Krinkle 0e82a6cfd0 Applying whitespace conventions in core JS files.
* Mostly whitespace in callers: $('foo').bar(baz,quux) => $( 'foo' ).bar( baz, quux )
* Also several occurrences of mixes spaces and tabs in the indention in front of a line, converted to tabs.
* And double spaces -> single spaces at random.
2011-08-12 21:48:10 +00:00

50 lines
1.3 KiB
JavaScript

/**
* jQuery tabIndex
*/
( function( $ ) {
/**
* Finds the lowerst tabindex in use within a selection
*
* @return number Lowest tabindex on the page
*/
$.fn.firstTabIndex = function() {
var minTabIndex = null;
$(this).find( '[tabindex]' ).each( function() {
var tabIndex = parseInt( $(this).prop( 'tabindex' ), 10 );
// In IE6/IE7 the above jQuery selector returns all elements,
// becuase it has a default value for tabIndex in IE6/IE7 of 0
// (rather than null/undefined). Therefore check "> 0" as well.
// Under IE7 under Windows NT 5.2 is also capable of returning NaN.
if ( tabIndex > 0 && !isNaN( tabIndex ) ) {
// Initial value
if ( minTabIndex === null ) {
minTabIndex = tabIndex;
} else if ( tabIndex < minTabIndex ) {
minTabIndex = tabIndex;
}
}
} );
return minTabIndex;
};
/**
* Finds the highest tabindex in use within a selection
*
* @return number Highest tabindex on the page
*/
$.fn.lastTabIndex = function() {
var maxTabIndex = null;
$(this).find( '[tabindex]' ).each( function() {
var tabIndex = parseInt( $(this).prop( 'tabindex' ), 10 );
if ( tabIndex > 0 && !isNaN( tabIndex ) ) {
// Initial value
if ( maxTabIndex === null ) {
maxTabIndex = tabIndex;
} else if ( tabIndex > maxTabIndex ) {
maxTabIndex = tabIndex;
}
}
} );
return maxTabIndex;
};
} )( jQuery );