Core: revert pull #849; changed sort initiation method

A click event can now be triggered on the header to initiate a sort
This commit is contained in:
Mottie 2015-03-20 18:17:36 -05:00
parent 9f9e4bef91
commit ac89d509c7
4 changed files with 30 additions and 32 deletions

View File

@ -59,7 +59,6 @@
delayInit : false, // if false, the parsed table contents will not update until the first sort delayInit : false, // if false, the parsed table contents will not update until the first sort
serverSideSorting: false, // if true, server-side sorting should be performed because client-side sorting will be disabled, but the ui and events will still be used. serverSideSorting: false, // if true, server-side sorting should be performed because client-side sorting will be disabled, but the ui and events will still be used.
resort : true, // default setting to trigger a resort after an 'update', 'addRows', 'updateCell', etc has completed resort : true, // default setting to trigger a resort after an 'update', 'addRows', 'updateCell', etc has completed
ignoreLongClick : true, // if true, ignore clicks longer than 250ms in case of column resizing widget, disable for sorting on slower devices
// *** sort options // *** sort options
headers : {}, // set sorter, string, empty, locked order, sortInitialOrder, filter, etc. headers : {}, // set sorter, string, empty, locked order, sortInitialOrder, filter, etc.
@ -1335,7 +1334,7 @@
ts.bindEvents = function(table, $headers, core){ ts.bindEvents = function(table, $headers, core){
table = $(table)[0]; table = $(table)[0];
var downTime, var downTarget = null,
c = table.config; c = table.config;
if (core !== true) { if (core !== true) {
c.$extraHeaders = c.$extraHeaders ? c.$extraHeaders.add($headers) : $headers; c.$extraHeaders = c.$extraHeaders ? c.$extraHeaders.add($headers) : $headers;
@ -1344,23 +1343,27 @@
$headers $headers
// http://stackoverflow.com/questions/5312849/jquery-find-self; // http://stackoverflow.com/questions/5312849/jquery-find-self;
.find(c.selectorSort).add( $headers.filter(c.selectorSort) ) .find(c.selectorSort).add( $headers.filter(c.selectorSort) )
.unbind( ('mousedown mouseup sort keyup '.split(' ').join(c.namespace + ' ')).replace(/\s+/g, ' ') ) .unbind( ('mousedown mouseup click sort keyup '.split(' ').join(c.namespace + ' ')).replace(/\s+/g, ' ') )
.bind( 'mousedown mouseup sort keyup '.split(' ').join(c.namespace + ' '), function(e, external) { .bind( 'mousedown mouseup click sort keyup '.split(' ').join(c.namespace + ' '), function(e, external) {
var cell, var cell,
$target = $(e.target), $target = $(e.target),
type = e.type; type = e.type;
// only recognize left clicks or enter // only recognize left clicks
if ( ((e.which || e.button) !== 1 && !/sort|keyup/.test(type)) || (type === 'keyup' && e.which !== 13) ) { if ( ( ( e.which || e.button ) !== 1 && !/sort|keyup|click/.test(type) ) ||
// allow pressing enter
( type === 'keyup' && e.which !== 13 ) ||
// allow triggering a click event (e.which is undefined) & ignore physical clicks
( type === 'click' && typeof e.which !== 'undefined' ) ) {
return; return;
} }
// ignore long clicks (prevents resizable widget from initializing a sort) // ignore mouseup if mousedown wasn't on the same target
if (type === 'mouseup' && external !== true && (new Date().getTime() - downTime > 250) && c.ignoreLongClick) { return; } if ( type === 'mouseup' && downTarget !== e.target && external !== true ) { return; }
// set timer on mousedown // set timer on mousedown
if (type === 'mousedown') { if ( type === 'mousedown' ) {
downTime = new Date().getTime(); downTarget = e.target;
return; return;
} }
cell = $.fn.closest ? $target.closest('td,th') : $target.parents('td,th').filter(':first'); downTarget = null;
// prevent sort being triggered on form elements // prevent sort being triggered on form elements
if ( /(input|select|button|textarea)/i.test(e.target.tagName) || if ( /(input|select|button|textarea)/i.test(e.target.tagName) ||
// nosort class name, or elements within a nosort container // nosort class name, or elements within a nosort container

File diff suppressed because one or more lines are too long

View File

@ -1050,14 +1050,6 @@
<td></td> <td></td>
</tr> </tr>
<tr id="ignorelongclick">
<td><span class="permalink">ignoreLongClick</span></td>
<td>Boolean</td>
<td>true</td>
<td>If true, tablesorter will ignore clicks longer than 250ms to prevent sorting when dragging columns in case of column resizing widget. Set to false for issues sorting on slower devices.</td>
<td></td>
</tr>
<tr id="imgattr"> <tr id="imgattr">
<td><a href="#" class="permalink">imgAttr</a></td> <td><a href="#" class="permalink">imgAttr</a></td>
<td>String</td> <td>String</td>

View File

@ -59,7 +59,6 @@
delayInit : false, // if false, the parsed table contents will not update until the first sort delayInit : false, // if false, the parsed table contents will not update until the first sort
serverSideSorting: false, // if true, server-side sorting should be performed because client-side sorting will be disabled, but the ui and events will still be used. serverSideSorting: false, // if true, server-side sorting should be performed because client-side sorting will be disabled, but the ui and events will still be used.
resort : true, // default setting to trigger a resort after an 'update', 'addRows', 'updateCell', etc has completed resort : true, // default setting to trigger a resort after an 'update', 'addRows', 'updateCell', etc has completed
ignoreLongClick : true, // if true, ignore clicks longer than 250ms in case of column resizing widget, disable for sorting on slower devices
// *** sort options // *** sort options
headers : {}, // set sorter, string, empty, locked order, sortInitialOrder, filter, etc. headers : {}, // set sorter, string, empty, locked order, sortInitialOrder, filter, etc.
@ -1335,7 +1334,7 @@
ts.bindEvents = function(table, $headers, core){ ts.bindEvents = function(table, $headers, core){
table = $(table)[0]; table = $(table)[0];
var downTime, var downTarget = null,
c = table.config; c = table.config;
if (core !== true) { if (core !== true) {
c.$extraHeaders = c.$extraHeaders ? c.$extraHeaders.add($headers) : $headers; c.$extraHeaders = c.$extraHeaders ? c.$extraHeaders.add($headers) : $headers;
@ -1344,23 +1343,27 @@
$headers $headers
// http://stackoverflow.com/questions/5312849/jquery-find-self; // http://stackoverflow.com/questions/5312849/jquery-find-self;
.find(c.selectorSort).add( $headers.filter(c.selectorSort) ) .find(c.selectorSort).add( $headers.filter(c.selectorSort) )
.unbind( ('mousedown mouseup sort keyup '.split(' ').join(c.namespace + ' ')).replace(/\s+/g, ' ') ) .unbind( ('mousedown mouseup click sort keyup '.split(' ').join(c.namespace + ' ')).replace(/\s+/g, ' ') )
.bind( 'mousedown mouseup sort keyup '.split(' ').join(c.namespace + ' '), function(e, external) { .bind( 'mousedown mouseup click sort keyup '.split(' ').join(c.namespace + ' '), function(e, external) {
var cell, var cell,
$target = $(e.target), $target = $(e.target),
type = e.type; type = e.type;
// only recognize left clicks or enter // only recognize left clicks
if ( ((e.which || e.button) !== 1 && !/sort|keyup/.test(type)) || (type === 'keyup' && e.which !== 13) ) { if ( ( ( e.which || e.button ) !== 1 && !/sort|keyup|click/.test(type) ) ||
// allow pressing enter
( type === 'keyup' && e.which !== 13 ) ||
// allow triggering a click event (e.which is undefined) & ignore physical clicks
( type === 'click' && typeof e.which !== 'undefined' ) ) {
return; return;
} }
// ignore long clicks (prevents resizable widget from initializing a sort) // ignore mouseup if mousedown wasn't on the same target
if (type === 'mouseup' && external !== true && (new Date().getTime() - downTime > 250) && c.ignoreLongClick) { return; } if ( type === 'mouseup' && downTarget !== e.target && external !== true ) { return; }
// set timer on mousedown // set timer on mousedown
if (type === 'mousedown') { if ( type === 'mousedown' ) {
downTime = new Date().getTime(); downTarget = e.target;
return; return;
} }
cell = $.fn.closest ? $target.closest('td,th') : $target.parents('td,th').filter(':first'); downTarget = null;
// prevent sort being triggered on form elements // prevent sort being triggered on form elements
if ( /(input|select|button|textarea)/i.test(e.target.tagName) || if ( /(input|select|button|textarea)/i.test(e.target.tagName) ||
// nosort class name, or elements within a nosort container // nosort class name, or elements within a nosort container