| 1 |
|
| 2 |
|
| 3 |
|
| 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; |
| 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 |
|
| 28 |
for ( indx = 0; indx < len; indx++ ) { |
| 29 |
$el = c.$headers.eq( indx ); |
| 30 |
|
| 31 |
ts.setColumnSort( c, $el, !isEnabled ); |
| 32 |
|
| 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 |
|
| 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 |
|
| 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 ); |