Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Updates tablesorter
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Sommerhalder committed Mar 11, 2019
1 parent a9d537e commit a4f697c
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions onegov/election_day/assets/js/jquery.tablesorter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*! TableSorter (FORK) v2.30.5 *//*
(function(factory){if (typeof define === 'function' && define.amd){define(['jquery'], factory);} else if (typeof module === 'object' && typeof module.exports === 'object'){module.exports = factory(require('jquery'));} else {factory(jQuery);}}(function(jQuery){
/*! TableSorter (FORK) v2.31.1 *//*
* Client-side table sorting with ease!
* @requires jQuery v1.2.6+
*
Expand All @@ -22,7 +23,7 @@
'use strict';
var ts = $.tablesorter = {

version : '2.30.5',
version : '2.31.1',

parsers : [],
widgets : [],
Expand Down Expand Up @@ -319,6 +320,8 @@
ts.applyWidget( table, true );
// if user has supplied a sort list to constructor
if ( c.sortList.length > 0 ) {
// save sortList before any sortAppend is added
c.last.sortList = c.sortList;
ts.sortOn( c, c.sortList, {}, !c.initWidgets );
} else {
ts.setHeadersCss( c );
Expand Down Expand Up @@ -593,10 +596,11 @@
// this may get updated numerous times if there are multiple rows
c.sortVars[ column ] = {
count : -1, // set to -1 because clicking on the header automatically adds one
order: tmp ?
order : tmp ?
( c.sortReset ? [ 1, 0, 2 ] : [ 1, 0 ] ) : // desc, asc, unsorted
( c.sortReset ? [ 0, 1, 2 ] : [ 0, 1 ] ), // asc, desc, unsorted
lockedOrder : false
lockedOrder : false,
sortedBy : ''
};
tmp = ts.getData( $elem, configHeaders, 'lockedOrder' ) || false;
if ( typeof tmp !== 'undefined' && tmp !== false ) {
Expand Down Expand Up @@ -1196,6 +1200,11 @@
txt += ts.language[ nextSort === 0 ? 'nextAsc' : nextSort === 1 ? 'nextDesc' : 'nextNone' ];
}
$header.attr( 'aria-label', txt );
if (vars.sortedBy) {
$header.attr( 'data-sortedBy', vars.sortedBy );
} else {
$header.removeAttr('data-sortedBy');
}
}
},

Expand Down Expand Up @@ -1550,6 +1559,7 @@
len = c.$headers.length,
th = ts.getClosest( $( cell ), 'th, td' ),
col = parseInt( th.attr( 'data-column' ), 10 ),
sortedBy = event.type === 'mouseup' ? 'user' : event.type,
order = c.sortVars[ col ].order;
th = th[0];
// Only call sortStart if sorting is enabled
Expand All @@ -1570,6 +1580,9 @@
}
// user only wants to sort on one column
if ( notMultiSort ) {
$.each( c.sortVars, function( i ) {
c.sortVars[ i ].sortedBy = '';
});
// flush the sort list
c.sortList = [];
c.last.sortList = [];
Expand All @@ -1578,19 +1591,22 @@
for ( indx = 0; indx < arry.length; indx++ ) {
if ( arry[ indx ][ 0 ] !== col ) {
c.sortList[ c.sortList.length ] = arry[ indx ];
c.sortVars[ arry[ indx ][ 0 ] ].sortedBy = 'sortForce';
}
}
}
// add column to sort list
dir = order[ c.sortVars[ col ].count ];
if ( dir < 2 ) {
c.sortList[ c.sortList.length ] = [ col, dir ];
c.sortVars[ col ].sortedBy = sortedBy;
// add other columns if header spans across multiple
if ( th.colSpan > 1 ) {
for ( indx = 1; indx < th.colSpan; indx++ ) {
c.sortList[ c.sortList.length ] = [ col + indx, dir ];
// update count on columns in colSpan
c.sortVars[ col + indx ].count = $.inArray( dir, order );
c.sortVars[ col + indx ].sortedBy = sortedBy;
}
}
}
Expand All @@ -1602,6 +1618,7 @@
// the user has clicked on an already sorted column
if ( ts.isValueInArray( col, c.sortList ) >= 0 ) {
// reverse the sorting direction
c.sortVars[ col ].sortedBy = sortedBy;
for ( indx = 0; indx < c.sortList.length; indx++ ) {
tmp = c.sortList[ indx ];
if ( tmp[ 0 ] === col ) {
Expand All @@ -1616,6 +1633,7 @@
} else {
// add column to sort list array
dir = order[ c.sortVars[ col ].count ];
c.sortVars[ col ].sortedBy = sortedBy;
if ( dir < 2 ) {
c.sortList[ c.sortList.length ] = [ col, dir ];
// add other columns if header spans across multiple
Expand All @@ -1624,6 +1642,7 @@
c.sortList[ c.sortList.length ] = [ col + indx, dir ];
// update count on columns in colSpan
c.sortVars[ col + indx ].count = $.inArray( dir, order );
c.sortVars[ col + indx ].sortedBy = sortedBy;
}
}
}
Expand Down Expand Up @@ -1659,6 +1678,7 @@
}
}
c.sortList[ c.sortList.length ] = [ arry[ indx ][ 0 ], dir ];
c.sortVars[ arry[ indx ][ 0 ] ].sortedBy = 'sortAppend';
}
}
}
Expand Down Expand Up @@ -1744,7 +1764,7 @@
sort = sorter[ col ]( x[ col ], y[ col ], dir, col, table );
} else {
// fall back to natural sort
sort = ts[ 'sortNatural' + ( dir ? 'Asc' : 'Desc' ) ]( a[ col ], b[ col ], col, c );
sort = ts[ 'sortNatural' + ( dir ? 'Asc' : 'Desc' ) ]( a[ col ] || '', b[ col ] || '', col, c );
}
}
if ( sort ) { return sort; }
Expand Down Expand Up @@ -1790,8 +1810,12 @@
},

sortOn : function( c, list, callback, init ) {
var table = c.table;
var indx,
table = c.table;
c.$table.triggerHandler( 'sortStart', table );
for (indx = 0; indx < c.columns; indx++) {
c.sortVars[ indx ].sortedBy = ts.isValueInArray( indx, list ) > -1 ? 'sorton' : '';
}
// update header count index
ts.updateHeaderSortCount( c, list );
// set css for headers
Expand All @@ -1814,13 +1838,14 @@

sortReset : function( c, callback ) {
c.sortList = [];
ts.setHeadersCss( c );
ts.multisort( c );
ts.appendCache( c );
var indx;
for (indx = 0; indx < c.columns; indx++) {
c.sortVars[ indx ].count = -1;
c.sortVars[ indx ].sortedBy = '';
}
ts.setHeadersCss( c );
ts.multisort( c );
ts.appendCache( c );
if ( $.isFunction( callback ) ) {
callback( c.table );
}
Expand All @@ -1838,20 +1863,20 @@
// Natural sort - https://github.com/overset/javascript-natural-sort (date sorting removed)
sortNatural : function( a, b ) {
if ( a === b ) { return 0; }
a = a.toString();
b = b.toString();
a = ( a || '' ).toString();
b = ( b || '' ).toString();
var aNum, bNum, aFloat, bFloat, indx, max,
regex = ts.regex;
// first try and sort Hex codes
if ( regex.hex.test( b ) ) {
aNum = parseInt( ( a || '' ).match( regex.hex ), 16 );
bNum = parseInt( ( b || '' ).match( regex.hex ), 16 );
aNum = parseInt( a.match( regex.hex ), 16 );
bNum = parseInt( b.match( regex.hex ), 16 );
if ( aNum < bNum ) { return -1; }
if ( aNum > bNum ) { return 1; }
}
// chunk/tokenize
aNum = ( a || '' ).replace( regex.chunk, '\\0$1\\0' ).replace( regex.chunks, '' ).split( '\\0' );
bNum = ( b || '' ).replace( regex.chunk, '\\0$1\\0' ).replace( regex.chunks, '' ).split( '\\0' );
aNum = a.replace( regex.chunk, '\\0$1\\0' ).replace( regex.chunks, '' ).split( '\\0' );
bNum = b.replace( regex.chunk, '\\0$1\\0' ).replace( regex.chunks, '' ).split( '\\0' );
max = Math.max( aNum.length, bNum.length );
// natural sorting through split numeric strings and default strings
for ( indx = 0; indx < max; indx++ ) {
Expand Down Expand Up @@ -2888,3 +2913,4 @@
});

})( jQuery );
return jQuery.tablesorter;}));

0 comments on commit a4f697c

Please sign in to comment.