Debian Codegraph @

js/widgets/widget-headerTitles.js

raw symbols SCIP
1 /*! Widget: headerTitles - updated 11/10/2015 (v2.24.4) *//*
2 * Requires tablesorter v2.8+ and jQuery 1.7+
3 * by Rob Garrison
4 */
5 /*jshint browser:true, jquery:true, unused:false */
6 /*global jQuery: false */
7 ;(function($) {
8 'use strict';
9 var ts = $.tablesorter;
10
11 ts.addWidget({
12 id: 'headerTitles',
13 options: {
14 // use aria-label text
15 // e.g. 'First Name: Ascending sort applied, activate to apply a descending sort'
16 headerTitle_useAria : false,
17 // add tooltip class
18 headerTitle_tooltip : '',
19 // custom titles [ ascending, descending, unsorted ]
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 // title display; {prefix} adds above prefix
26 // {type} adds the current sort order from above (text or numeric)
27 // {next} adds the next sort direction using the sort order above
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 // use this type to override the parser detection result
32 // e.g. use for numerically parsed columns (e.g. dates), but you
33 // want the user to see a text sort, e.g. [ 'text', 'numeric' ]
34 headerTitle_type : [],
35 // manipulate the title as desired
36 headerTitle_callback : null // function($cell, txt) { return txt; }
37 },
38 init: function(table, thisWidget, c, wo) {
39 // force refresh
40 c.$table.on('refreshHeaderTitle', function() {
41 thisWidget.format(table, c, wo);
42 });
43 // add tooltip class
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 || '') + // now deprecated
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 // remove tooltip class
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);