| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
;(function($) { |
| 8 |
'use strict'; |
| 9 |
|
| 10 |
var ts = $.tablesorter, |
| 11 |
namespace = '.tscolsel', |
| 12 |
tsColSel = ts.columnSelector = { |
| 13 |
|
| 14 |
queryAll : '@media only all { [columns] { display: none; } } ', |
| 15 |
queryBreak : '@media all and (min-width: [size]) { [columns] { display: table-cell; } } ', |
| 16 |
|
| 17 |
init: function(table, c, wo) { |
| 18 |
var $t, colSel, |
| 19 |
debug = ts.debug(c, 'columnSelector'); |
| 20 |
|
| 21 |
|
| 22 |
$t = $(wo.columnSelector_layout); |
| 23 |
if (!$t.find('input').add( $t.filter('input') ).length) { |
| 24 |
if (debug) { |
| 25 |
console.error('ColumnSelector >> ERROR: Column Selector aborting, no input found in the layout! ***'); |
| 26 |
} |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
c.$table.addClass( c.namespace.slice(1) + 'columnselector' ); |
| 32 |
|
| 33 |
|
| 34 |
colSel = c.selector = { $container : $(wo.columnSelector_container || '<div>') }; |
| 35 |
colSel.$style = $('<style></style>').prop('disabled', true).appendTo('head'); |
| 36 |
colSel.$breakpoints = $('<style></style>').prop('disabled', true).appendTo('head'); |
| 37 |
|
| 38 |
colSel.isInitializing = true; |
| 39 |
tsColSel.setUpColspan(c, wo); |
| 40 |
tsColSel.setupSelector(c, wo); |
| 41 |
|
| 42 |
if (wo.columnSelector_mediaquery) { |
| 43 |
tsColSel.setupBreakpoints(c, wo); |
| 44 |
} |
| 45 |
|
| 46 |
colSel.isInitializing = false; |
| 47 |
if (colSel.$container.length) { |
| 48 |
tsColSel.updateCols(c, wo); |
| 49 |
} else if (debug) { |
| 50 |
console.warn('ColumnSelector >> container not found'); |
| 51 |
} |
| 52 |
|
| 53 |
c.$table |
| 54 |
.off('refreshColumnSelector' + namespace) |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
.on('refreshColumnSelector' + namespace, function( e, optName, optState ) { |
| 64 |
|
| 65 |
tsColSel.refreshColumns( this.config, optName, optState ); |
| 66 |
}); |
| 67 |
|
| 68 |
if (debug) { |
| 69 |
console.log('ColumnSelector >> Widget initialized'); |
| 70 |
} |
| 71 |
}, |
| 72 |
|
| 73 |
refreshColumns: function( c, optName, optState ) { |
| 74 |
var i, arry, $el, val, |
| 75 |
colSel = c.selector, |
| 76 |
isArry = $.isArray(optState || optName), |
| 77 |
wo = c.widgetOptions; |
| 78 |
|
| 79 |
if (typeof optName !== 'undefined' && optName !== null && colSel.$container.length) { |
| 80 |
|
| 81 |
if ( optName === 'selectors' ) { |
| 82 |
colSel.$container.empty(); |
| 83 |
tsColSel.setupSelector(c, wo); |
| 84 |
tsColSel.setupBreakpoints(c, wo); |
| 85 |
|
| 86 |
if ( typeof optState === 'undefined' && optState !== null ) { |
| 87 |
optState = colSel.auto; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
if (isArry) { |
| 92 |
arry = optState || optName; |
| 93 |
|
| 94 |
$.each(arry, function(i, v) { |
| 95 |
arry[i] = parseInt(v, 10); |
| 96 |
}); |
| 97 |
for (i = 0; i < c.columns; i++) { |
| 98 |
val = $.inArray( i, arry ) >= 0; |
| 99 |
$el = colSel.$container.find( 'input[data-column=' + i + ']' ); |
| 100 |
if ( $el.length ) { |
| 101 |
$el.prop( 'checked', val ); |
| 102 |
colSel.states[i] = val; |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
val = optState === true || optName === true || optName === 'auto' && optState !== false; |
| 109 |
$el = colSel.$container.find( 'input[data-column="auto"]' ).prop( 'checked', val ); |
| 110 |
tsColSel.updateAuto( c, wo, $el ); |
| 111 |
} else { |
| 112 |
tsColSel.updateBreakpoints(c, wo); |
| 113 |
tsColSel.updateCols(c, wo); |
| 114 |
} |
| 115 |
tsColSel.saveValues( c, wo ); |
| 116 |
tsColSel.adjustColspans( c, wo ); |
| 117 |
}, |
| 118 |
|
| 119 |
setupSelector: function(c, wo) { |
| 120 |
var index, name, $header, priority, col, colId, $el, |
| 121 |
colSel = c.selector, |
| 122 |
$container = colSel.$container, |
| 123 |
useStorage = wo.columnSelector_saveColumns && ts.storage, |
| 124 |
|
| 125 |
saved = useStorage ? ts.storage( c.table, 'tablesorter-columnSelector' ) : [], |
| 126 |
state = useStorage ? ts.storage( c.table, 'tablesorter-columnSelector-auto') : {}; |
| 127 |
|
| 128 |
|
| 129 |
colSel.auto = $.isEmptyObject(state) || $.type(state.auto) !== 'boolean' ? wo.columnSelector_mediaqueryState : state.auto; |
| 130 |
colSel.states = []; |
| 131 |
colSel.$column = []; |
| 132 |
colSel.$wrapper = []; |
| 133 |
colSel.$checkbox = []; |
| 134 |
|
| 135 |
for ( index = 0; index < c.columns; index++ ) { |
| 136 |
$header = c.$headerIndexed[ index ]; |
| 137 |
|
| 138 |
priority = $header.attr(wo.columnSelector_priority) || 1; |
| 139 |
colId = $header.attr('data-column'); |
| 140 |
col = ts.getColumnData( c.table, c.headers, colId ); |
| 141 |
state = ts.getData( $header, col, 'columnSelector'); |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
if ( isNaN(priority) && priority.length > 0 || state === 'disable' || |
| 146 |
( wo.columnSelector_columns[colId] && wo.columnSelector_columns[colId] === 'disable') ) { |
| 147 |
colSel.states[colId] = null; |
| 148 |
continue; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
colSel.states[colId] = saved && (typeof saved[colId] !== 'undefined' && saved[colId] !== null) ? |
| 153 |
saved[colId] : (typeof wo.columnSelector_columns[colId] !== 'undefined' && wo.columnSelector_columns[colId] !== null) ? |
| 154 |
wo.columnSelector_columns[colId] : (state === 'true' || state !== 'false'); |
| 155 |
colSel.$column[colId] = $(this); |
| 156 |
if ($container.length) { |
| 157 |
|
| 158 |
name = $header.attr(wo.columnSelector_name) || $header.text().trim(); |
| 159 |
if (typeof wo.columnSelector_layoutCustomizer === 'function') { |
| 160 |
$el = $header.find('.' + ts.css.headerIn); |
| 161 |
name = wo.columnSelector_layoutCustomizer( $el.length ? $el : $header, name, parseInt(colId, 10) ); |
| 162 |
} |
| 163 |
colSel.$wrapper[colId] = $(wo.columnSelector_layout.replace(/\{name\}/g, name)).appendTo($container); |
| 164 |
colSel.$checkbox[colId] = colSel.$wrapper[colId] |
| 165 |
|
| 166 |
.find('input').add( colSel.$wrapper[colId].filter('input') ) |
| 167 |
.attr('data-column', colId) |
| 168 |
.toggleClass( wo.columnSelector_cssChecked, colSel.states[colId] ) |
| 169 |
.prop('checked', colSel.states[colId]) |
| 170 |
.on('change', function() { |
| 171 |
if (!colSel.isInitializing) { |
| 172 |
|
| 173 |
var colId = $(this).attr('data-column'); |
| 174 |
if (tsColSel.checkChange(c, this.checked)) { |
| 175 |
|
| 176 |
c.selector.states[colId] = this.checked; |
| 177 |
tsColSel.updateCols(c, wo); |
| 178 |
} else { |
| 179 |
this.checked = !this.checked; |
| 180 |
return false; |
| 181 |
} |
| 182 |
} |
| 183 |
}).change(); |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
}, |
| 188 |
|
| 189 |
checkChange: function(c, checked) { |
| 190 |
var wo = c.widgetOptions, |
| 191 |
max = wo.columnSelector_maxVisible, |
| 192 |
min = wo.columnSelector_minVisible, |
| 193 |
states = c.selector.states, |
| 194 |
indx = states.length, |
| 195 |
count = 0; |
| 196 |
while (indx-- >= 0) { |
| 197 |
if (states[indx]) { |
| 198 |
count++; |
| 199 |
} |
| 200 |
} |
| 201 |
if ((checked & max !== null && count >= max) || |
| 202 |
(!checked && min !== null && count <= min)) { |
| 203 |
return false; |
| 204 |
} |
| 205 |
return true; |
| 206 |
}, |
| 207 |
|
| 208 |
setupBreakpoints: function(c, wo) { |
| 209 |
var colSel = c.selector; |
| 210 |
|
| 211 |
|
| 212 |
if (wo.columnSelector_mediaquery) { |
| 213 |
|
| 214 |
colSel.lastIndex = -1; |
| 215 |
tsColSel.updateBreakpoints(c, wo); |
| 216 |
c.$table |
| 217 |
.off('updateAll' + namespace) |
| 218 |
.on('updateAll' + namespace, function() { |
| 219 |
tsColSel.setupSelector(c, wo); |
| 220 |
tsColSel.setupBreakpoints(c, wo); |
| 221 |
tsColSel.updateBreakpoints(c, wo); |
| 222 |
tsColSel.updateCols(c, wo); |
| 223 |
}); |
| 224 |
} |
| 225 |
|
| 226 |
if (colSel.$container.length) { |
| 227 |
|
| 228 |
if (wo.columnSelector_mediaquery) { |
| 229 |
colSel.$auto = $( wo.columnSelector_layout.replace(/\{name\}/g, wo.columnSelector_mediaqueryName) ).prependTo(colSel.$container); |
| 230 |
colSel.$auto |
| 231 |
|
| 232 |
.find('input').add( colSel.$auto.filter('input') ) |
| 233 |
.attr('data-column', 'auto') |
| 234 |
.prop('checked', colSel.auto) |
| 235 |
.toggleClass( wo.columnSelector_cssChecked, colSel.auto ) |
| 236 |
.on('change', function() { |
| 237 |
tsColSel.updateAuto(c, wo, $(this)); |
| 238 |
}).change(); |
| 239 |
} |
| 240 |
|
| 241 |
c.$table.off('update' + namespace).on('update' + namespace, function() { |
| 242 |
tsColSel.updateCols(c, wo); |
| 243 |
}); |
| 244 |
} |
| 245 |
}, |
| 246 |
|
| 247 |
updateAuto: function(c, wo, $el) { |
| 248 |
var colSel = c.selector; |
| 249 |
colSel.auto = $el.prop('checked') || false; |
| 250 |
$.each( colSel.$checkbox, function(i, $cb) { |
| 251 |
if ($cb) { |
| 252 |
$cb[0].disabled = colSel.auto; |
| 253 |
colSel.$wrapper[i].toggleClass('disabled', colSel.auto); |
| 254 |
} |
| 255 |
}); |
| 256 |
if (wo.columnSelector_mediaquery) { |
| 257 |
tsColSel.updateBreakpoints(c, wo); |
| 258 |
} |
| 259 |
tsColSel.updateCols(c, wo); |
| 260 |
|
| 261 |
if (c.selector.$popup) { |
| 262 |
c.selector.$popup.find('.tablesorter-column-selector') |
| 263 |
.html( colSel.$container.html() ) |
| 264 |
.find('input').each(function() { |
| 265 |
var indx = $(this).attr('data-column'); |
| 266 |
$(this).prop( 'checked', indx === 'auto' ? colSel.auto : colSel.states[indx] ); |
| 267 |
}); |
| 268 |
} |
| 269 |
tsColSel.saveValues( c, wo ); |
| 270 |
tsColSel.adjustColspans( c, wo ); |
| 271 |
|
| 272 |
if (colSel.auto) { |
| 273 |
c.$table.triggerHandler(wo.columnSelector_updated); |
| 274 |
} |
| 275 |
}, |
| 276 |
addSelectors: function( wo, prefix, column ) { |
| 277 |
var array = [], |
| 278 |
temp = ' col:nth-child(' + column + ')'; |
| 279 |
array.push(prefix + temp + ',' + prefix + '_extra_table' + temp); |
| 280 |
temp = ' tr:not(.' + wo.columnSelector_classHasSpan + ') th[data-column="' + ( column - 1 ) + '"]'; |
| 281 |
array.push(prefix + temp + ',' + prefix + '_extra_table' + temp); |
| 282 |
temp = ' tr:not(.' + wo.columnSelector_classHasSpan + ') td:nth-child(' + column + ')'; |
| 283 |
array.push(prefix + temp + ',' + prefix + '_extra_table' + temp); |
| 284 |
|
| 285 |
temp = ' tr td:not(' + prefix + wo.columnSelector_classHasSpan + ')[data-column="' + (column - 1) + '"]'; |
| 286 |
array.push(prefix + temp + ',' + prefix + '_extra_table' + temp); |
| 287 |
return array; |
| 288 |
}, |
| 289 |
updateBreakpoints: function(c, wo) { |
| 290 |
var priority, col, column, breaks, |
| 291 |
isHidden = [], |
| 292 |
colSel = c.selector, |
| 293 |
prefix = c.namespace + 'columnselector', |
| 294 |
mediaAll = [], |
| 295 |
breakpts = ''; |
| 296 |
if (wo.columnSelector_mediaquery && !colSel.auto) { |
| 297 |
colSel.$breakpoints.prop('disabled', true); |
| 298 |
colSel.$style.prop('disabled', false); |
| 299 |
return; |
| 300 |
} |
| 301 |
if (wo.columnSelector_mediaqueryHidden) { |
| 302 |
|
| 303 |
for ( column = 0; column < c.columns; column++ ) { |
| 304 |
col = ts.getColumnData( c.table, c.headers, column ); |
| 305 |
isHidden[ column + 1 ] = ts.getData( c.$headerIndexed[ column ], col, 'columnSelector' ) === 'false'; |
| 306 |
if ( isHidden[ column + 1 ] ) { |
| 307 |
|
| 308 |
mediaAll = mediaAll.concat( tsColSel.addSelectors( wo, prefix, column + 1 ) ); |
| 309 |
} |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
for (priority = 0; priority < wo.columnSelector_maxPriorities; priority++) { |
| 314 |
|
| 315 |
breaks = []; |
| 316 |
c.$headers.filter('[' + wo.columnSelector_priority + '=' + (priority + 1) + ']').each(function() { |
| 317 |
column = parseInt($(this).attr('data-column'), 10) + 1; |
| 318 |
|
| 319 |
if ( !isHidden[ column ] ) { |
| 320 |
breaks = breaks.concat( tsColSel.addSelectors( wo, prefix, column ) ); |
| 321 |
} |
| 322 |
}); |
| 323 |
if (breaks.length) { |
| 324 |
mediaAll = mediaAll.concat( breaks ); |
| 325 |
breakpts += tsColSel.queryBreak |
| 326 |
.replace(/\[size\]/g, wo.columnSelector_breakpoints[priority]) |
| 327 |
.replace(/\[columns\]/g, breaks.join(',')); |
| 328 |
} |
| 329 |
} |
| 330 |
if (colSel.$style) { |
| 331 |
colSel.$style.prop('disabled', true); |
| 332 |
} |
| 333 |
if (mediaAll.length) { |
| 334 |
colSel.$breakpoints |
| 335 |
.prop('disabled', false) |
| 336 |
.text( tsColSel.queryAll.replace(/\[columns\]/g, mediaAll.join(',')) + breakpts ); |
| 337 |
} |
| 338 |
}, |
| 339 |
updateCols: function(c, wo) { |
| 340 |
if (wo.columnSelector_mediaquery && c.selector.auto || c.selector.isInitializing) { |
| 341 |
return; |
| 342 |
} |
| 343 |
var column, |
| 344 |
colSel = c.selector, |
| 345 |
styles = [], |
| 346 |
prefix = c.namespace + 'columnselector'; |
| 347 |
colSel.$container.find('input[data-column]').filter('[data-column!="auto"]').each(function() { |
| 348 |
if (!this.checked) { |
| 349 |
column = parseInt( $(this).attr('data-column'), 10 ) + 1; |
| 350 |
styles = styles.concat( tsColSel.addSelectors( wo, prefix, column ) ); |
| 351 |
} |
| 352 |
$(this).toggleClass( wo.columnSelector_cssChecked, this.checked ); |
| 353 |
}); |
| 354 |
if (wo.columnSelector_mediaquery) { |
| 355 |
colSel.$breakpoints.prop('disabled', true); |
| 356 |
} |
| 357 |
if (colSel.$style) { |
| 358 |
colSel.$style.prop('disabled', false).text( styles.length ? styles.join(',') + ' { display: none; }' : '' ); |
| 359 |
} |
| 360 |
tsColSel.saveValues( c, wo ); |
| 361 |
tsColSel.adjustColspans( c, wo ); |
| 362 |
c.$table.triggerHandler(wo.columnSelector_updated); |
| 363 |
}, |
| 364 |
|
| 365 |
setUpColspan: function(c, wo) { |
| 366 |
var index, span, nspace, |
| 367 |
$window = $( window ), |
| 368 |
hasSpans = false, |
| 369 |
$cells = c.$table |
| 370 |
.add( $(c.namespace + '_extra_table') ) |
| 371 |
.children() |
| 372 |
.children('tr') |
| 373 |
.children('th, td'), |
| 374 |
len = $cells.length; |
| 375 |
for ( index = 0; index < len; index++ ) { |
| 376 |
span = $cells[ index ].colSpan; |
| 377 |
if ( span > 1 ) { |
| 378 |
hasSpans = true; |
| 379 |
$cells.eq( index ) |
| 380 |
.addClass( c.namespace.slice( 1 ) + 'columnselector' + wo.columnSelector_classHasSpan ) |
| 381 |
.attr( 'data-col-span', span ); |
| 382 |
|
| 383 |
ts.computeColumnIndex( $cells.eq( index ).parent().addClass( wo.columnSelector_classHasSpan ) ); |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
if ( hasSpans && wo.columnSelector_mediaquery ) { |
| 388 |
nspace = c.namespace + 'columnselector'; |
| 389 |
|
| 390 |
$window |
| 391 |
.off( nspace ) |
| 392 |
.on( 'resize' + nspace, ts.window_resize ) |
| 393 |
.on( 'resizeEnd' + nspace, function() { |
| 394 |
|
| 395 |
|
| 396 |
$window.off( 'resize' + nspace, ts.window_resize ); |
| 397 |
tsColSel.adjustColspans( c, wo ); |
| 398 |
$window.on( 'resize' + nspace, ts.window_resize ); |
| 399 |
}); |
| 400 |
} |
| 401 |
}, |
| 402 |
|
| 403 |
|
| 404 |
findHeaders : function(c) { |
| 405 |
var indx, $temp, |
| 406 |
sel = '.' + ts.css.scrollerHeader + ' thead > tr > ', |
| 407 |
$headers = $(sel + 'th,' + sel + 'td'), |
| 408 |
result = []; |
| 409 |
for ( indx = 0; indx < c.columns; indx++ ) { |
| 410 |
|
| 411 |
$temp = $headers.filter( '[data-column="' + indx + '"]' ); |
| 412 |
|
| 413 |
|
| 414 |
result[ indx ] = $temp.length ? |
| 415 |
$temp.not( '.sorter-false' ).length ? |
| 416 |
$temp.not( '.sorter-false' ).filter( ':last' ) : |
| 417 |
$temp.filter( ':last' ) : |
| 418 |
$(); |
| 419 |
} |
| 420 |
return result; |
| 421 |
}, |
| 422 |
|
| 423 |
adjustColspans: function(c, wo) { |
| 424 |
var index, cols, col, span, end, $cell, |
| 425 |
colSel = c.selector, |
| 426 |
filtered = wo.filter_filteredRow || 'filtered', |
| 427 |
autoModeOn = wo.columnSelector_mediaquery && colSel.auto, |
| 428 |
|
| 429 |
$headers = c.$table.children( 'thead, tfoot' ).children().children() |
| 430 |
.add( $(c.namespace + '_extra_table').children( 'thead, tfoot' ).children().children() ) |
| 431 |
|
| 432 |
.add( c.$table.find( '.group-header' ).children() ), |
| 433 |
len = $headers.length, |
| 434 |
$headerIndexed = ts.hasWidget(c.table, 'scroller') |
| 435 |
? tsColSel.findHeaders(c) |
| 436 |
: c.$headerIndexed; |
| 437 |
for ( index = 0; index < len; index++ ) { |
| 438 |
$cell = $headers.eq(index); |
| 439 |
col = parseInt( $cell.attr('data-column'), 10 ) || $cell[0].cellIndex; |
| 440 |
span = parseInt( $cell.attr('data-col-span'), 10 ) || 1; |
| 441 |
end = col + span; |
| 442 |
if ( span > 1 ) { |
| 443 |
for ( cols = col; cols < end; cols++ ) { |
| 444 |
if ( !autoModeOn && colSel.states[ cols ] === false || |
| 445 |
autoModeOn && $headerIndexed[ cols ] && !$headerIndexed[ cols ].is(':visible') ) { |
| 446 |
span--; |
| 447 |
} |
| 448 |
} |
| 449 |
if ( span ) { |
| 450 |
$cell.removeClass( filtered )[0].colSpan = span; |
| 451 |
} else { |
| 452 |
$cell.addClass( filtered ); |
| 453 |
} |
| 454 |
} else if ( typeof colSel.states[ col ] !== 'undefined' && colSel.states[ col ] !== null ) { |
| 455 |
$cell.toggleClass( filtered, !autoModeOn && !colSel.states[ col ] ); |
| 456 |
} |
| 457 |
} |
| 458 |
}, |
| 459 |
|
| 460 |
saveValues : function( c, wo ) { |
| 461 |
if ( wo.columnSelector_saveColumns && ts.storage ) { |
| 462 |
var colSel = c.selector; |
| 463 |
ts.storage( c.$table[0], 'tablesorter-columnSelector-auto', { auto : colSel.auto } ); |
| 464 |
ts.storage( c.$table[0], 'tablesorter-columnSelector', colSel.states ); |
| 465 |
} |
| 466 |
}, |
| 467 |
|
| 468 |
attachTo : function(table, elm) { |
| 469 |
table = $(table)[0]; |
| 470 |
var colSel, wo, indx, |
| 471 |
c = table.config, |
| 472 |
$popup = $(elm); |
| 473 |
if ($popup.length && c) { |
| 474 |
if (!$popup.find('.tablesorter-column-selector').length) { |
| 475 |
|
| 476 |
$popup.append('<span class="tablesorter-column-selector"></span>'); |
| 477 |
} |
| 478 |
colSel = c.selector; |
| 479 |
wo = c.widgetOptions; |
| 480 |
$popup.find('.tablesorter-column-selector') |
| 481 |
.html( colSel.$container.html() ) |
| 482 |
.find('input').each(function() { |
| 483 |
var indx = $(this).attr('data-column'), |
| 484 |
isChecked = indx === 'auto' ? colSel.auto : colSel.states[indx]; |
| 485 |
$(this) |
| 486 |
.toggleClass( wo.columnSelector_cssChecked, isChecked ) |
| 487 |
.prop( 'checked', isChecked ); |
| 488 |
}); |
| 489 |
colSel.$popup = $popup.on('change', 'input', function() { |
| 490 |
if (!colSel.isInitializing) { |
| 491 |
if (tsColSel.checkChange(c, this.checked)) { |
| 492 |
|
| 493 |
indx = $(this).toggleClass( wo.columnSelector_cssChecked, this.checked ).attr('data-column'); |
| 494 |
|
| 495 |
colSel.$container.find('input[data-column="' + indx + '"]') |
| 496 |
.prop('checked', this.checked) |
| 497 |
.trigger('change'); |
| 498 |
} else { |
| 499 |
this.checked = !this.checked; |
| 500 |
return false; |
| 501 |
} |
| 502 |
} |
| 503 |
}); |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
}; |
| 508 |
|
| 509 |
|
| 510 |
ts.window_resize = function() { |
| 511 |
if ( ts.timer_resize ) { |
| 512 |
clearTimeout( ts.timer_resize ); |
| 513 |
} |
| 514 |
ts.timer_resize = setTimeout( function() { |
| 515 |
$( window ).trigger( 'resizeEnd' ); |
| 516 |
}, 250 ); |
| 517 |
}; |
| 518 |
|
| 519 |
ts.addWidget({ |
| 520 |
id: 'columnSelector', |
| 521 |
priority: 10, |
| 522 |
options: { |
| 523 |
|
| 524 |
columnSelector_container : null, |
| 525 |
|
| 526 |
|
| 527 |
columnSelector_columns : {}, |
| 528 |
|
| 529 |
columnSelector_saveColumns: true, |
| 530 |
|
| 531 |
|
| 532 |
columnSelector_layout : '<label><input type="checkbox">{name}</label>', |
| 533 |
|
| 534 |
|
| 535 |
columnSelector_layoutCustomizer : null, |
| 536 |
|
| 537 |
columnSelector_name : 'data-selector-name', |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
columnSelector_mediaquery : true, |
| 542 |
|
| 543 |
columnSelector_mediaqueryName : 'Auto: ', |
| 544 |
|
| 545 |
columnSelector_mediaqueryState : true, |
| 546 |
|
| 547 |
columnSelector_mediaqueryHidden : false, |
| 548 |
|
| 549 |
columnSelector_maxVisible : null, |
| 550 |
columnSelector_minVisible : null, |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
columnSelector_breakpoints : [ '20em', '30em', '40em', '50em', '60em', '70em' ], |
| 556 |
|
| 557 |
|
| 558 |
columnSelector_maxPriorities : 6, |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
columnSelector_priority : 'data-priority', |
| 563 |
|
| 564 |
|
| 565 |
columnSelector_cssChecked : 'checked', |
| 566 |
|
| 567 |
columnSelector_classHasSpan : 'hasSpan', |
| 568 |
|
| 569 |
columnSelector_updated : 'columnUpdate' |
| 570 |
}, |
| 571 |
init: function(table, thisWidget, c, wo) { |
| 572 |
tsColSel.init(table, c, wo); |
| 573 |
}, |
| 574 |
remove: function(table, c, wo, refreshing) { |
| 575 |
var csel = c.selector; |
| 576 |
if ( refreshing || !csel ) { return; } |
| 577 |
if ( csel ) { csel.$container.empty(); } |
| 578 |
if ( csel.$popup ) { csel.$popup.empty(); } |
| 579 |
csel.$style.remove(); |
| 580 |
csel.$breakpoints.remove(); |
| 581 |
$( c.namespace + 'columnselector' + wo.columnSelector_classHasSpan ) |
| 582 |
.removeClass( wo.filter_filteredRow || 'filtered' ); |
| 583 |
c.$table.find('[data-col-span]').each(function(indx, el) { |
| 584 |
var $el = $(el); |
| 585 |
$el.attr('colspan', $el.attr('data-col-span')); |
| 586 |
}); |
| 587 |
c.$table.off('updateAll' + namespace + ' update' + namespace); |
| 588 |
} |
| 589 |
|
| 590 |
}); |
| 591 |
|
| 592 |
})(jQuery); |