Debian Codegraph @

js/widgets/widget-toggle.js

raw symbols SCIP
1 /*! tablesorter enable/disable sort & filter (BETA) - 11/10/2015 (v2.24.4)
2 * Requires tablesorter v2.24.4+ & jQuery 1.7+
3 * by Rob Garrison
4 */
5 ;( function( $ ) {
6 'use strict';
7 var ts = $.tablesorter,
8
9 tst = ts.toggleTS = {
10
11 init : function( c, wo ) {
12 wo.toggleTS_isEnabled = true; // enabled
13 wo.toggleTS_areDisabled = {
14 headers : [],
15 filters : []
16 };
17 c.$table.on('enable.toggleTS disable.toggleTS', function( event ) {
18 tst.toggle( this.config, this.config.widgetOptions, event.type === 'enable' );
19 });
20 },
21 toggle : function( c, wo, isEnabled ) {
22 if ( wo.toggleTS_isEnabled !== isEnabled ) {
23 wo.toggleTS_isEnabled = isEnabled;
24 var indx, $el,
25 len = c.$headers.length;
26
27 // table headers
28 for ( indx = 0; indx < len; indx++ ) {
29 $el = c.$headers.eq( indx );
30 // function added in v2.24.4
31 ts.setColumnSort( c, $el, !isEnabled );
32 // function added in v2.24.4; passing "isEnabled" allows removal of "next sort" labels
33 ts.setColumnAriaLabel( c, $el, isEnabled );
34 }
35 if ( wo.toggleTS_hideFilterRow ) {
36 c.$table.find( '.' + ts.css.filterRow ).toggle( isEnabled );
37 } else if ( ts.hasWidget( c.$table, 'filter' ) ) {
38 // c.$filters points to filter CELL
39 len = c.$filters.length;
40 for ( indx = 0; indx < len; indx++ ) {
41 if ( isEnabled && !wo.toggleTS_areDisabled.filters[ indx ] ) {
42 c.$filters.eq( indx ).find( 'input, select' )
43 .removeClass( ts.css.filterDisabled )
44 .prop( 'disabled', false );
45 } else if ( !isEnabled ) {
46 $el = c.$filters.eq( indx ).find( 'input, select' );
47 if ( $el.hasClass( ts.css.filterDisabled ) ) {
48 wo.toggleTS_areDisabled.filters[ indx ] = true;
49 }
50 $el
51 .addClass( ts.css.filterDisabled )
52 .prop( 'disabled', true );
53 }
54 }
55 }
56 // include external filters
57 wo.filter_$externalFilters
58 .toggleClass( ts.css.filterDisabled, isEnabled )
59 .prop( 'disabled', !isEnabled );
60 }
61 if ( typeof wo.toggleTS_callback === 'function' ) {
62 wo.toggleTS_callback( c, isEnabled );
63 }
64 }
65 };
66
67 ts.addWidget({
68 id: 'toggle-ts',
69 options: {
70 toggleTS_hideFilterRow : false,
71 toggleTS_callback : null
72 },
73 init : function( table, thisWidget, c, wo ) {
74 tst.init( c, wo );
75 },
76 remove : function( table, c ) {
77 c.$table.off( 'enable.toggleTS disable.toggleTS' );
78 }
79 });
80
81 })( jQuery );