| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
;( function( $, window ) { |
| 36 |
'use strict'; |
| 37 |
|
| 38 |
var ts = $.tablesorter, |
| 39 |
tscss = ts.css; |
| 40 |
|
| 41 |
$.extend( ts.css, { |
| 42 |
scrollerWrap : 'tablesorter-scroller', |
| 43 |
scrollerHeader : 'tablesorter-scroller-header', |
| 44 |
scrollerTable : 'tablesorter-scroller-table', |
| 45 |
scrollerFooter : 'tablesorter-scroller-footer', |
| 46 |
scrollerFixed : 'tablesorter-scroller-fixed', |
| 47 |
scrollerFixedPanel : 'tablesorter-scroller-fixed-panel', |
| 48 |
scrollerHasFix : 'tablesorter-scroller-has-fixed-columns', |
| 49 |
scrollerHideColumn : 'tablesorter-scroller-hidden-column', |
| 50 |
scrollerHideElement : 'tablesorter-scroller-hidden', |
| 51 |
scrollerSpacerRow : 'tablesorter-scroller-spacer', |
| 52 |
scrollerBarSpacer : 'tablesorter-scroller-bar-spacer', |
| 53 |
scrollerAddedHeight : 'tablesorter-scroller-added-height', |
| 54 |
scrollerHack : 'tablesorter-scroller-scrollbar-hack', |
| 55 |
|
| 56 |
|
| 57 |
scrollerRtl : 'ts-scroller-rtl' |
| 58 |
}); |
| 59 |
|
| 60 |
ts.addWidget({ |
| 61 |
id : 'scroller', |
| 62 |
priority : 60, |
| 63 |
options : { |
| 64 |
scroller_height : 300, |
| 65 |
|
| 66 |
scroller_jumpToHeader : true, |
| 67 |
|
| 68 |
scroller_upAfterSort : true, |
| 69 |
|
| 70 |
scroller_fixedColumns : 0, |
| 71 |
|
| 72 |
scroller_rowHighlight : 'hover', |
| 73 |
|
| 74 |
scroller_addFixedOverlay : false, |
| 75 |
|
| 76 |
|
| 77 |
scroller_barWidth : null |
| 78 |
}, |
| 79 |
format : function( table, c, wo ) { |
| 80 |
if ( c.isScrolling ) { |
| 81 |
ts.scroller.resize( c, wo ); |
| 82 |
} else { |
| 83 |
|
| 84 |
|
| 85 |
ts.scroller.setup( c, wo ); |
| 86 |
} |
| 87 |
}, |
| 88 |
remove : function( table, c, wo ) { |
| 89 |
ts.scroller.remove( c, wo ); |
| 90 |
} |
| 91 |
}); |
| 92 |
|
| 93 |
|
| 94 |
ts.window_resize = function() { |
| 95 |
if ( ts.timer_resize ) { |
| 96 |
clearTimeout( ts.timer_resize ); |
| 97 |
} |
| 98 |
ts.timer_resize = setTimeout( function() { |
| 99 |
$( window ).trigger( 'resizeEnd' ); |
| 100 |
}, 250 ); |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
$( function() { |
| 105 |
var style = '<style>' + |
| 106 |
|
| 107 |
'.' + tscss.scrollerWrap + ' { position: relative; overflow: hidden; }' + |
| 108 |
|
| 109 |
'.' + tscss.scrollerWrap + ' * { box-sizing: border-box; }' + |
| 110 |
'.' + tscss.scrollerHeader + ', .' + tscss.scrollerFooter + ' { position: relative; overflow: hidden; }' + |
| 111 |
'.' + tscss.scrollerHeader + ' table.' + tscss.table + ' { margin-bottom: 0; }' + |
| 112 |
|
| 113 |
|
| 114 |
'.' + tscss.scrollerTable + ' { position: relative; overflow: auto; }' + |
| 115 |
'.' + tscss.scrollerTable + ' table.' + tscss.table + |
| 116 |
' { border-top: 0; margin-top: 0; margin-bottom: 0; overflow: hidden; max-width: initial; }' + |
| 117 |
|
| 118 |
'.' + tscss.scrollerTable + ' tfoot, .' + tscss.scrollerHideElement + ', .' + tscss.scrollerHideColumn + |
| 119 |
' { display: none; }' + |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
'.' + tscss.scrollerFixed + ', .' + tscss.scrollerFixed + ' .' + tscss.scrollerFixedPanel + |
| 124 |
' { pointer-events: none; }' + |
| 125 |
|
| 126 |
'.' + tscss.scrollerFixed + ' > div { pointer-events: all; }' + |
| 127 |
'.' + tscss.scrollerWrap + ' .' + tscss.scrollerFixed + ' { position: absolute; top: 0; z-index: 1; left: 0 } ' + |
| 128 |
'.' + tscss.scrollerWrap + ' .' + tscss.scrollerFixed + '.' + tscss.scrollerRtl + ' { left: auto; right: 0 } ' + |
| 129 |
|
| 130 |
'.' + tscss.scrollerWrap + '.' + tscss.scrollerHasFix + ' > .' + tscss.scrollerTable + ' { overflow: auto; }' + |
| 131 |
|
| 132 |
|
| 133 |
'.' + tscss.scrollerFixed + ' .' + tscss.scrollerFooter + ' { position: absolute; bottom: 0; }' + |
| 134 |
|
| 135 |
'.' + tscss.scrollerFixed + ' .' + tscss.scrollerTable + |
| 136 |
' { position: relative; left: 0; overflow: auto; -ms-overflow-style: none; }' + |
| 137 |
'.' + tscss.scrollerFixed + ' .' + tscss.scrollerTable + '::-webkit-scrollbar { display: none; }' + |
| 138 |
|
| 139 |
'.' + tscss.scrollerWrap + ' .' + tscss.scrollerFixedPanel + |
| 140 |
' { position: absolute; top: 0; bottom: 0; z-index: 2; left: 0; right: 0; } ' + |
| 141 |
'</style>'; |
| 142 |
$( 'head' ).append( style ); |
| 143 |
}); |
| 144 |
|
| 145 |
ts.scroller = { |
| 146 |
|
| 147 |
|
| 148 |
isFirefox : navigator.userAgent.toLowerCase().indexOf( 'firefox' ) > -1, |
| 149 |
|
| 150 |
isOldIE : document.all && !window.atob, |
| 151 |
isIE : ( document.all && !window.atob ) || navigator.appVersion.indexOf( 'Trident/' ) > 0, |
| 152 |
|
| 153 |
|
| 154 |
isSafari : navigator.userAgent.toLowerCase().indexOf( 'safari' ) > -1 && |
| 155 |
navigator.userAgent.toLowerCase().indexOf( 'chrome' ) === -1, |
| 156 |
|
| 157 |
hasScrollBar : function( $target, checkWidth ) { |
| 158 |
if ( checkWidth ) { |
| 159 |
return $target.get(0).scrollWidth > $target.width(); |
| 160 |
} else { |
| 161 |
return $target.get(0).scrollHeight > $target.height(); |
| 162 |
} |
| 163 |
}, |
| 164 |
|
| 165 |
setWidth : function( $el, width ) { |
| 166 |
$el.css({ |
| 167 |
'width' : width, |
| 168 |
'min-width' : width, |
| 169 |
'max-width' : width |
| 170 |
}); |
| 171 |
}, |
| 172 |
|
| 173 |
|
| 174 |
getBarWidth : function() { |
| 175 |
var $div = $( '<div>' ).css({ |
| 176 |
'position' : 'absolute', |
| 177 |
'top' : '-9999px', |
| 178 |
'left' : 0, |
| 179 |
'width' : '100px', |
| 180 |
'height' : '100px', |
| 181 |
'overflow' : 'scroll', |
| 182 |
'visibility' : 'hidden' |
| 183 |
}).appendTo( 'body' ), |
| 184 |
div = $div[0], |
| 185 |
barWidth = div.offsetWidth - div.clientWidth; |
| 186 |
$div.remove(); |
| 187 |
return barWidth; |
| 188 |
}, |
| 189 |
|
| 190 |
setup : function( c, wo ) { |
| 191 |
var tbHt, $hdr, $t, $hCells, $tableWrap, events, tmp, detectedWidth, |
| 192 |
$win = $( window ), |
| 193 |
tsScroller = ts.scroller, |
| 194 |
namespace = c.namespace + 'tsscroller', |
| 195 |
$foot = $(), |
| 196 |
|
| 197 |
id = c.namespace.slice( 1 ) + 'tsscroller', |
| 198 |
$table = c.$table; |
| 199 |
|
| 200 |
|
| 201 |
c.widthFixed = true; |
| 202 |
|
| 203 |
wo.scroller_calcWidths = []; |
| 204 |
wo.scroller_saved = [ 0, 0 ]; |
| 205 |
wo.scroller_isBusy = true; |
| 206 |
wo.scroller_scrollTimer = null; |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
if ( wo.scroller_barWidth !== null ) { |
| 211 |
wo.scroller_barSetWidth = wo.scroller_barWidth; |
| 212 |
} else { |
| 213 |
detectedWidth = tsScroller.getBarWidth(); |
| 214 |
wo.scroller_barSetWidth = detectedWidth !== null ? detectedWidth : 15; |
| 215 |
} |
| 216 |
|
| 217 |
tmp = $table.children( 'caption' ); |
| 218 |
|
| 219 |
$hdr = $( '<table class="' + $table.attr( 'class' ) + '" cellpadding=0 cellspacing=0>' + |
| 220 |
( tmp.length ? tmp[ 0 ].outerHTML : '' ) + |
| 221 |
$table.children( 'thead' )[ 0 ].outerHTML + '</table>' ); |
| 222 |
wo.scroller_$header = $hdr.addClass( c.namespace.slice( 1 ) + '_extra_table' ); |
| 223 |
|
| 224 |
$t = $table.children( 'tfoot' ); |
| 225 |
if ( $t.length ) { |
| 226 |
$foot = $( '<table class="' + $table.attr( 'class' ) + |
| 227 |
'" cellpadding=0 cellspacing=0 style="margin-top:0"></table>' ) |
| 228 |
.addClass( c.namespace.slice( 1 ) + '_extra_table' ) |
| 229 |
|
| 230 |
.append( $t.clone( true ) ) |
| 231 |
.wrap( '<div class="' + tscss.scrollerFooter + '"/>' ); |
| 232 |
} |
| 233 |
wo.scroller_$footer = $foot; |
| 234 |
|
| 235 |
$table |
| 236 |
.wrap( '<div id="' + id + '" class="' + tscss.scrollerWrap + '" />' ) |
| 237 |
.before( $hdr ) |
| 238 |
|
| 239 |
.find( '.' + tscss.filterRow ) |
| 240 |
.addClass( tscss.filterRowHide ); |
| 241 |
|
| 242 |
wo.scroller_$container = $table.parent(); |
| 243 |
|
| 244 |
if ( $foot.length ) { |
| 245 |
|
| 246 |
$table.after( $foot.parent() ); |
| 247 |
} |
| 248 |
|
| 249 |
$hCells = $hdr |
| 250 |
.wrap( '<div class="' + tscss.scrollerHeader + '" />' ) |
| 251 |
.find( '.' + tscss.header ); |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
$table.wrap( '<div class="' + tscss.scrollerTable + |
| 256 |
( wo.scroller_height > 0 ? '" style="max-height:' + wo.scroller_height + 'px;">' : '">' ) ); |
| 257 |
$tableWrap = $table.parent(); |
| 258 |
|
| 259 |
|
| 260 |
ts.bindEvents( c.table, $hCells ); |
| 261 |
|
| 262 |
|
| 263 |
if ( $table.hasClass( 'hasFilters' ) ) { |
| 264 |
ts.filter.bindSearch( $table, $hdr.find( '.' + tscss.filter ) ); |
| 265 |
} |
| 266 |
|
| 267 |
$table |
| 268 |
.children( 'thead, caption' ) |
| 269 |
.addClass( tscss.scrollerHideElement ); |
| 270 |
tbHt = $tableWrap.parent().height(); |
| 271 |
|
| 272 |
|
| 273 |
$tableWrap |
| 274 |
.off( 'scroll' + namespace ) |
| 275 |
.on( 'scroll' + namespace, function() { |
| 276 |
|
| 277 |
clearTimeout(wo.scroller_scrollTimer); |
| 278 |
wo.scroller_scrollTimer = setTimeout(function() { |
| 279 |
wo.scroller_saved[0] = $tableWrap.scrollLeft(); |
| 280 |
wo.scroller_saved[1] = $tableWrap.scrollTop(); |
| 281 |
}, 300); |
| 282 |
if ( wo.scroller_jumpToHeader ) { |
| 283 |
var pos = $win.scrollTop() - $hdr.offset().top; |
| 284 |
if ( $( this ).scrollTop() !== 0 && pos < tbHt && pos > 0 ) { |
| 285 |
$win.scrollTop( $hdr.offset().top ); |
| 286 |
} |
| 287 |
} |
| 288 |
$hdr |
| 289 |
.parent() |
| 290 |
.add( $foot.parent() ) |
| 291 |
.scrollLeft( $( this ).scrollLeft() ); |
| 292 |
}); |
| 293 |
|
| 294 |
|
| 295 |
tmp = ts.hasWidget( c.table, 'filter' ) ? |
| 296 |
'filterEnd filterInit' : |
| 297 |
'tablesorter-initialized updateComplete'; |
| 298 |
events = ( tmp + ' sortEnd pagerComplete columnUpdate ' ).split( ' ' ).join( namespace + ' ' ); |
| 299 |
|
| 300 |
$table |
| 301 |
.off( namespace ) |
| 302 |
.on( 'sortStart' + namespace, function() { |
| 303 |
clearTimeout(wo.scroller_scrollTimer); |
| 304 |
wo.scroller_isBusy = true; |
| 305 |
}) |
| 306 |
.on( 'sortEnd filterEnd'.split( ' ' ).join( namespace + ' ' ), function( event ) { |
| 307 |
|
| 308 |
if ( event.type === 'sortEnd' && wo.scroller_upAfterSort ) { |
| 309 |
$tableWrap |
| 310 |
.scrollLeft( wo.scroller_saved[0] ) |
| 311 |
.animate({ scrollTop : 0 }, 'fast', function() { |
| 312 |
wo.scroller_isBusy = false; |
| 313 |
}); |
| 314 |
} else if ( wo.scroller_fixedColumns ) { |
| 315 |
setTimeout( function() { |
| 316 |
|
| 317 |
$tableWrap |
| 318 |
.scrollTop( wo.scroller_saved[1] ) |
| 319 |
.scrollLeft( wo.scroller_saved[0] ); |
| 320 |
tsScroller.updateFixed( c, wo ); |
| 321 |
}, 0 ); |
| 322 |
} |
| 323 |
}) |
| 324 |
.on( 'setFixedColumnSize' + namespace, function( event, size ) { |
| 325 |
var $wrap = wo.scroller_$container; |
| 326 |
if ( typeof size !== 'undefined' && !isNaN( size ) ) { |
| 327 |
wo.scroller_fixedColumns = parseInt( size, 10 ); |
| 328 |
} |
| 329 |
|
| 330 |
tsScroller.removeFixed( c, wo ); |
| 331 |
size = wo.scroller_fixedColumns; |
| 332 |
if ( size > 0 && size < c.columns - 1 ) { |
| 333 |
tsScroller.updateFixed( c, wo ); |
| 334 |
} else if ( $wrap.hasClass( tscss.scrollerHasFix ) ) { |
| 335 |
$wrap.removeClass( tscss.scrollerHasFix ); |
| 336 |
|
| 337 |
tsScroller.resize( c, wo ); |
| 338 |
} |
| 339 |
}) |
| 340 |
.on( events, function( event ) { |
| 341 |
|
| 342 |
if ( ts.hasWidget( 'pager' ) && event.type === 'updateComplete' ) { |
| 343 |
return; |
| 344 |
} |
| 345 |
if ( wo.scroller_fixedColumns > 0 ) { |
| 346 |
tsScroller.updateFixed( c, wo ); |
| 347 |
} |
| 348 |
|
| 349 |
tsScroller.resize( c, wo ); |
| 350 |
}); |
| 351 |
|
| 352 |
|
| 353 |
$win |
| 354 |
.off( 'resize resizeEnd '.split( ' ' ).join( namespace + ' ' ) ) |
| 355 |
.on( 'resize' + namespace, ts.window_resize ) |
| 356 |
.on( 'resizeEnd' + namespace, function() { |
| 357 |
|
| 358 |
|
| 359 |
$win.off( 'resize' + namespace, ts.window_resize ); |
| 360 |
tsScroller.resize( c, wo ); |
| 361 |
$win.on( 'resize' + namespace, ts.window_resize ); |
| 362 |
$tableWrap.trigger( 'scroll' + namespace ); |
| 363 |
}); |
| 364 |
|
| 365 |
|
| 366 |
c.isScrolling = true; |
| 367 |
|
| 368 |
tsScroller.updateFixed( c, wo ); |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
if ( c.table.hasInitialized && c.isScrolling ) { |
| 373 |
setTimeout(function() { |
| 374 |
ts.scroller.resize( c, wo ); |
| 375 |
}, 50); |
| 376 |
} |
| 377 |
|
| 378 |
}, |
| 379 |
|
| 380 |
resize : function( c, wo ) { |
| 381 |
if ( wo.scroller_isBusy ) { return; } |
| 382 |
var index, borderWidth, setWidth, $headers, $this, |
| 383 |
tsScroller = ts.scroller, |
| 384 |
$container = wo.scroller_$container, |
| 385 |
$table = c.$table, |
| 386 |
$tableWrap = $table.parent(), |
| 387 |
$hdr = wo.scroller_$header, |
| 388 |
$foot = wo.scroller_$footer, |
| 389 |
$win = $(window), |
| 390 |
position = [ $win.scrollLeft(), $win.scrollTop() ], |
| 391 |
id = c.namespace.slice( 1 ) + 'tsscroller', |
| 392 |
|
| 393 |
$div = $( 'div.' + tscss.scrollerWrap + '[id!="' + id + '"]' ) |
| 394 |
.addClass( tscss.scrollerHideElement ), |
| 395 |
temp = 'padding:0;margin:0;border:0;height:0;max-height:0;min-height:0;', |
| 396 |
row = '<tr class="' + tscss.scrollerSpacerRow + ' ' + c.selectorRemove.slice(1) + |
| 397 |
'" style="' + temp + '">'; |
| 398 |
|
| 399 |
wo.scroller_calcWidths = []; |
| 400 |
|
| 401 |
|
| 402 |
tsScroller.removeFixed( c, wo ); |
| 403 |
$container.find( '.' + tscss.scrollerSpacerRow ).remove(); |
| 404 |
|
| 405 |
$container.find( '.' + ts.css.colgroup ).remove(); |
| 406 |
|
| 407 |
|
| 408 |
$table |
| 409 |
.find( '.' + tscss.scrollerHideElement ) |
| 410 |
.removeClass( tscss.scrollerHideElement ); |
| 411 |
|
| 412 |
|
| 413 |
borderWidth = parseInt( $table.css( 'border-left-width' ), 10 ); |
| 414 |
|
| 415 |
$headers = c.$headerIndexed; |
| 416 |
|
| 417 |
for ( index = 0; index < c.columns; index++ ) { |
| 418 |
$this = $headers[ index ]; |
| 419 |
|
| 420 |
if ( $this.css( 'box-sizing' ) === 'border-box' ) { |
| 421 |
setWidth = $this.outerWidth(); |
| 422 |
} else { |
| 423 |
if ( $this.css( 'border-collapse' ) === 'collapse' ) { |
| 424 |
if ( $this.length && window.getComputedStyle ) { |
| 425 |
setWidth = parseFloat( window.getComputedStyle( $this[ 0 ], null ).width ); |
| 426 |
} else { |
| 427 |
|
| 428 |
setWidth = $this.outerWidth() - parseFloat( $this.css( 'padding-left' ) ) - |
| 429 |
parseFloat( $this.css( 'padding-right' ) ) - |
| 430 |
( parseFloat( $this.css( 'border-width' ) ) || 0 ); |
| 431 |
} |
| 432 |
} else { |
| 433 |
setWidth = $this.width(); |
| 434 |
} |
| 435 |
} |
| 436 |
row += '<td data-column="' + index + '" style="' + temp + 'width:' + setWidth + |
| 437 |
'px;min-width:' + setWidth + 'px;max-width:' + setWidth + 'px"></td>'; |
| 438 |
|
| 439 |
|
| 440 |
wo.scroller_calcWidths[ index ] = setWidth; |
| 441 |
} |
| 442 |
row += '</tr>'; |
| 443 |
c.$tbodies.eq(0).append( row ); |
| 444 |
$hdr.children( 'thead' ).append( row ); |
| 445 |
$foot.children( 'tfoot' ).append( row ); |
| 446 |
|
| 447 |
|
| 448 |
ts.fixColumnWidth( c.table ); |
| 449 |
row = c.$table.children( 'colgroup' )[0].outerHTML; |
| 450 |
$hdr.append( row ); |
| 451 |
$foot.append( row ); |
| 452 |
|
| 453 |
temp = $tableWrap.parent().innerWidth() - |
| 454 |
( tsScroller.hasScrollBar( $tableWrap ) ? wo.scroller_barSetWidth : 0 ); |
| 455 |
$tableWrap.width( temp ); |
| 456 |
|
| 457 |
temp = ( tsScroller.hasScrollBar( $tableWrap ) ? wo.scroller_barSetWidth : 0 ) + borderWidth; |
| 458 |
setWidth = $tableWrap.innerWidth() - temp; |
| 459 |
|
| 460 |
$hdr |
| 461 |
.parent() |
| 462 |
.add( $foot.parent() ) |
| 463 |
.width( setWidth ); |
| 464 |
|
| 465 |
$tableWrap |
| 466 |
.width( setWidth + temp ); |
| 467 |
|
| 468 |
|
| 469 |
$table.children( 'thead, caption' ).addClass( tscss.scrollerHideElement ); |
| 470 |
|
| 471 |
|
| 472 |
tsScroller.updateFixed( c, wo ); |
| 473 |
|
| 474 |
$div.removeClass( tscss.scrollerHideElement ); |
| 475 |
|
| 476 |
|
| 477 |
$tableWrap.scrollTop( wo.scroller_saved[1] ); |
| 478 |
wo.scroller_$container |
| 479 |
.find( '.' + tscss.scrollerFixed ) |
| 480 |
.find( '.' + tscss.scrollerTable ) |
| 481 |
.scrollTop( wo.scroller_saved[1] ); |
| 482 |
$win.scrollLeft( position[0] ); |
| 483 |
$win.scrollTop( position[1] ); |
| 484 |
|
| 485 |
|
| 486 |
setTimeout( function() { |
| 487 |
c.$table.triggerHandler( 'resizableUpdate' ); |
| 488 |
c.$table.triggerHandler( 'scrollerComplete' ); |
| 489 |
}, 100 ); |
| 490 |
|
| 491 |
}, |
| 492 |
|
| 493 |
|
| 494 |
setupFixed : function( c, wo ) { |
| 495 |
var index, index2, $el, len, temp, $fixedColumn, $fixedTbody, |
| 496 |
$table = c.$table, |
| 497 |
$wrapper = wo.scroller_$container, |
| 498 |
fixedColumns = wo.scroller_fixedColumns; |
| 499 |
|
| 500 |
$fixedColumn = $wrapper |
| 501 |
.addClass( tscss.scrollerHasFix ) |
| 502 |
.clone() |
| 503 |
.addClass( tscss.scrollerFixed ) |
| 504 |
.removeClass( tscss.scrollerWrap ) |
| 505 |
.attr( 'id', '' ); |
| 506 |
|
| 507 |
$fixedColumn.find('caption').html(' '); |
| 508 |
|
| 509 |
if ( wo.scroller_addFixedOverlay ) { |
| 510 |
$fixedColumn.append( '<div class="' + tscss.scrollerFixedPanel + '">' ); |
| 511 |
} |
| 512 |
|
| 513 |
$fixedTbody = $fixedColumn.find( '.' + tscss.scrollerTable ); |
| 514 |
$fixedTbody |
| 515 |
.children( 'table' ) |
| 516 |
.addClass( c.namespace.slice( 1 ) + '_extra_table' ) |
| 517 |
.attr( 'id', '' ) |
| 518 |
.children( 'thead, tfoot' ) |
| 519 |
.remove(); |
| 520 |
|
| 521 |
wo.scroller_$fixedColumns = $fixedColumn; |
| 522 |
|
| 523 |
|
| 524 |
if ( $table.hasClass( tscss.scrollerRtl ) ) { |
| 525 |
$fixedColumn.addClass( tscss.scrollerRtl ); |
| 526 |
} |
| 527 |
|
| 528 |
$el = $fixedColumn.find( 'tr' ); |
| 529 |
len = $el.length; |
| 530 |
for ( index = 0; index < len; index++ ) { |
| 531 |
$el.eq( index ).children( ':gt(' + ( fixedColumns - 1 ) + ')' ).remove(); |
| 532 |
} |
| 533 |
$fixedColumn |
| 534 |
.addClass( tscss.scrollerHideElement ) |
| 535 |
.prependTo( $wrapper ); |
| 536 |
|
| 537 |
|
| 538 |
if ( c.$table.hasClass( 'hasFilters' ) ) { |
| 539 |
|
| 540 |
$el = $fixedColumn |
| 541 |
.find( '.' + tscss.filter ) |
| 542 |
.not( '.' + tscss.filterDisabled ) |
| 543 |
.prop( 'disabled', false ); |
| 544 |
ts.filter.bindSearch( $table, $fixedColumn.find( '.' + tscss.filter ) ); |
| 545 |
|
| 546 |
$el = $wrapper |
| 547 |
.children( '.' + tscss.scrollerHeader ) |
| 548 |
.find( '.' + tscss.filter ); |
| 549 |
len = $el.length; |
| 550 |
for ( index = 0; index < len; index++ ) { |
| 551 |
|
| 552 |
if ( !$el.eq( index ).hasClass( tscss.filterDisabled || 'disabled' ) ) { |
| 553 |
|
| 554 |
$el.eq( index ).prop( 'disabled', index < fixedColumns ); |
| 555 |
} |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
c.$table |
| 561 |
.add( '.' + tscss.scrollerFooter + ' table' ) |
| 562 |
.children( 'thead' ) |
| 563 |
.children( 'tr.' + tscss.headerRow ) |
| 564 |
.children() |
| 565 |
.attr( 'tabindex', -1 ); |
| 566 |
|
| 567 |
$el = wo.scroller_$header |
| 568 |
.add( $fixedColumn.find( '.' + tscss.scrollerTable + ' table' ) ) |
| 569 |
.children( 'thead' ) |
| 570 |
.children( 'tr.' + tscss.headerRow ); |
| 571 |
len = $el.length; |
| 572 |
for ( index = 0; index < len; index++ ) { |
| 573 |
temp = $el.eq( index ).children(); |
| 574 |
for ( index2 = 0; index2 < temp.length; index2++ ) { |
| 575 |
temp.eq( index2 ).attr( 'tabindex', index2 < fixedColumns ? -1 : 0 ); |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
ts.bindEvents( c.table, $fixedColumn.find( '.' + tscss.header ) ); |
| 580 |
ts.scroller.bindFixedColumnEvents( c, wo ); |
| 581 |
|
| 582 |
|
| 583 |
if ( ts.scroller.isFirefox || ts.scroller.isOldIE ) { |
| 584 |
$fixedTbody.wrap( '<div class="' + tscss.scrollerHack + '" style="overflow:hidden;">' ); |
| 585 |
} |
| 586 |
|
| 587 |
}, |
| 588 |
|
| 589 |
|
| 590 |
throttle : function(fn, threshhold, scope) { |
| 591 |
threshhold = threshhold || 50; |
| 592 |
var last, deferTimer; |
| 593 |
return function() { |
| 594 |
var context = scope || this, |
| 595 |
now = +(new Date()), |
| 596 |
args = arguments; |
| 597 |
if (last && now < last + threshhold) { |
| 598 |
|
| 599 |
clearTimeout(deferTimer); |
| 600 |
deferTimer = setTimeout(function() { |
| 601 |
last = now; |
| 602 |
fn.apply(context, args); |
| 603 |
}, threshhold); |
| 604 |
} else { |
| 605 |
last = now; |
| 606 |
fn.apply(context, args); |
| 607 |
} |
| 608 |
}; |
| 609 |
}, |
| 610 |
|
| 611 |
bindFixedColumnEvents : function( c, wo ) { |
| 612 |
|
| 613 |
var tsScroller = ts.scroller, |
| 614 |
namespace = c.namespace + 'tsscrollerFixed', |
| 615 |
events = 'scroll' + namespace, |
| 616 |
$fixedTbody = wo.scroller_$fixedColumns.find( '.' + tscss.scrollerTable ), |
| 617 |
fixedScroll = true, |
| 618 |
tableScroll = true; |
| 619 |
|
| 620 |
c.$table |
| 621 |
.parent() |
| 622 |
|
| 623 |
.off( events ) |
| 624 |
.on( events, tsScroller.throttle(function() { |
| 625 |
|
| 626 |
if ( !wo.scroller_isBusy && fixedScroll ) { |
| 627 |
tableScroll = false; |
| 628 |
var $this = $( this ); |
| 629 |
$fixedTbody[0].scrollTop = wo.scroller_saved[1] = $this.scrollTop(); |
| 630 |
wo.scroller_saved[0] = $this.scrollLeft(); |
| 631 |
setTimeout( function() { |
| 632 |
tableScroll = true; |
| 633 |
}, 20 ); |
| 634 |
} |
| 635 |
})); |
| 636 |
|
| 637 |
$fixedTbody |
| 638 |
.off( events ) |
| 639 |
.on( events, tsScroller.throttle(function() { |
| 640 |
|
| 641 |
if ( !wo.scroller_isBusy && tableScroll ) { |
| 642 |
fixedScroll = false; |
| 643 |
c.$table.parent()[0].scrollTop = wo.scroller_saved[1] = $( this ).scrollTop(); |
| 644 |
setTimeout( function() { |
| 645 |
fixedScroll = true; |
| 646 |
}, 20 ); |
| 647 |
} |
| 648 |
})) |
| 649 |
.scroll(); |
| 650 |
|
| 651 |
|
| 652 |
if ( wo.scroller_rowHighlight !== '' ) { |
| 653 |
events = 'mouseover mouseleave '.split( ' ' ).join( namespace + ' ' ); |
| 654 |
|
| 655 |
c.$table |
| 656 |
.off( events, 'tbody > tr' ) |
| 657 |
.on( events, 'tbody > tr', function( event ) { |
| 658 |
var indx = c.$table.children( 'tbody' ).children( 'tr' ).index( this ); |
| 659 |
$fixedTbody |
| 660 |
.children( 'table' ) |
| 661 |
.children( 'tbody' ) |
| 662 |
.children( 'tr' ) |
| 663 |
.eq( indx ) |
| 664 |
.add( this ) |
| 665 |
.toggleClass( wo.scroller_rowHighlight, event.type === 'mouseover' ); |
| 666 |
}); |
| 667 |
$fixedTbody |
| 668 |
.find( 'table' ) |
| 669 |
.off( events, 'tbody > tr' ) |
| 670 |
.on( events, 'tbody > tr', function( event ) { |
| 671 |
var $fixed = $fixedTbody.children( 'table' ).children( 'tbody' ).children( 'tr' ), |
| 672 |
indx = $fixed.index( this ); |
| 673 |
c.$table |
| 674 |
.children( 'tbody' ) |
| 675 |
.children( 'tr' ) |
| 676 |
.eq( indx ) |
| 677 |
.add( this ) |
| 678 |
.toggleClass( wo.scroller_rowHighlight, event.type === 'mouseover' ); |
| 679 |
}); |
| 680 |
} |
| 681 |
}, |
| 682 |
|
| 683 |
adjustWidth : function( c, wo, totalWidth, adj, dir ) { |
| 684 |
var $wrapper = wo.scroller_$container; |
| 685 |
|
| 686 |
|
| 687 |
$wrapper |
| 688 |
.children( '.' + tscss.scrollerTable ) |
| 689 |
.css( dir ? 'right' : 'left', totalWidth ); |
| 690 |
$wrapper |
| 691 |
.children( '.' + tscss.scrollerHeader + ', .' + tscss.scrollerFooter ) |
| 692 |
|
| 693 |
.css( dir ? 'right' : 'left', totalWidth + ( dir && ts.scroller.isSafari ? adj : 0 ) ); |
| 694 |
}, |
| 695 |
|
| 696 |
updateFixed : function( c, wo ) { |
| 697 |
var temp, adj, |
| 698 |
$wrapper = wo.scroller_$container, |
| 699 |
$hdr = wo.scroller_$header, |
| 700 |
$foot = wo.scroller_$footer, |
| 701 |
$table = c.$table, |
| 702 |
$tableWrap = $table.parent(), |
| 703 |
scrollBarWidth = wo.scroller_barSetWidth, |
| 704 |
dir = $table.hasClass( tscss.scrollerRtl ); |
| 705 |
|
| 706 |
if ( wo.scroller_fixedColumns === 0 ) { |
| 707 |
wo.scroller_isBusy = false; |
| 708 |
ts.scroller.removeFixed( c, wo ); |
| 709 |
temp = $wrapper.width(); |
| 710 |
$tableWrap.width( temp ); |
| 711 |
adj = ts.scroller.hasScrollBar( $tableWrap ) ? scrollBarWidth : 0; |
| 712 |
$hdr |
| 713 |
.parent() |
| 714 |
.add( $foot.parent() ) |
| 715 |
.width( temp - adj ); |
| 716 |
return; |
| 717 |
} |
| 718 |
|
| 719 |
if ( !c.isScrolling ) { |
| 720 |
return; |
| 721 |
} |
| 722 |
|
| 723 |
wo.scroller_isBusy = true; |
| 724 |
|
| 725 |
|
| 726 |
if ( !$wrapper.find( '.' + tscss.scrollerFixed ).length ) { |
| 727 |
ts.scroller.setupFixed( c, wo ); |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
var index, tbodyIndex, rowIndex, $tbody, $adjCol, $fb, totalRows, |
| 732 |
|
| 733 |
|
| 734 |
$mainTbodies = wo.scroller_$container |
| 735 |
.children( '.' + tscss.scrollerTable ) |
| 736 |
.children( 'table' ) |
| 737 |
.children( 'tbody' ), |
| 738 |
|
| 739 |
$rows = wo.scroller_$header |
| 740 |
.children( 'thead' ) |
| 741 |
.children( '.' + tscss.headerRow ), |
| 742 |
|
| 743 |
|
| 744 |
$fixedColumn = wo.scroller_$fixedColumns |
| 745 |
.addClass( tscss.scrollerHideElement ), |
| 746 |
|
| 747 |
|
| 748 |
$fixedTbodiesTable = $fixedColumn |
| 749 |
.find( '.' + tscss.scrollerTable ) |
| 750 |
.children( 'table' ), |
| 751 |
$fixedTbodies = $fixedTbodiesTable |
| 752 |
.children( 'tbody' ), |
| 753 |
|
| 754 |
tsScroller = ts.scroller, |
| 755 |
fixedColumns = wo.scroller_fixedColumns, |
| 756 |
|
| 757 |
getDim = function ($el, name, deflt) { |
| 758 |
return parseInt( $el.css(name) || '', 10 ) || deflt || 0; |
| 759 |
}, |
| 760 |
$temp = $table.find( 'tbody td' ), |
| 761 |
borderRightWidth = getDim( $temp, 'border-right-width', 1 ), |
| 762 |
borderSpacing = getDim( $temp, 'border-spacing', 0 ), |
| 763 |
totalWidth = getDim( $table, 'padding-left' ) + |
| 764 |
getDim( $table, 'padding-right' ) + |
| 765 |
|
| 766 |
getDim( $table, 'border-left-width', 1 ) * 2 + |
| 767 |
getDim( $table, 'border-right-width', 1 ) - |
| 768 |
borderRightWidth + borderSpacing / 2, |
| 769 |
widths = wo.scroller_calcWidths; |
| 770 |
|
| 771 |
ts.scroller.removeFixed( c, wo, false ); |
| 772 |
|
| 773 |
|
| 774 |
for ( index = 0; index < fixedColumns; index++ ) { |
| 775 |
totalWidth += widths[ index ] + borderSpacing; |
| 776 |
} |
| 777 |
|
| 778 |
|
| 779 |
totalWidth = totalWidth + borderRightWidth * 2; |
| 780 |
tsScroller.setWidth( $fixedColumn.add( $fixedColumn.children() ), totalWidth ); |
| 781 |
tsScroller.setWidth( $fixedColumn.children().children( 'table' ), totalWidth ); |
| 782 |
|
| 783 |
|
| 784 |
for ( tbodyIndex = 0; tbodyIndex < c.$tbodies.length; tbodyIndex++ ) { |
| 785 |
$tbody = $mainTbodies.eq( tbodyIndex ); |
| 786 |
if ( $tbody.length ) { |
| 787 |
|
| 788 |
$rows = $tbody.children(); |
| 789 |
totalRows = $rows.length; |
| 790 |
$fb = ts.processTbody( $fixedTbodiesTable, $fixedTbodies.eq( tbodyIndex ), true ); |
| 791 |
$fb.empty(); |
| 792 |
|
| 793 |
for ( rowIndex = 0; rowIndex < totalRows; rowIndex++ ) { |
| 794 |
$adjCol = $( $rows[ rowIndex ].outerHTML ); |
| 795 |
$adjCol |
| 796 |
.children( 'td, th' ) |
| 797 |
.slice( fixedColumns ) |
| 798 |
.remove(); |
| 799 |
$fb.append( $adjCol ); |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
ts.processTbody( $fixedTbodiesTable, $fb, false ); |
| 804 |
} |
| 805 |
} |
| 806 |
|
| 807 |
adj = ts.scroller.hasScrollBar( $tableWrap ) ? scrollBarWidth : 0; |
| 808 |
|
| 809 |
|
| 810 |
if ( tsScroller.isFirefox || tsScroller.isOldIE ) { |
| 811 |
$fixedTbodiesTable |
| 812 |
.css( 'width', totalWidth ) |
| 813 |
.parent() |
| 814 |
.css( 'width', totalWidth + adj ); |
| 815 |
} |
| 816 |
|
| 817 |
for ( index = 0; index < fixedColumns; index++ ) { |
| 818 |
temp = ':nth-child(' + ( index + 1 ) + ')'; |
| 819 |
$wrapper |
| 820 |
.children( 'div' ) |
| 821 |
.children( 'table' ) |
| 822 |
.find( 'th' + temp + ', td' + temp + ', col' + temp ) |
| 823 |
.addClass( tscss.scrollerHideColumn ); |
| 824 |
} |
| 825 |
$fixedColumn |
| 826 |
.removeClass( tscss.scrollerHideElement ) |
| 827 |
.find('colgroup') |
| 828 |
.each(function() { |
| 829 |
$(this) |
| 830 |
.find('col:gt(' + (fixedColumns - 1) + ')') |
| 831 |
.addClass( tscss.scrollerHideElement ); |
| 832 |
}); |
| 833 |
|
| 834 |
totalWidth = totalWidth - borderRightWidth; |
| 835 |
temp = $tableWrap.parent().innerWidth() - totalWidth; |
| 836 |
$tableWrap.width( temp ); |
| 837 |
|
| 838 |
$wrapper |
| 839 |
.children( '.' + tscss.scrollerTable ) |
| 840 |
.css( dir ? 'right' : 'left', totalWidth ); |
| 841 |
$wrapper |
| 842 |
.children( '.' + tscss.scrollerHeader + ', .' + tscss.scrollerFooter ) |
| 843 |
|
| 844 |
.css( dir ? 'right' : 'left', totalWidth + ( dir && ts.scroller.isSafari ? adj : 0 ) ); |
| 845 |
|
| 846 |
$hdr |
| 847 |
.parent() |
| 848 |
.add( $foot.parent() ) |
| 849 |
.width( temp - adj ); |
| 850 |
|
| 851 |
|
| 852 |
temp = ts.scroller.hasScrollBar( $tableWrap, true ); |
| 853 |
adj = temp ? scrollBarWidth : 0; |
| 854 |
if ( !$fixedColumn.find( '.' + tscss.scrollerBarSpacer ).length && temp ) { |
| 855 |
$temp = $( '<div class="' + tscss.scrollerBarSpacer + '">' ) |
| 856 |
.css( 'height', adj + 'px' ); |
| 857 |
$fixedColumn.find( '.' + tscss.scrollerTable ).append( $temp ); |
| 858 |
} else if ( !temp ) { |
| 859 |
$fixedColumn.find( '.' + tscss.scrollerBarSpacer ).remove(); |
| 860 |
} |
| 861 |
|
| 862 |
ts.scroller.updateRowHeight( c, wo ); |
| 863 |
|
| 864 |
$fixedColumn.height( $wrapper.height() ); |
| 865 |
|
| 866 |
$fixedColumn.removeClass( tscss.scrollerHideElement ); |
| 867 |
|
| 868 |
|
| 869 |
$fixedColumn.find('caption').height( wo.scroller_$header.find( 'caption' ).height() ); |
| 870 |
|
| 871 |
$tableWrap.scroll(); |
| 872 |
setTimeout(function() { |
| 873 |
wo.scroller_isBusy = false; |
| 874 |
}, 0); |
| 875 |
|
| 876 |
}, |
| 877 |
|
| 878 |
fixHeight : function( $rows, $fixedRows ) { |
| 879 |
var index, heightRow, heightFixed, $r, $f, |
| 880 |
addedHt = tscss.scrollerAddedHeight, |
| 881 |
len = $rows.length; |
| 882 |
for ( index = 0; index < len; index++ ) { |
| 883 |
$r = $rows.eq( index ); |
| 884 |
$f = $fixedRows.eq( index ); |
| 885 |
heightRow = $r.height(); |
| 886 |
heightFixed = $f.height(); |
| 887 |
if ( heightRow > heightFixed ) { |
| 888 |
$f.addClass( addedHt ).height( heightRow ); |
| 889 |
} else if ( heightRow < heightFixed ) { |
| 890 |
$r.addClass( addedHt ).height( heightFixed ); |
| 891 |
} |
| 892 |
} |
| 893 |
}, |
| 894 |
|
| 895 |
updateRowHeight : function( c, wo ) { |
| 896 |
var $rows, $fixed, |
| 897 |
$fixedColumns = wo.scroller_$fixedColumns; |
| 898 |
|
| 899 |
wo.scroller_$container |
| 900 |
.find( '.' + tscss.scrollerAddedHeight ) |
| 901 |
.removeClass( tscss.scrollerAddedHeight ) |
| 902 |
.height( '' ); |
| 903 |
|
| 904 |
$rows = wo.scroller_$header |
| 905 |
.children( 'thead' ) |
| 906 |
.children( 'tr' ); |
| 907 |
$fixed = $fixedColumns |
| 908 |
.children( '.' + tscss.scrollerHeader ) |
| 909 |
.children( 'table' ) |
| 910 |
.children( 'thead' ) |
| 911 |
.children( 'tr' ); |
| 912 |
ts.scroller.fixHeight( $rows, $fixed ); |
| 913 |
|
| 914 |
$rows = wo.scroller_$footer |
| 915 |
.children( 'tfoot' ) |
| 916 |
.children( 'tr' ); |
| 917 |
$fixed = $fixedColumns |
| 918 |
.children( '.' + tscss.scrollerFooter ) |
| 919 |
.children( 'table' ) |
| 920 |
.children( 'tfoot' ) |
| 921 |
.children( 'tr' ); |
| 922 |
ts.scroller.fixHeight( $rows, $fixed ); |
| 923 |
|
| 924 |
if ( ts.scroller.isFirefox || ts.scroller.isOldIE ) { |
| 925 |
|
| 926 |
$fixedColumns = $fixedColumns.find( '.' + tscss.scrollerHack ); |
| 927 |
} |
| 928 |
$rows = c.$table |
| 929 |
.children( 'tbody' ) |
| 930 |
.children( 'tr' ); |
| 931 |
$fixed = $fixedColumns |
| 932 |
.children( '.' + tscss.scrollerTable ) |
| 933 |
.children( 'table' ) |
| 934 |
.children( 'tbody' ) |
| 935 |
.children( 'tr' ); |
| 936 |
ts.scroller.fixHeight( $rows, $fixed ); |
| 937 |
|
| 938 |
}, |
| 939 |
|
| 940 |
removeFixed : function( c, wo, removeIt ) { |
| 941 |
var $table = c.$table, |
| 942 |
$wrapper = wo.scroller_$container, |
| 943 |
dir = $table.hasClass( tscss.scrollerRtl ); |
| 944 |
|
| 945 |
|
| 946 |
if ( removeIt || typeof removeIt === 'undefined' ) { |
| 947 |
$wrapper.find( '.' + tscss.scrollerFixed ).remove(); |
| 948 |
} |
| 949 |
|
| 950 |
$wrapper |
| 951 |
.find( '.' + tscss.scrollerHideColumn ) |
| 952 |
.removeClass( tscss.scrollerHideColumn ); |
| 953 |
|
| 954 |
|
| 955 |
$wrapper |
| 956 |
.children( ':not(.' + tscss.scrollerFixed + ')' ) |
| 957 |
.css( dir ? 'right' : 'left', 0 ); |
| 958 |
}, |
| 959 |
|
| 960 |
remove : function( c, wo ) { |
| 961 |
var $wrap = wo.scroller_$container, |
| 962 |
namespace = c.namespace + 'tsscroller'; |
| 963 |
c.$table.off( namespace ); |
| 964 |
$( window ).off( namespace ); |
| 965 |
if ( $wrap ) { |
| 966 |
c.$table |
| 967 |
.insertBefore( $wrap ) |
| 968 |
.find( 'thead' ) |
| 969 |
.removeClass( tscss.scrollerHideElement ) |
| 970 |
.children( 'tr.' + tscss.headerRow ) |
| 971 |
.children() |
| 972 |
.attr( 'tabindex', 0 ) |
| 973 |
.end() |
| 974 |
.find( '.' + tscss.filterRow ) |
| 975 |
.removeClass( tscss.scrollerHideElement + ' ' + tscss.filterRowHide ); |
| 976 |
c.$table |
| 977 |
.find( '.' + tscss.filter ) |
| 978 |
.not( '.' + tscss.filterDisabled ) |
| 979 |
.prop( 'disabled', false ); |
| 980 |
$wrap.remove(); |
| 981 |
c.isScrolling = false; |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
}; |
| 986 |
|
| 987 |
})( jQuery, window ); |