From: Derk-Jan Hartman Date: Sat, 6 Jul 2013 15:01:30 +0000 (+0200) Subject: tablesorter: Keyboard accessibility for sort headers. X-Git-Tag: 1.31.0-rc.0~19141^2 X-Git-Url: http://git.cyclocoop.org//%22%22.str_replace%28%27%22%27%2C?a=commitdiff_plain;h=a908ec81a3475f60ab444f1668005d5ebf184156;p=lhc%2Fweb%2Fwiklou.git tablesorter: Keyboard accessibility for sort headers. * Add role=button and tabindex=0 * Handle "Enter" keypresses Change-Id: I2b937eba605b7e6a98612a02c75eb9e7f3477527 --- 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; }