| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
;( function( $ ) { |
| 6 |
'use strict'; |
| 7 |
var ts = $.tablesorter; |
| 8 |
|
| 9 |
ts.currentSortLanguage = { |
| 10 |
0: 'asc', |
| 11 |
1: 'desc', |
| 12 |
2: 'unsorted' |
| 13 |
}; |
| 14 |
|
| 15 |
ts.currentSort = { |
| 16 |
init : function( c ) { |
| 17 |
c.$table.on( 'sortEnd.tscurrentSort', function() { |
| 18 |
ts.currentSort.update( this.config ); |
| 19 |
}); |
| 20 |
}, |
| 21 |
update: function( c ) { |
| 22 |
if ( c ) { |
| 23 |
var indx, |
| 24 |
wo = c.widgetOptions, |
| 25 |
lang = ts.currentSortLanguage, |
| 26 |
unsort = lang[ 2 ], |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
order = Array |
| 32 |
.apply( null, Array( c.columns ) ) |
| 33 |
.map( String.prototype.valueOf, unsort ), |
| 34 |
sortList = c.sortList, |
| 35 |
len = sortList.length; |
| 36 |
for ( indx = 0; indx < len; indx++ ) { |
| 37 |
order[ sortList[ indx ][ 0 ] ] = lang[ sortList[ indx ][ 1 ] ]; |
| 38 |
} |
| 39 |
c.currentSort = order; |
| 40 |
if ( typeof wo.currentSort_callback === 'function' ) { |
| 41 |
wo.currentSort_callback(c, order); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
ts.addWidget({ |
| 48 |
id: 'currentSort', |
| 49 |
options: { |
| 50 |
currentSort_callback : null |
| 51 |
}, |
| 52 |
init : function( table, thisWidget, c, wo ) { |
| 53 |
ts.currentSort.init( c, wo ); |
| 54 |
}, |
| 55 |
remove : function( table, c ) { |
| 56 |
c.$table.off( 'sortEnd.tscurrentSort' ); |
| 57 |
} |
| 58 |
}); |
| 59 |
|
| 60 |
})( jQuery ); |