summaryrefslogtreecommitdiff
path: root/resources/src/jquery/jquery.tabIndex.js
blob: ed37aa1ea3c9b56fb34891692ffdfd6c7fa8e461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
 * @class jQuery.plugin.tabIndex
 */
( function ( $ ) {

	/**
	 * Find the lowest 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;
	};

	/**
	 * Find 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;
	};

	/**
	 * @class jQuery
	 * @mixins jQuery.plugin.tabIndex
	 */

}( jQuery ) );