META-INF.resources.bower_components.datatables.net-scroller.js.dataTables.scroller.min.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jwebmp-data-tables Show documentation
Show all versions of jwebmp-data-tables Show documentation
The JWebSwing implementation for Data Tables
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery","datatables.net"],function($){return factory($,window,document)})}else if(typeof exports==="object"){module.exports=function(root,$){if(!root){root=window}if(!$||!$.fn.dataTable){$=require("datatables.net")(root,$).$}return factory($,root,root.document)}}else{factory(jQuery,window,document)}})(function($,window,document,undefined){"use strict";var DataTable=$.fn.dataTable;var Scroller=function(dt,opts){if(!(this instanceof Scroller)){alert("Scroller warning: Scroller must be initialised with the 'new' keyword.");return}if(opts===undefined){opts={}}var dtApi=$.fn.dataTable.Api(dt);this.s={dt:dtApi.settings()[0],dtApi:dtApi,tableTop:0,tableBottom:0,redrawTop:0,redrawBottom:0,autoHeight:true,viewportRows:0,stateTO:null,drawTO:null,heights:{jump:null,page:null,virtual:null,scroll:null,row:null,viewport:null},topRowFloat:0,scrollDrawDiff:null,loaderVisible:false,forceReposition:false};this.s=$.extend(this.s,Scroller.oDefaults,opts);this.s.heights.row=this.s.rowHeight;this.dom={force:document.createElement("div"),scroller:null,table:null,loader:null};if(this.s.dt.oScroller){return}this.s.dt.oScroller=this;this._fnConstruct()};$.extend(Scroller.prototype,{fnRowToPixels:function(rowIdx,intParse,virtual){var pixels;var diff=rowIdx-this.s.baseRowTop;if(virtual){pixels=this._domain("virtualToPhysical",this.s.baseScrollTop);pixels+=diff*this.s.heights.row}else{pixels=this.s.baseScrollTop;pixels+=diff*this.s.heights.row}return intParse||intParse===undefined?parseInt(pixels,10):pixels},fnPixelsToRow:function(pixels,intParse,virtual){var diff=pixels-this.s.baseScrollTop;var row=virtual?(this._domain("physicalToVirtual",this.s.baseScrollTop)+diff)/this.s.heights.row:diff/this.s.heights.row+this.s.baseRowTop;return intParse||intParse===undefined?parseInt(row,10):row},fnScrollToRow:function(iRow,bAnimate){var that=this;var ani=false;var px=this.fnRowToPixels(iRow);var preRows=(this.s.displayBuffer-1)/2*this.s.viewportRows;var drawRow=iRow-preRows;if(drawRow<0){drawRow=0}if((px>this.s.redrawBottom||pxtable",this.dom.scroller)[0];this.dom.table.style.position="absolute";this.dom.table.style.top="0px";this.dom.table.style.left="0px";$(dt.table().container()).addClass("DTS");if(this.s.loadingIndicator){this.dom.loader=$(''+this.s.dt.oLanguage.sLoadingRecords+"").css("display","none");$(this.dom.scroller.parentNode).css("position","relative").append(this.dom.loader)}if(this.s.heights.row&&this.s.heights.row!="auto"){this.s.autoHeight=false}this.fnMeasure(false);this.s.ingnoreScroll=true;this.s.stateSaveThrottle=this.s.dt.oApi._fnThrottle(function(){that.s.dtApi.state.save()},500);$(this.dom.scroller).on("scroll.dt-scroller",function(e){that._fnScroll.call(that)});$(this.dom.scroller).on("touchstart.dt-scroller",function(){that._fnScroll.call(that)});$(window).on("resize.dt-scroller",function(){that.fnMeasure(false);that._fnInfo()});var initialStateSave=true;var loadedState=dt.state.loaded();dt.on("stateSaveParams.scroller",function(e,settings,data){data.scroller={topRow:initialStateSave&&loadedState&&loadedState.scroller?loadedState.scroller.topRow:that.s.topRowFloat,baseScrollTop:that.s.baseScrollTop,baseRowTop:that.s.baseRowTop};initialStateSave=false});if(loadedState&&loadedState.scroller){this.s.topRowFloat=loadedState.scroller.topRow;this.s.baseScrollTop=loadedState.scroller.baseScrollTop;this.s.baseRowTop=loadedState.scroller.baseRowTop}dt.on("init.scroller",function(){that.fnMeasure(false);that._fnDrawCallback();dt.on("draw.scroller",function(){that._fnDrawCallback()})});dt.on("preDraw.dt.scroller",function(){that._fnScrollForce()});dt.on("destroy.scroller",function(){$(window).off("resize.dt-scroller");$(that.dom.scroller).off(".dt-scroller");$(that.s.dt.nTable).off(".scroller");$(that.s.dt.nTableWrapper).removeClass("DTS");$("div.DTS_Loading",that.dom.scroller.parentNode).remove();that.dom.table.style.position="";that.dom.table.style.top="";that.dom.table.style.left=""})},_fnScroll:function(){var that=this,heights=this.s.heights,iScrollTop=this.dom.scroller.scrollTop,iTopRow;if(this.s.skip){return}if(this.s.ingnoreScroll){return}if(this.s.dt.bFiltered||this.s.dt.bSorted){this.s.lastScrollTop=0;return}this._fnInfo();clearTimeout(this.s.stateTO);this.s.stateTO=setTimeout(function(){that.s.dtApi.state.save()},250);if(this.s.forceReposition||iScrollTopthis.s.redrawBottom){var preRows=Math.ceil((this.s.displayBuffer-1)/2*this.s.viewportRows);iTopRow=parseInt(this._domain("physicalToVirtual",iScrollTop)/heights.row,10)-preRows;this.s.topRowFloat=this._domain("physicalToVirtual",iScrollTop)/heights.row;this.s.forceReposition=false;if(iTopRow<=0){iTopRow=0}else if(iTopRow+this.s.dt._iDisplayLength>this.s.dt.fnRecordsDisplay()){iTopRow=this.s.dt.fnRecordsDisplay()-this.s.dt._iDisplayLength;if(iTopRow<0){iTopRow=0}}else if(iTopRow%2!==0){iTopRow++}if(iTopRow!=this.s.dt._iDisplayStart){this.s.tableTop=$(this.s.dt.nTable).offset().top;this.s.tableBottom=$(this.s.dt.nTable).height()+this.s.tableTop;var draw=function(){if(that.s.scrollDrawReq===null){that.s.scrollDrawReq=iScrollTop}that.s.dt._iDisplayStart=iTopRow;that.s.dt.oApi._fnDraw(that.s.dt)};if(this.s.dt.oFeatures.bServerSide){clearTimeout(this.s.drawTO);this.s.drawTO=setTimeout(draw,this.s.serverWait)}else{draw()}if(this.dom.loader&&!this.s.loaderVisible){this.dom.loader.css("display","block");this.s.loaderVisible=true}}}else{this.s.topRowFloat=this.fnPixelsToRow(iScrollTop,false,true)}this.s.lastScrollTop=iScrollTop;this.s.stateSaveThrottle()},_domain:function(dir,val){var heights=this.s.heights;var coeff;if(heights.virtual===heights.scroll){return val}var xMax=(heights.scroll-heights.viewport)/2;var yMax=(heights.virtual-heights.viewport)/2;coeff=yMax/(xMax*xMax);if(dir==="virtualToPhysical"){if(val=displayEnd){iScrollTop=heights.scroll-(displayEnd-this.s.topRowFloat)*heights.row}else{iScrollTop=this._domain("virtualToPhysical",this.s.topRowFloat*heights.row)}this.dom.scroller.scrollTop=iScrollTop;this.s.baseScrollTop=iScrollTop;this.s.baseRowTop=this.s.topRowFloat;var tableTop=iScrollTop-(this.s.topRowFloat-displayStart)*heights.row;if(displayStart===0){tableTop=0}else if(displayStart+displayLen>=displayEnd){tableTop=heights.scroll-iTableHeight}this.dom.table.style.top=tableTop+"px";this.s.tableTop=tableTop;this.s.tableBottom=iTableHeight+this.s.tableTop;var boundaryPx=(iScrollTop-this.s.tableTop)*this.s.boundaryScale;this.s.redrawTop=iScrollTop-boundaryPx;this.s.redrawBottom=iScrollTop+boundaryPx>heights.scroll-heights.viewport-heights.row?heights.scroll-heights.viewport-heights.row:iScrollTop+boundaryPx;this.s.skip=false;if(this.s.dt.oFeatures.bStateSave&&this.s.dt.oLoadedState!==null&&typeof this.s.dt.oLoadedState.iScroller!="undefined"){var ajaxSourced=(this.s.dt.sAjaxSource||that.s.dt.ajax)&&!this.s.dt.oFeatures.bServerSide?true:false;if(ajaxSourced&&this.s.dt.iDraw==2||!ajaxSourced&&this.s.dt.iDraw==1){setTimeout(function(){$(that.dom.scroller).scrollTop(that.s.dt.oLoadedState.iScroller);that.s.redrawTop=that.s.dt.oLoadedState.iScroller-heights.viewport/2;setTimeout(function(){that.s.ingnoreScroll=false},0)},0)}}else{that.s.ingnoreScroll=false}if(this.s.dt.oFeatures.bInfo){setTimeout(function(){that._fnInfo.call(that)},0)}if(this.dom.loader&&this.s.loaderVisible){this.dom.loader.css("display","none");this.s.loaderVisible=false}},_fnScrollForce:function(){var heights=this.s.heights;var max=1e6;heights.virtual=heights.row*this.s.dt.fnRecordsDisplay();heights.scroll=heights.virtual;if(heights.scroll>max){heights.scroll=max}this.dom.force.style.height=heights.scroll>this.s.heights.row?heights.scroll+"px":this.s.heights.row+"px"},_fnCalcRowHeight:function(){var dt=this.s.dt;var origTable=dt.nTable;var nTable=origTable.cloneNode(false);var tbody=$("").appendTo(nTable);var container=$(''+''+''+""+"");$("tbody tr:lt(4)",origTable).clone().appendTo(tbody);while($("tr",tbody).length<3){tbody.append(" ")}$("div."+dt.oClasses.sScrollBody,container).append(nTable);var insertEl=this.s.dt.nHolding||origTable.parentNode;if(!$(insertEl).is(":visible")){insertEl="body"}container.appendTo(insertEl);this.s.heights.row=$("tr",tbody).eq(1).outerHeight();container.remove()},_fnInfo:function(){if(!this.s.dt.oFeatures.bInfo){return}var dt=this.s.dt,language=dt.oLanguage,iScrollTop=this.dom.scroller.scrollTop,iStart=Math.floor(this.fnPixelsToRow(iScrollTop,false,this.s.ani)+1),iMax=dt.fnRecordsTotal(),iTotal=dt.fnRecordsDisplay(),iPossibleEnd=Math.ceil(this.fnPixelsToRow(iScrollTop+this.s.heights.viewport,false,this.s.ani)),iEnd=iTotal
© 2015 - 2025 Weber Informatics LLC | Privacy Policy