mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Added in keyboard access
This commit is contained in:
parent
6e5351d104
commit
a582eda64d
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
/*jshint browser:true, jquery:true, unused:false, expr: true */
|
/*jshint browser:true, jquery:true, unused:false, expr: true */
|
||||||
/*global console:false, alert:false */
|
/*global console:false, alert:false */
|
||||||
|
|
||||||
!(function($) {
|
!(function($) {
|
||||||
"use strict";
|
"use strict";
|
||||||
$.extend({
|
$.extend({
|
||||||
@ -407,6 +408,8 @@
|
|||||||
c.headerList[index] = this;
|
c.headerList[index] = this;
|
||||||
// add to parent in case there are multiple rows
|
// add to parent in case there are multiple rows
|
||||||
$t.parent().addClass(c.cssHeaderRow);
|
$t.parent().addClass(c.cssHeaderRow);
|
||||||
|
// allow keyboard cursor to focus on element
|
||||||
|
$t.attr("tabindex", 0);
|
||||||
});
|
});
|
||||||
// enable/disable sorting
|
// enable/disable sorting
|
||||||
updateHeader(table);
|
updateHeader(table);
|
||||||
@ -665,19 +668,25 @@
|
|||||||
c.$headers
|
c.$headers
|
||||||
// http://stackoverflow.com/questions/5312849/jquery-find-self;
|
// http://stackoverflow.com/questions/5312849/jquery-find-self;
|
||||||
.find(c.selectorSort).add( c.$headers.filter(c.selectorSort) )
|
.find(c.selectorSort).add( c.$headers.filter(c.selectorSort) )
|
||||||
.unbind('mousedown.tablesorter mouseup.tablesorter sort.tablesorter')
|
.unbind('mousedown.tablesorter mouseup.tablesorter sort.tablesorter keypress.tablesorter')
|
||||||
.bind('mousedown.tablesorter mouseup.tablesorter sort.tablesorter', function(e, external) {
|
.bind('mousedown.tablesorter mouseup.tablesorter sort.tablesorter keypress.tablesorter', function(e, external) {
|
||||||
|
if (e.keyCode && e.keyCode !== 13) { return; }
|
||||||
// jQuery v1.2.6 doesn't have closest()
|
// jQuery v1.2.6 doesn't have closest()
|
||||||
var $cell = /TH|TD/.test(this.tagName) ? $(this) : $(this).parents('th, td').filter(':last'), cell = $cell[0];
|
var $cell = /TH|TD/.test(this.tagName) ? $(this) : $(this).parents('th, td').filter(':last'), cell = $cell[0];
|
||||||
// only recognize left clicks
|
// only recognize left clicks or enter
|
||||||
if ((e.which || e.button) !== 1 && e.type !== 'sort') { return false; }
|
if (e.keyCode) {
|
||||||
|
if (e.keyCode !== 13) { return false; }
|
||||||
|
}
|
||||||
|
else if ( (e.which || e.button) !== 1 && e.type !== 'sort') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// set timer on mousedown
|
// set timer on mousedown
|
||||||
if (e.type === 'mousedown') {
|
if (e.type === 'mousedown') {
|
||||||
downTime = new Date().getTime();
|
downTime = new Date().getTime();
|
||||||
return e.target.tagName === "INPUT" ? '' : !c.cancelSelection;
|
return e.target.tagName === "INPUT" ? '' : !c.cancelSelection;
|
||||||
}
|
}
|
||||||
// ignore long clicks (prevents resizable widget from initializing a sort)
|
// ignore long clicks (prevents resizable widget from initializing a sort)
|
||||||
if (external !== true && (new Date().getTime() - downTime > 250)) { return false; }
|
if (e.type === 'mouseup' && external !== true && (new Date().getTime() - downTime > 250)) { return false; }
|
||||||
if (c.delayInit && !c.cache) { buildCache(table); }
|
if (c.delayInit && !c.cache) { buildCache(table); }
|
||||||
if (!cell.sortDisabled) {
|
if (!cell.sortDisabled) {
|
||||||
initSort(table, cell, e);
|
initSort(table, cell, e);
|
||||||
@ -952,11 +961,11 @@
|
|||||||
// disable tablesorter
|
// disable tablesorter
|
||||||
$t
|
$t
|
||||||
.removeData('tablesorter')
|
.removeData('tablesorter')
|
||||||
.unbind('sortReset update updateAll updateRows updateCell addRows sorton appendCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave sortBegin sortEnd '.split(' ').join('.tablesorter '));
|
.unbind('sortReset update updateAll updateRows updateCell addRows sorton appendCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave keypress sortBegin sortEnd '.split(' ').join('.tablesorter '));
|
||||||
c.$headers.add($f)
|
c.$headers.add($f)
|
||||||
.removeClass(c.cssHeader + ' ' + c.cssAsc + ' ' + c.cssDesc)
|
.removeClass(c.cssHeader + ' ' + c.cssAsc + ' ' + c.cssDesc)
|
||||||
.removeAttr('data-column');
|
.removeAttr('data-column');
|
||||||
$r.find(c.selectorSort).unbind('mousedown.tablesorter mouseup.tablesorter');
|
$r.find(c.selectorSort).unbind('mousedown.tablesorter mouseup.tablesorter keypress.tablesorter');
|
||||||
ts.restoreHeaders(table);
|
ts.restoreHeaders(table);
|
||||||
if (removeClasses !== false) {
|
if (removeClasses !== false) {
|
||||||
$t.removeClass(c.tableClass + ' tablesorter-' + c.theme);
|
$t.removeClass(c.tableClass + ' tablesorter-' + c.theme);
|
||||||
|
2
js/jquery.tablesorter.min.js
vendored
2
js/jquery.tablesorter.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user