From a908ec81a3475f60ab444f1668005d5ebf184156 Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Sat, 6 Jul 2013 17:01:30 +0200 Subject: [PATCH] tablesorter: Keyboard accessibility for sort headers. * Add role=button and tabindex=0 * Handle "Enter" keypresses Change-Id: I2b937eba605b7e6a98612a02c75eb9e7f3477527 --- resources/jquery/jquery.tablesorter.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/resources/jquery/jquery.tablesorter.js b/resources/jquery/jquery.tablesorter.js index 97357d9be9..a231f26fa7 100644 --- a/resources/jquery/jquery.tablesorter.js +++ b/resources/jquery/jquery.tablesorter.js @@ -332,7 +332,10 @@ } 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 @@ -749,10 +752,15 @@ // 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; } -- 2.20.1