tablesorter: Keyboard accessibility for sort headers.
authorDerk-Jan Hartman <hartman@videolan.org>
Sat, 6 Jul 2013 15:01:30 +0000 (17:01 +0200)
committerMatmaRex <matma.rex@gmail.com>
Tue, 9 Jul 2013 12:17:01 +0000 (14:17 +0200)
* Add role=button and tabindex=0
* Handle "Enter" keypresses

Change-Id: I2b937eba605b7e6a98612a02c75eb9e7f3477527

resources/jquery/jquery.tablesorter.js

index 97357d9..a231f26 100644 (file)
                        }
 
                        if ( !this.sortDisabled ) {
-                               $( this ).addClass( table.config.cssHeader ).attr( 'title', msg[1] );
+                               $( this )
+                                       .addClass( table.config.cssHeader )
+                                       .attr( 'title', msg[1] )
+                                       .prop( 'tabIndex', 0 ).attr( 'role', 'button' );
                        }
 
                        // add cell to headerList
 
                                        // Apply event handling to headers
                                        // this is too big, perhaps break it out?
-                                       $headers.filter( ':not(.unsortable)' ).click( function ( e ) {
-                                               if ( e.target.nodeName.toLowerCase() === 'a' ) {
-                                                       // The user clicked on a link inside a table header
-                                                       // Do nothing and let the default link click action continue
+                                       $headers.filter( ':not(.unsortable)' ).on( 'keypress click', function ( e ) {
+                                               if ( e.type === 'click' && e.target.nodeName.toLowerCase() === 'a' ) {
+                                                       // The user clicked on a link inside a table header.
+                                                       // Do nothing and let the default link click action continue.
+                                                       return true;
+                                               }
+
+                                               if ( e.type === 'keypress' && e.which !== 13 ) {
+                                                       // Only handle keypresses on the "Enter" key.
                                                        return true;
                                                }