| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
;(function($) { |
| 8 |
'use strict'; |
| 9 |
var ts = $.tablesorter; |
| 10 |
|
| 11 |
ts.addWidget({ |
| 12 |
id: 'headerTitles', |
| 13 |
options: { |
| 14 |
|
| 15 |
|
| 16 |
headerTitle_useAria : false, |
| 17 |
|
| 18 |
headerTitle_tooltip : '', |
| 19 |
|
| 20 |
headerTitle_cur_text : [ ' sort: A - Z', ' sort: Z - A', 'ly unsorted' ], |
| 21 |
headerTitle_cur_numeric : [ ' sort: 0 - 9', ' sort: 9 - 0', 'ly unsorted' ], |
| 22 |
headerTitle_nxt_text : [ ' sort: A - Z', ' sort: Z - A', 'remove sort' ], |
| 23 |
headerTitle_nxt_numeric : [ ' sort: 0 - 9', ' sort: 9 - 0', 'remove sort' ], |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
headerTitle_output_sorted : 'current{current}; activate to {next}', |
| 29 |
headerTitle_output_unsorted : 'current{current}; activate to {next} ', |
| 30 |
headerTitle_output_nosort : 'No sort available', |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
headerTitle_type : [], |
| 35 |
|
| 36 |
headerTitle_callback : null |
| 37 |
}, |
| 38 |
init: function(table, thisWidget, c, wo) { |
| 39 |
|
| 40 |
c.$table.on('refreshHeaderTitle', function() { |
| 41 |
thisWidget.format(table, c, wo); |
| 42 |
}); |
| 43 |
|
| 44 |
if ($.isArray(wo.headerTitle_tooltip)) { |
| 45 |
c.$headers.each(function() { |
| 46 |
$(this).addClass( wo.headerTitle_tooltip[this.column] || '' ); |
| 47 |
}); |
| 48 |
} else if (wo.headerTitle_tooltip !== '') { |
| 49 |
c.$headers.addClass( wo.headerTitle_tooltip ); |
| 50 |
} |
| 51 |
}, |
| 52 |
format: function (table, c, wo) { |
| 53 |
var txt; |
| 54 |
c.$headers.each(function() { |
| 55 |
var $this = $(this), |
| 56 |
col = parseInt( $this.attr( 'data-column' ), 10 ), |
| 57 |
sortType = wo.headerTitle_type[ col ] || c.parsers[ col ].type || 'text', |
| 58 |
sortDirection = $this.hasClass(ts.css.sortAsc) ? 0 : $this.hasClass(ts.css.sortDesc) ? 1 : 2, |
| 59 |
sortNext = c.sortVars[ col ].order[ ( c.sortVars[ col ].count + 1 ) % ( c.sortReset ? 3 : 2 ) ]; |
| 60 |
if (wo.headerTitle_useAria) { |
| 61 |
txt = $this.attr('aria-label') || wo.headerTitle_output_nosort || ''; |
| 62 |
} else { |
| 63 |
txt = (wo.headerTitle_prefix || '') + |
| 64 |
($this.hasClass('sorter-false') ? wo.headerTitle_output_nosort : |
| 65 |
ts.isValueInArray( col, c.sortList ) >= 0 ? wo.headerTitle_output_sorted : wo.headerTitle_output_unsorted); |
| 66 |
txt = txt.replace(/\{(current|next|name)\}/gi, function(m) { |
| 67 |
return { |
| 68 |
'{name}' : $this.text(), |
| 69 |
'{current}' : wo[ 'headerTitle_cur_' + sortType ][ sortDirection ] || '', |
| 70 |
'{next}' : wo[ 'headerTitle_nxt_' + sortType ][ sortNext ] || '' |
| 71 |
}[m.toLowerCase()]; |
| 72 |
}); |
| 73 |
} |
| 74 |
$this.attr('title', $.isFunction(wo.headerTitle_callback) ? wo.headerTitle_callback($this, txt) : txt); |
| 75 |
}); |
| 76 |
}, |
| 77 |
remove: function (table, c, wo) { |
| 78 |
c.$headers.attr('title', ''); |
| 79 |
c.$table.off('refreshHeaderTitle'); |
| 80 |
|
| 81 |
if ($.isArray(wo.headerTitle_tooltip)) { |
| 82 |
c.$headers.each(function() { |
| 83 |
$(this).removeClass( wo.headerTitle_tooltip[this.column] || '' ); |
| 84 |
}); |
| 85 |
} else if (wo.headerTitle_tooltip !== '') { |
| 86 |
c.$headers.removeClass( wo.headerTitle_tooltip ); |
| 87 |
} |
| 88 |
} |
| 89 |
}); |
| 90 |
|
| 91 |
})(jQuery); |