| 1 |
|
| 2 |
e |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
(function(window, document, undefined){ |
| 25 |
|
| 26 |
|
| 27 |
var factory = function( $, DataTable ) { |
| 28 |
"use strict"; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
var Scroller = function ( dt, opts ) { |
| 78 |
|
| 79 |
if ( ! (this instanceof Scroller) ) { |
| 80 |
alert( "Scroller warning: Scroller must be initialised with the 'new' keyword." ); |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
if ( opts === undefined ) { |
| 85 |
opts = {}; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
this.s = { |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
"dt": $.fn.dataTable.Api( dt ).settings()[0], |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
"tableTop": 0, |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
"tableBottom": 0, |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
"redrawTop": 0, |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
"redrawBottom": 0, |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
"autoHeight": true, |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
"viewportRows": 0, |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
"stateTO": null, |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
"drawTO": null, |
| 165 |
|
| 166 |
heights: { |
| 167 |
jump: null, |
| 168 |
page: null, |
| 169 |
virtual: null, |
| 170 |
scroll: null, |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
row: null, |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
viewport: null |
| 185 |
}, |
| 186 |
|
| 187 |
topRowFloat: 0, |
| 188 |
scrollDrawDiff: null, |
| 189 |
loaderVisible: false |
| 190 |
}; |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
this.s = $.extend( this.s, Scroller.oDefaults, opts ); |
| 195 |
|
| 196 |
|
| 197 |
this.s.heights.row = this.s.rowHeight; |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
this.dom = { |
| 206 |
"force": document.createElement('div'), |
| 207 |
"scroller": null, |
| 208 |
"table": null, |
| 209 |
"loader": null |
| 210 |
}; |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
if ( this.s.dt.oScroller ) { |
| 215 |
return; |
| 216 |
} |
| 217 |
|
| 218 |
this.s.dt.oScroller = this; |
| 219 |
|
| 220 |
|
| 221 |
this._fnConstruct(); |
| 222 |
}; |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
Scroller.prototype = { |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
"fnRowToPixels": function ( rowIdx, intParse, virtual ) |
| 251 |
{ |
| 252 |
var pixels; |
| 253 |
|
| 254 |
if ( virtual ) { |
| 255 |
pixels = this._domain( 'virtualToPhysical', rowIdx * this.s.heights.row ); |
| 256 |
} |
| 257 |
else { |
| 258 |
var diff = rowIdx - this.s.baseRowTop; |
| 259 |
pixels = this.s.baseScrollTop + (diff * this.s.heights.row); |
| 260 |
} |
| 261 |
|
| 262 |
return intParse || intParse === undefined ? |
| 263 |
parseInt( pixels, 10 ) : |
| 264 |
pixels; |
| 265 |
}, |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
"fnPixelsToRow": function ( pixels, intParse, virtual ) |
| 295 |
{ |
| 296 |
var diff = pixels - this.s.baseScrollTop; |
| 297 |
var row = virtual ? |
| 298 |
this._domain( 'physicalToVirtual', pixels ) / this.s.heights.row : |
| 299 |
( diff / this.s.heights.row ) + this.s.baseRowTop; |
| 300 |
|
| 301 |
return intParse || intParse === undefined ? |
| 302 |
parseInt( row, 10 ) : |
| 303 |
row; |
| 304 |
}, |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
"fnScrollToRow": function ( iRow, bAnimate ) |
| 331 |
{ |
| 332 |
var that = this; |
| 333 |
var ani = false; |
| 334 |
var px = this.fnRowToPixels( iRow ); |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
var preRows = ((this.s.displayBuffer-1)/2) * this.s.viewportRows; |
| 342 |
var drawRow = iRow - preRows; |
| 343 |
if ( drawRow < 0 ) { |
| 344 |
drawRow = 0; |
| 345 |
} |
| 346 |
|
| 347 |
if ( (px > this.s.redrawBottom || px < this.s.redrawTop) && this.s.dt._iDisplayStart !== drawRow ) { |
| 348 |
ani = true; |
| 349 |
px = this.fnRowToPixels( iRow, false, true ); |
| 350 |
} |
| 351 |
|
| 352 |
if ( typeof bAnimate == 'undefined' || bAnimate ) |
| 353 |
{ |
| 354 |
this.s.ani = ani; |
| 355 |
$(this.dom.scroller).animate( { |
| 356 |
"scrollTop": px |
| 357 |
}, function () { |
| 358 |
|
| 359 |
|
| 360 |
setTimeout( function () { |
| 361 |
that.s.ani = false; |
| 362 |
}, 25 ); |
| 363 |
} ); |
| 364 |
} |
| 365 |
else |
| 366 |
{ |
| 367 |
$(this.dom.scroller).scrollTop( px ); |
| 368 |
} |
| 369 |
}, |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
"fnMeasure": function ( bRedraw ) |
| 402 |
{ |
| 403 |
if ( this.s.autoHeight ) |
| 404 |
{ |
| 405 |
this._fnCalcRowHeight(); |
| 406 |
} |
| 407 |
|
| 408 |
var heights = this.s.heights; |
| 409 |
|
| 410 |
heights.viewport = $(this.dom.scroller).height(); |
| 411 |
this.s.viewportRows = parseInt( heights.viewport / heights.row, 10 )+1; |
| 412 |
this.s.dt._iDisplayLength = this.s.viewportRows * this.s.displayBuffer; |
| 413 |
|
| 414 |
if ( bRedraw === undefined || bRedraw ) |
| 415 |
{ |
| 416 |
this.s.dt.oInstance.fnDraw(); |
| 417 |
} |
| 418 |
}, |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
"_fnConstruct": function () |
| 432 |
{ |
| 433 |
var that = this; |
| 434 |
|
| 435 |
|
| 436 |
if ( !this.s.dt.oFeatures.bPaginate ) { |
| 437 |
this.s.dt.oApi._fnLog( this.s.dt, 0, 'Pagination must be enabled for Scroller' ); |
| 438 |
return; |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
this.dom.force.style.position = "relative"; |
| 445 |
this.dom.force.style.top = "0px"; |
| 446 |
this.dom.force.style.left = "0px"; |
| 447 |
this.dom.force.style.width = "1px"; |
| 448 |
|
| 449 |
this.dom.scroller = $('div.'+this.s.dt.oClasses.sScrollBody, this.s.dt.nTableWrapper)[0]; |
| 450 |
this.dom.scroller.appendChild( this.dom.force ); |
| 451 |
this.dom.scroller.style.position = "relative"; |
| 452 |
|
| 453 |
this.dom.table = $('>table', this.dom.scroller)[0]; |
| 454 |
this.dom.table.style.position = "absolute"; |
| 455 |
this.dom.table.style.top = "0px"; |
| 456 |
this.dom.table.style.left = "0px"; |
| 457 |
|
| 458 |
|
| 459 |
$(this.s.dt.nTableWrapper).addClass('DTS'); |
| 460 |
|
| 461 |
|
| 462 |
if ( this.s.loadingIndicator ) |
| 463 |
{ |
| 464 |
this.dom.loader = $('<div class="dataTables_processing DTS_Loading">'+this.s.dt.oLanguage.sLoadingRecords+'</div>') |
| 465 |
.css('display', 'none'); |
| 466 |
|
| 467 |
$(this.dom.scroller.parentNode) |
| 468 |
.css('position', 'relative') |
| 469 |
.append( this.dom.loader ); |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
if ( this.s.heights.row && this.s.heights.row != 'auto' ) |
| 474 |
{ |
| 475 |
this.s.autoHeight = false; |
| 476 |
} |
| 477 |
this.fnMeasure( false ); |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
this.s.ingnoreScroll = true; |
| 484 |
this.s.stateSaveThrottle = this.s.dt.oApi._fnThrottle( function () { |
| 485 |
that.s.dt.oApi._fnSaveState( that.s.dt ); |
| 486 |
}, 500 ); |
| 487 |
$(this.dom.scroller).on( 'scroll.DTS', function (e) { |
| 488 |
that._fnScroll.call( that ); |
| 489 |
} ); |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
$(this.dom.scroller).on('touchstart.DTS', function () { |
| 495 |
that._fnScroll.call( that ); |
| 496 |
} ); |
| 497 |
|
| 498 |
|
| 499 |
this.s.dt.aoDrawCallback.push( { |
| 500 |
"fn": function () { |
| 501 |
if ( that.s.dt.bInitialised ) { |
| 502 |
that._fnDrawCallback.call( that ); |
| 503 |
} |
| 504 |
}, |
| 505 |
"sName": "Scroller" |
| 506 |
} ); |
| 507 |
|
| 508 |
|
| 509 |
$(window).on( 'resize.DTS', function () { |
| 510 |
that.fnMeasure( false ); |
| 511 |
that._fnInfo(); |
| 512 |
} ); |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
var initialStateSave = true; |
| 518 |
this.s.dt.oApi._fnCallbackReg( this.s.dt, 'aoStateSaveParams', function (oS, oData) { |
| 519 |
|
| 520 |
|
| 521 |
if(initialStateSave && that.s.dt.oLoadedState){ |
| 522 |
oData.iScroller = that.s.dt.oLoadedState.iScroller; |
| 523 |
oData.iScrollerTopRow = that.s.dt.oLoadedState.iScrollerTopRow; |
| 524 |
initialStateSave = false; |
| 525 |
} else { |
| 526 |
oData.iScroller = that.dom.scroller.scrollTop; |
| 527 |
oData.iScrollerTopRow = that.s.topRowFloat; |
| 528 |
} |
| 529 |
}, "Scroller_State" ); |
| 530 |
|
| 531 |
if ( this.s.dt.oLoadedState ) { |
| 532 |
this.s.topRowFloat = this.s.dt.oLoadedState.iScrollerTopRow || 0; |
| 533 |
} |
| 534 |
|
| 535 |
$(this.s.dt.nTable).on( 'init.dt', function () { |
| 536 |
that.fnMeasure(); |
| 537 |
} ); |
| 538 |
|
| 539 |
|
| 540 |
this.s.dt.aoDestroyCallback.push( { |
| 541 |
"sName": "Scroller", |
| 542 |
"fn": function () { |
| 543 |
$(window).off( 'resize.DTS' ); |
| 544 |
$(that.dom.scroller).off('touchstart.DTS scroll.DTS'); |
| 545 |
$(that.s.dt.nTableWrapper).removeClass('DTS'); |
| 546 |
$('div.DTS_Loading', that.dom.scroller.parentNode).remove(); |
| 547 |
$(that.s.dt.nTable).off( 'init.dt' ); |
| 548 |
|
| 549 |
that.dom.table.style.position = ""; |
| 550 |
that.dom.table.style.top = ""; |
| 551 |
that.dom.table.style.left = ""; |
| 552 |
} |
| 553 |
} ); |
| 554 |
}, |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
"_fnScroll": function () |
| 567 |
{ |
| 568 |
var |
| 569 |
that = this, |
| 570 |
heights = this.s.heights, |
| 571 |
iScrollTop = this.dom.scroller.scrollTop, |
| 572 |
iTopRow; |
| 573 |
|
| 574 |
if ( this.s.skip ) { |
| 575 |
return; |
| 576 |
} |
| 577 |
|
| 578 |
if ( this.s.ingnoreScroll ) { |
| 579 |
return; |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
if ( this.s.dt.bFiltered || this.s.dt.bSorted ) { |
| 586 |
this.s.lastScrollTop = 0; |
| 587 |
return; |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
this._fnInfo(); |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
clearTimeout( this.s.stateTO ); |
| 598 |
this.s.stateTO = setTimeout( function () { |
| 599 |
that.s.dt.oApi._fnSaveState( that.s.dt ); |
| 600 |
}, 250 ); |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
if ( iScrollTop < this.s.redrawTop || iScrollTop > this.s.redrawBottom ) { |
| 606 |
var preRows = Math.ceil( ((this.s.displayBuffer-1)/2) * this.s.viewportRows ); |
| 607 |
|
| 608 |
if ( Math.abs( iScrollTop - this.s.lastScrollTop ) > heights.viewport || this.s.ani ) { |
| 609 |
iTopRow = parseInt(this._domain( 'physicalToVirtual', iScrollTop ) / heights.row, 10) - preRows; |
| 610 |
this.s.topRowFloat = (this._domain( 'physicalToVirtual', iScrollTop ) / heights.row); |
| 611 |
} |
| 612 |
else { |
| 613 |
iTopRow = this.fnPixelsToRow( iScrollTop ) - preRows; |
| 614 |
this.s.topRowFloat = this.fnPixelsToRow( iScrollTop, false ); |
| 615 |
} |
| 616 |
|
| 617 |
if ( iTopRow <= 0 ) { |
| 618 |
|
| 619 |
iTopRow = 0; |
| 620 |
} |
| 621 |
else if ( iTopRow + this.s.dt._iDisplayLength > this.s.dt.fnRecordsDisplay() ) { |
| 622 |
|
| 623 |
iTopRow = this.s.dt.fnRecordsDisplay() - this.s.dt._iDisplayLength; |
| 624 |
if ( iTopRow < 0 ) { |
| 625 |
iTopRow = 0; |
| 626 |
} |
| 627 |
} |
| 628 |
else if ( iTopRow % 2 !== 0 ) { |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
iTopRow++; |
| 633 |
} |
| 634 |
|
| 635 |
if ( iTopRow != this.s.dt._iDisplayStart ) { |
| 636 |
|
| 637 |
this.s.tableTop = $(this.s.dt.nTable).offset().top; |
| 638 |
this.s.tableBottom = $(this.s.dt.nTable).height() + this.s.tableTop; |
| 639 |
|
| 640 |
var draw = function () { |
| 641 |
if ( that.s.scrollDrawReq === null ) { |
| 642 |
that.s.scrollDrawReq = iScrollTop; |
| 643 |
} |
| 644 |
|
| 645 |
that.s.dt._iDisplayStart = iTopRow; |
| 646 |
that.s.dt.oApi._fnDraw( that.s.dt ); |
| 647 |
}; |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
if ( this.s.dt.oFeatures.bServerSide ) { |
| 653 |
clearTimeout( this.s.drawTO ); |
| 654 |
this.s.drawTO = setTimeout( draw, this.s.serverWait ); |
| 655 |
} |
| 656 |
else { |
| 657 |
draw(); |
| 658 |
} |
| 659 |
|
| 660 |
if ( this.dom.loader && ! this.s.loaderVisible ) { |
| 661 |
this.dom.loader.css( 'display', 'block' ); |
| 662 |
this.s.loaderVisible = true; |
| 663 |
} |
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
this.s.lastScrollTop = iScrollTop; |
| 668 |
this.s.stateSaveThrottle(); |
| 669 |
}, |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
_domain: function ( dir, val ) |
| 683 |
{ |
| 684 |
var heights = this.s.heights; |
| 685 |
var coeff; |
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
if ( heights.virtual === heights.scroll ) { |
| 690 |
coeff = (heights.virtual-heights.viewport) / (heights.scroll-heights.viewport); |
| 691 |
|
| 692 |
if ( dir === 'virtualToPhysical' ) { |
| 693 |
return val / coeff; |
| 694 |
} |
| 695 |
else if ( dir === 'physicalToVirtual' ) { |
| 696 |
return val * coeff; |
| 697 |
} |
| 698 |
} |
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
var xMax = (heights.scroll - heights.viewport) / 2; |
| 708 |
var yMax = (heights.virtual - heights.viewport) / 2; |
| 709 |
|
| 710 |
coeff = yMax / ( xMax * xMax ); |
| 711 |
|
| 712 |
if ( dir === 'virtualToPhysical' ) { |
| 713 |
if ( val < yMax ) { |
| 714 |
return Math.pow(val / coeff, 0.5); |
| 715 |
} |
| 716 |
else { |
| 717 |
val = (yMax*2) - val; |
| 718 |
return val < 0 ? |
| 719 |
heights.scroll : |
| 720 |
(xMax*2) - Math.pow(val / coeff, 0.5); |
| 721 |
} |
| 722 |
} |
| 723 |
else if ( dir === 'physicalToVirtual' ) { |
| 724 |
if ( val < xMax ) { |
| 725 |
return val * val * coeff; |
| 726 |
} |
| 727 |
else { |
| 728 |
val = (xMax*2) - val; |
| 729 |
return val < 0 ? |
| 730 |
heights.virtual : |
| 731 |
(yMax*2) - (val * val * coeff); |
| 732 |
} |
| 733 |
} |
| 734 |
}, |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
"_fnDrawCallback": function () |
| 745 |
{ |
| 746 |
var |
| 747 |
that = this, |
| 748 |
heights = this.s.heights, |
| 749 |
iScrollTop = this.dom.scroller.scrollTop, |
| 750 |
iActualScrollTop = iScrollTop, |
| 751 |
iScrollBottom = iScrollTop + heights.viewport, |
| 752 |
iTableHeight = $(this.s.dt.nTable).height(), |
| 753 |
displayStart = this.s.dt._iDisplayStart, |
| 754 |
displayLen = this.s.dt._iDisplayLength, |
| 755 |
displayEnd = this.s.dt.fnRecordsDisplay(); |
| 756 |
|
| 757 |
|
| 758 |
this.s.skip = true; |
| 759 |
|
| 760 |
|
| 761 |
this._fnScrollForce(); |
| 762 |
|
| 763 |
|
| 764 |
if ( displayStart === 0 ) { |
| 765 |
|
| 766 |
iScrollTop = this.s.topRowFloat * heights.row; |
| 767 |
} |
| 768 |
else if ( displayStart + displayLen >= displayEnd ) { |
| 769 |
|
| 770 |
iScrollTop = heights.scroll - ((displayEnd - this.s.topRowFloat) * heights.row); |
| 771 |
} |
| 772 |
else { |
| 773 |
|
| 774 |
iScrollTop = this._domain( 'virtualToPhysical', this.s.topRowFloat * heights.row ); |
| 775 |
} |
| 776 |
|
| 777 |
this.dom.scroller.scrollTop = iScrollTop; |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
this.s.baseScrollTop = iScrollTop; |
| 782 |
this.s.baseRowTop = this.s.topRowFloat; |
| 783 |
|
| 784 |
|
| 785 |
var tableTop = iScrollTop - ((this.s.topRowFloat - displayStart) * heights.row); |
| 786 |
if ( displayStart === 0 ) { |
| 787 |
tableTop = 0; |
| 788 |
} |
| 789 |
else if ( displayStart + displayLen >= displayEnd ) { |
| 790 |
tableTop = heights.scroll - iTableHeight; |
| 791 |
} |
| 792 |
|
| 793 |
this.dom.table.style.top = tableTop+'px'; |
| 794 |
|
| 795 |
|
| 796 |
this.s.tableTop = tableTop; |
| 797 |
this.s.tableBottom = iTableHeight + this.s.tableTop; |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
var boundaryPx = (iScrollTop - this.s.tableTop) * this.s.boundaryScale; |
| 802 |
this.s.redrawTop = iScrollTop - boundaryPx; |
| 803 |
this.s.redrawBottom = iScrollTop + boundaryPx; |
| 804 |
|
| 805 |
this.s.skip = false; |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
if ( this.s.dt.oFeatures.bStateSave && this.s.dt.oLoadedState !== null && |
| 811 |
typeof this.s.dt.oLoadedState.iScroller != 'undefined' ) |
| 812 |
{ |
| 813 |
|
| 814 |
|
| 815 |
var ajaxSourced = (this.s.dt.sAjaxSource || that.s.dt.ajax) && ! this.s.dt.oFeatures.bServerSide ? |
| 816 |
true : |
| 817 |
false; |
| 818 |
|
| 819 |
if ( ( ajaxSourced && this.s.dt.iDraw == 2) || |
| 820 |
(!ajaxSourced && this.s.dt.iDraw == 1) ) |
| 821 |
{ |
| 822 |
setTimeout( function () { |
| 823 |
$(that.dom.scroller).scrollTop( that.s.dt.oLoadedState.iScroller ); |
| 824 |
that.s.redrawTop = that.s.dt.oLoadedState.iScroller - (heights.viewport/2); |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
setTimeout( function () { |
| 829 |
that.s.ingnoreScroll = false; |
| 830 |
}, 0 ); |
| 831 |
}, 0 ); |
| 832 |
} |
| 833 |
} |
| 834 |
else { |
| 835 |
that.s.ingnoreScroll = false; |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
setTimeout( function () { |
| 842 |
that._fnInfo.call( that ); |
| 843 |
}, 0 ); |
| 844 |
|
| 845 |
|
| 846 |
if ( this.dom.loader && this.s.loaderVisible ) { |
| 847 |
this.dom.loader.css( 'display', 'none' ); |
| 848 |
this.s.loaderVisible = false; |
| 849 |
} |
| 850 |
}, |
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
_fnScrollForce: function () |
| 865 |
{ |
| 866 |
var heights = this.s.heights; |
| 867 |
var max = 1000000; |
| 868 |
|
| 869 |
heights.virtual = heights.row * this.s.dt.fnRecordsDisplay(); |
| 870 |
heights.scroll = heights.virtual; |
| 871 |
|
| 872 |
if ( heights.scroll > max ) { |
| 873 |
heights.scroll = max; |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
this.dom.force.style.height = heights.scroll > this.s.heights.row ? |
| 879 |
heights.scroll+'px' : |
| 880 |
this.s.heights.row+'px'; |
| 881 |
}, |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
"_fnCalcRowHeight": function () |
| 893 |
{ |
| 894 |
var dt = this.s.dt; |
| 895 |
var origTable = dt.nTable; |
| 896 |
var nTable = origTable.cloneNode( false ); |
| 897 |
var tbody = $('<tbody/>').appendTo( nTable ); |
| 898 |
var container = $( |
| 899 |
'<div class="'+dt.oClasses.sWrapper+' DTS">'+ |
| 900 |
'<div class="'+dt.oClasses.sScrollWrapper+'">'+ |
| 901 |
'<div class="'+dt.oClasses.sScrollBody+'"></div>'+ |
| 902 |
'</div>'+ |
| 903 |
'</div>' |
| 904 |
); |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
$('tbody tr:lt(4)', origTable).clone().appendTo( tbody ); |
| 909 |
while( $('tr', tbody).length < 3 ) { |
| 910 |
tbody.append( '<tr><td> </td></tr>' ); |
| 911 |
} |
| 912 |
|
| 913 |
$('div.'+dt.oClasses.sScrollBody, container).append( nTable ); |
| 914 |
|
| 915 |
|
| 916 |
container.appendTo( this.s.dt.nHolding || origTable.parentNode ); |
| 917 |
this.s.heights.row = $('tr', tbody).eq(1).outerHeight(); |
| 918 |
|
| 919 |
container.remove(); |
| 920 |
}, |
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
"_fnInfo": function () |
| 931 |
{ |
| 932 |
if ( !this.s.dt.oFeatures.bInfo ) |
| 933 |
{ |
| 934 |
return; |
| 935 |
} |
| 936 |
|
| 937 |
var |
| 938 |
dt = this.s.dt, |
| 939 |
language = dt.oLanguage, |
| 940 |
iScrollTop = this.dom.scroller.scrollTop, |
| 941 |
iStart = Math.floor( this.fnPixelsToRow(iScrollTop, false, this.s.ani)+1 ), |
| 942 |
iMax = dt.fnRecordsTotal(), |
| 943 |
iTotal = dt.fnRecordsDisplay(), |
| 944 |
iPossibleEnd = Math.ceil( this.fnPixelsToRow(iScrollTop+this.s.heights.viewport, false, this.s.ani) ), |
| 945 |
iEnd = iTotal < iPossibleEnd ? iTotal : iPossibleEnd, |
| 946 |
sStart = dt.fnFormatNumber( iStart ), |
| 947 |
sEnd = dt.fnFormatNumber( iEnd ), |
| 948 |
sMax = dt.fnFormatNumber( iMax ), |
| 949 |
sTotal = dt.fnFormatNumber( iTotal ), |
| 950 |
sOut; |
| 951 |
|
| 952 |
if ( dt.fnRecordsDisplay() === 0 && |
| 953 |
dt.fnRecordsDisplay() == dt.fnRecordsTotal() ) |
| 954 |
{ |
| 955 |
|
| 956 |
sOut = language.sInfoEmpty+ language.sInfoPostFix; |
| 957 |
} |
| 958 |
else if ( dt.fnRecordsDisplay() === 0 ) |
| 959 |
{ |
| 960 |
|
| 961 |
sOut = language.sInfoEmpty +' '+ |
| 962 |
language.sInfoFiltered.replace('_MAX_', sMax)+ |
| 963 |
language.sInfoPostFix; |
| 964 |
} |
| 965 |
else if ( dt.fnRecordsDisplay() == dt.fnRecordsTotal() ) |
| 966 |
{ |
| 967 |
|
| 968 |
sOut = language.sInfo. |
| 969 |
replace('_START_', sStart). |
| 970 |
replace('_END_', sEnd). |
| 971 |
replace('_MAX_', sMax). |
| 972 |
replace('_TOTAL_', sTotal)+ |
| 973 |
language.sInfoPostFix; |
| 974 |
} |
| 975 |
else |
| 976 |
{ |
| 977 |
|
| 978 |
sOut = language.sInfo. |
| 979 |
replace('_START_', sStart). |
| 980 |
replace('_END_', sEnd). |
| 981 |
replace('_MAX_', sMax). |
| 982 |
replace('_TOTAL_', sTotal) +' '+ |
| 983 |
language.sInfoFiltered.replace( |
| 984 |
'_MAX_', |
| 985 |
dt.fnFormatNumber(dt.fnRecordsTotal()) |
| 986 |
)+ |
| 987 |
language.sInfoPostFix; |
| 988 |
} |
| 989 |
|
| 990 |
var callback = language.fnInfoCallback; |
| 991 |
if ( callback ) { |
| 992 |
sOut = callback.call( dt.oInstance, |
| 993 |
dt, iStart, iEnd, iMax, iTotal, sOut |
| 994 |
); |
| 995 |
} |
| 996 |
|
| 997 |
var n = dt.aanFeatures.i; |
| 998 |
if ( typeof n != 'undefined' ) |
| 999 |
{ |
| 1000 |
for ( var i=0, iLen=n.length ; i<iLen ; i++ ) |
| 1001 |
{ |
| 1002 |
$(n[i]).html( sOut ); |
| 1003 |
} |
| 1004 |
} |
| 1005 |
} |
| 1006 |
}; |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
Scroller.defaults = { |
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
"trace": false, |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
"rowHeight": "auto", |
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
"serverWait": 200, |
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
"displayBuffer": 9, |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
"boundaryScale": 0.5, |
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
"loadingIndicator": false |
| 1142 |
}; |
| 1143 |
|
| 1144 |
Scroller.oDefaults = Scroller.defaults; |
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
Scroller.version = "1.3.0"; |
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
if ( typeof $.fn.dataTable == "function" && |
| 1169 |
typeof $.fn.dataTableExt.fnVersionCheck == "function" && |
| 1170 |
$.fn.dataTableExt.fnVersionCheck('1.10.0') ) |
| 1171 |
{ |
| 1172 |
$.fn.dataTableExt.aoFeatures.push( { |
| 1173 |
"fnInit": function( oDTSettings ) { |
| 1174 |
var init = oDTSettings.oInit; |
| 1175 |
var opts = init.scroller || init.oScroller || {}; |
| 1176 |
|
| 1177 |
new Scroller( oDTSettings, opts ); |
| 1178 |
}, |
| 1179 |
"cFeature": "S", |
| 1180 |
"sFeature": "Scroller" |
| 1181 |
} ); |
| 1182 |
} |
| 1183 |
else |
| 1184 |
{ |
| 1185 |
alert( "Warning: Scroller requires DataTables 1.10.0 or greater - www.datatables.net/download"); |
| 1186 |
} |
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
$(document).on( 'preInit.dt.dtscroller', function (e, settings) { |
| 1191 |
if ( e.namespace !== 'dt' ) { |
| 1192 |
return; |
| 1193 |
} |
| 1194 |
|
| 1195 |
var init = settings.oInit.scroller; |
| 1196 |
var defaults = DataTable.defaults.scroller; |
| 1197 |
|
| 1198 |
if ( init || defaults ) { |
| 1199 |
var opts = $.extend( {}, init, defaults ); |
| 1200 |
|
| 1201 |
if ( init !== false ) { |
| 1202 |
new Scroller( settings, opts ); |
| 1203 |
} |
| 1204 |
} |
| 1205 |
} ); |
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
$.fn.dataTable.Scroller = Scroller; |
| 1210 |
$.fn.DataTable.Scroller = Scroller; |
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
var Api = $.fn.dataTable.Api; |
| 1215 |
|
| 1216 |
Api.register( 'scroller()', function () { |
| 1217 |
return this; |
| 1218 |
} ); |
| 1219 |
|
| 1220 |
|
| 1221 |
Api.register( 'scroller().rowToPixels()', function ( rowIdx, intParse, virtual ) { |
| 1222 |
var ctx = this.context; |
| 1223 |
|
| 1224 |
if ( ctx.length && ctx[0].oScroller ) { |
| 1225 |
return ctx[0].oScroller.fnRowToPixels( rowIdx, intParse, virtual ); |
| 1226 |
} |
| 1227 |
|
| 1228 |
} ); |
| 1229 |
|
| 1230 |
|
| 1231 |
Api.register( 'scroller().pixelsToRow()', function ( pixels, intParse, virtual ) { |
| 1232 |
var ctx = this.context; |
| 1233 |
|
| 1234 |
if ( ctx.length && ctx[0].oScroller ) { |
| 1235 |
return ctx[0].oScroller.fnPixelsToRow( pixels, intParse, virtual ); |
| 1236 |
} |
| 1237 |
|
| 1238 |
} ); |
| 1239 |
|
| 1240 |
|
| 1241 |
Api.register( 'scroller().scrollToRow()', function ( row, ani ) { |
| 1242 |
this.iterator( 'table', function ( ctx ) { |
| 1243 |
if ( ctx.oScroller ) { |
| 1244 |
ctx.oScroller.fnScrollToRow( row, ani ); |
| 1245 |
} |
| 1246 |
} ); |
| 1247 |
|
| 1248 |
return this; |
| 1249 |
} ); |
| 1250 |
|
| 1251 |
Api.register( 'row().scrollTo()', function ( ani ) { |
| 1252 |
var that = this; |
| 1253 |
|
| 1254 |
this.iterator( 'row', function ( ctx, rowIdx ) { |
| 1255 |
if ( ctx.oScroller ) { |
| 1256 |
var displayIdx = that |
| 1257 |
.rows( { order: 'applied', search: 'applied' } ) |
| 1258 |
.indexes() |
| 1259 |
.indexOf( rowIdx ); |
| 1260 |
|
| 1261 |
ctx.oScroller.fnScrollToRow( displayIdx, ani ); |
| 1262 |
} |
| 1263 |
} ); |
| 1264 |
|
| 1265 |
return this; |
| 1266 |
} ); |
| 1267 |
|
| 1268 |
Api.register( 'scroller.measure()', function ( redraw ) { |
| 1269 |
this.iterator( 'table', function ( ctx ) { |
| 1270 |
if ( ctx.oScroller ) { |
| 1271 |
ctx.oScroller.fnMeasure( redraw ); |
| 1272 |
} |
| 1273 |
} ); |
| 1274 |
|
| 1275 |
return this; |
| 1276 |
} ); |
| 1277 |
|
| 1278 |
|
| 1279 |
return Scroller; |
| 1280 |
}; |
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
if ( typeof define === 'function' && define.amd ) { |
| 1285 |
define( ['jquery', 'datatables'], factory ); |
| 1286 |
} |
| 1287 |
else if ( typeof exports === 'object' ) { |
| 1288 |
|
| 1289 |
factory( require('jquery'), require('datatables') ); |
| 1290 |
} |
| 1291 |
else if ( jQuery && !jQuery.fn.dataTable.Scroller ) { |
| 1292 |
|
| 1293 |
factory( jQuery, jQuery.fn.dataTable ); |
| 1294 |
} |
| 1295 |
|
| 1296 |
|
| 1297 |
})(window, document); |
| 1298 |
|