Debian Codegraph @

js/widgets/widget-currentSort.js

raw symbols SCIP
1 /*! Widget: currentSort - 7/31/2016 (v2.27.0) *//*
2 * Requires tablesorter v2.8+ and jQuery 1.7+
3 * by Rob Garrison
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 // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill
28 // order = new Array(c.columns).fill(unsort),
29 // the above ES6 will not work in all browsers, so
30 // we're stuck with this messy code to fill the array:
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 );