2015-11-10 21:27:30 +00:00
|
|
|
/*! Widget: headerTitles - updated 11/10/2015 (v2.24.4) *//*
|
2014-03-05 23:44:10 +00:00
|
|
|
* Requires tablesorter v2.8+ and jQuery 1.7+
|
|
|
|
* by Rob Garrison
|
|
|
|
*/
|
|
|
|
/*jshint browser:true, jquery:true, unused:false */
|
|
|
|
/*global jQuery: false */
|
|
|
|
;(function($){
|
2015-07-23 04:29:51 +00:00
|
|
|
'use strict';
|
|
|
|
var ts = $.tablesorter;
|
2014-03-05 23:44:10 +00:00
|
|
|
|
2014-03-09 00:52:20 +00:00
|
|
|
ts.addWidget({
|
2014-03-05 23:44:10 +00:00
|
|
|
id: 'headerTitles',
|
|
|
|
options: {
|
2014-03-09 00:52:20 +00:00
|
|
|
// use aria-label text
|
2015-07-23 04:29:51 +00:00
|
|
|
// e.g. 'First Name: Ascending sort applied, activate to apply a descending sort'
|
2014-03-09 00:52:20 +00:00
|
|
|
headerTitle_useAria : false,
|
|
|
|
// add tooltip class
|
|
|
|
headerTitle_tooltip : '',
|
|
|
|
// custom titles [ ascending, descending, unsorted ]
|
|
|
|
headerTitle_cur_text : [ ' sort: A - Z', ' sort: Z - A', 'ly unsorted' ],
|
|
|
|
headerTitle_cur_numeric : [ ' sort: 0 - 9', ' sort: 9 - 0', 'ly unsorted' ],
|
|
|
|
headerTitle_nxt_text : [ ' sort: A - Z', ' sort: Z - A', 'remove sort' ],
|
|
|
|
headerTitle_nxt_numeric : [ ' sort: 0 - 9', ' sort: 9 - 0', 'remove sort' ],
|
|
|
|
|
|
|
|
// title display; {prefix} adds above prefix
|
|
|
|
// {type} adds the current sort order from above (text or numeric)
|
|
|
|
// {next} adds the next sort direction using the sort order above
|
|
|
|
headerTitle_output_sorted : 'current{current}; activate to {next}',
|
|
|
|
headerTitle_output_unsorted : 'current{current}; activate to {next} ',
|
|
|
|
headerTitle_output_nosort : 'No sort available',
|
|
|
|
// use this type to override the parser detection result
|
|
|
|
// e.g. use for numerically parsed columns (e.g. dates), but you
|
|
|
|
// want the user to see a text sort, e.g. [ 'text', 'numeric' ]
|
|
|
|
headerTitle_type : [],
|
|
|
|
// manipulate the title as desired
|
|
|
|
headerTitle_callback : null // function($cell, txt) { return txt; }
|
|
|
|
},
|
|
|
|
init: function(table, thisWidget, c, wo){
|
|
|
|
// force refresh
|
|
|
|
c.$table.on('refreshHeaderTitle', function(){
|
|
|
|
thisWidget.format(table, c, wo);
|
|
|
|
});
|
|
|
|
// add tooltip class
|
|
|
|
if ($.isArray(wo.headerTitle_tooltip)) {
|
|
|
|
c.$headers.each(function(){
|
|
|
|
$(this).addClass( wo.headerTitle_tooltip[this.column] || '' );
|
|
|
|
});
|
|
|
|
} else if (wo.headerTitle_tooltip !== '') {
|
|
|
|
c.$headers.addClass( wo.headerTitle_tooltip );
|
|
|
|
}
|
2014-03-05 23:44:10 +00:00
|
|
|
},
|
|
|
|
format: function (table, c, wo) {
|
|
|
|
var txt;
|
2014-03-09 00:52:20 +00:00
|
|
|
c.$headers.each(function(){
|
|
|
|
var t = this,
|
|
|
|
$this = $(this),
|
2015-10-21 16:03:14 +00:00
|
|
|
col = parseInt( $this.attr( 'data-column' ), 10 ),
|
|
|
|
sortType = wo.headerTitle_type[ col ] || c.parsers[ col ].type || 'text',
|
2014-03-09 00:52:20 +00:00
|
|
|
sortDirection = $this.hasClass(ts.css.sortAsc) ? 0 : $this.hasClass(ts.css.sortDesc) ? 1 : 2,
|
2015-10-21 16:03:14 +00:00
|
|
|
sortNext = c.sortVars[ col ].order[ ( c.sortVars[ col ].count + 1 ) % ( c.sortReset ? 3 : 2 ) ];
|
2014-03-09 00:52:20 +00:00
|
|
|
if (wo.headerTitle_useAria) {
|
2015-11-08 14:42:23 +00:00
|
|
|
txt = $this.attr('aria-label') || wo.headerTitle_output_nosort || '';
|
2014-03-09 00:52:20 +00:00
|
|
|
} else {
|
|
|
|
txt = (wo.headerTitle_prefix || '') + // now deprecated
|
|
|
|
($this.hasClass('sorter-false') ? wo.headerTitle_output_nosort :
|
2015-10-21 16:03:14 +00:00
|
|
|
ts.isValueInArray( col, c.sortList ) >= 0 ? wo.headerTitle_output_sorted : wo.headerTitle_output_unsorted);
|
2014-03-09 00:52:20 +00:00
|
|
|
txt = txt.replace(/\{(current|next|name)\}/gi, function(m){
|
|
|
|
return {
|
|
|
|
'{name}' : $this.text(),
|
|
|
|
'{current}' : wo[ 'headerTitle_cur_' + sortType ][ sortDirection ] || '',
|
|
|
|
'{next}' : wo[ 'headerTitle_nxt_' + sortType ][ sortNext ] || ''
|
|
|
|
}[m.toLowerCase()];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$this.attr('title', $.isFunction(wo.headerTitle_callback) ? wo.headerTitle_callback($this, txt) : txt);
|
2014-03-05 23:44:10 +00:00
|
|
|
});
|
|
|
|
},
|
2014-03-09 00:52:20 +00:00
|
|
|
remove: function (table, c, wo) {
|
2014-03-05 23:44:10 +00:00
|
|
|
c.$headers.attr('title', '');
|
2014-03-09 00:52:20 +00:00
|
|
|
c.$table.off('refreshHeaderTitle');
|
|
|
|
// remove tooltip class
|
|
|
|
if ($.isArray(wo.headerTitle_tooltip)) {
|
|
|
|
c.$headers.each(function(){
|
|
|
|
$(this).removeClass( wo.headerTitle_tooltip[this.column] || '' );
|
|
|
|
});
|
|
|
|
} else if (wo.headerTitle_tooltip !== '') {
|
|
|
|
c.$headers.removeClass( wo.headerTitle_tooltip );
|
|
|
|
}
|
2014-03-05 23:44:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|