/*! Scroller 2.1.1
* © SpryMedia Ltd - datatables.net/license
*/
import $ from"jquery";import DataTable from"datatables.net";var Scroller=function(s,t){this instanceof Scroller?(void 0===t&&(t={}),s=$.fn.dataTable.Api(s),this.s={dt:s.settings()[0],dtApi:s,tableTop:0,tableBottom:0,redrawTop:0,redrawBottom:0,autoHeight:!0,viewportRows:0,stateTO:null,stateSaveThrottle:function(){},drawTO:null,heights:{jump:null,page:null,virtual:null,scroll:null,row:null,viewport:null,labelHeight:0,xbar:0},topRowFloat:0,scrollDrawDiff:null,loaderVisible:!1,forceReposition:!1,baseRowTop:0,baseScrollTop:0,mousedown:!1,lastScrollTop:0},this.s=$.extend(this.s,Scroller.oDefaults,t),this.s.heights.row=this.s.rowHeight,this.dom={force:document.createElement("div"),label:$('
0
'),scroller:null,table:null,loader:null},this.s.dt.oScroller||(this.s.dt.oScroller=this).construct()):alert("Scroller warning: Scroller must be initialised with the 'new' keyword.")},Api=($.extend(Scroller.prototype,{measure:function(s){this.s.autoHeight&&this._calcRowHeight();var t=this.s.heights,o=(t.row&&(t.viewport=this._parseHeight($(this.dom.scroller).css("max-height")),this.s.viewportRows=parseInt(t.viewport/t.row,10)+1,this.s.dt._iDisplayLength=this.s.viewportRows*this.s.displayBuffer),this.dom.label.outerHeight());t.xbar=this.dom.scroller.offsetHeight-this.dom.scroller.clientHeight,t.labelHeight=o,void 0!==s&&!s||this.s.dt.oInstance.fnDraw(!1)},pageInfo:function(){var s=this.s.dt,t=this.dom.scroller.scrollTop,s=s.fnRecordsDisplay(),o=Math.ceil(this.pixelsToRow(t+this.s.heights.viewport,!1,this.s.ani));return{start:Math.floor(this.pixelsToRow(t,!1,this.s.ani)),end:sthis.s.redrawBottom||ltable",this.dom.scroller)[0],this.dom.table.style.position="absolute",this.dom.table.style.top="0px",this.dom.table.style.left="0px",$(s.table().container()).addClass("dts DTS"),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)),this.dom.label.appendTo(this.dom.scroller),this.s.heights.row&&"auto"!=this.s.heights.row&&(this.s.autoHeight=!1),this.s.ingnoreScroll=!0,$(this.dom.scroller).on("scroll.dt-scroller",function(s){r._scroll.call(r)}),$(this.dom.scroller).on("touchstart.dt-scroller",function(){r._scroll.call(r)}),$(this.dom.scroller).on("mousedown.dt-scroller",function(){r.s.mousedown=!0}).on("mouseup.dt-scroller",function(){r.s.labelVisible=!1,r.s.mousedown=!1,r.dom.label.css("display","none")}),$(window).on("resize.dt-scroller",function(){r.measure(!1),r._info()}),e=!0,l=s.state.loaded(),s.on("stateSaveParams.scroller",function(s,t,o){e&&l?(o.scroller=l.scroller,e=!1,o.scroller&&(r.s.lastScrollTop=o.scroller.scrollTop)):o.scroller={topRow:r.s.topRowFloat,baseScrollTop:r.s.baseScrollTop,baseRowTop:r.s.baseRowTop,scrollTop:r.s.lastScrollTop}}),s.on("stateLoadParams.scroller",function(s,t,o){void 0!==o.scroller&&r.scrollToRow(o.scroller.topRow)}),l&&l.scroller&&(this.s.topRowFloat=l.scroller.topRow,this.s.baseScrollTop=l.scroller.baseScrollTop,this.s.baseRowTop=l.scroller.baseRowTop),this.measure(!1),r.s.stateSaveThrottle=r.s.dt.oApi._fnThrottle(function(){r.s.dtApi.state.save()},500),s.on("init.scroller",function(){r.measure(!1),r.s.scrollType="jump",r._draw(),s.on("draw.scroller",function(){r._draw()})}),s.on("preDraw.dt.scroller",function(){r._scrollForce()}),s.on("destroy.scroller",function(){$(window).off("resize.dt-scroller"),$(r.dom.scroller).off(".dt-scroller"),$(r.s.dt.nTable).off(".scroller"),$(r.s.dt.nTableWrapper).removeClass("DTS"),$("div.DTS_Loading",r.dom.scroller.parentNode).remove(),r.dom.table.style.position="",r.dom.table.style.top="",r.dom.table.style.left=""})):this.s.dt.oApi._fnLog(this.s.dt,0,"Pagination must be enabled for Scroller")},_calcRowHeight:function(){var s=this.s.dt,t=s.nTable,o=t.cloneNode(!1),e=$("").appendTo(o),l=$(''),r=($("tbody tr:lt(4)",t).clone().appendTo(e),$("tr",e).length);if(1===r)e.prepend(" |
"),e.append(" |
");else for(;r<3;r++)e.append(" |
");$("div."+s.oClasses.sScrollBody,l).append(o);s=this.s.dt.nHolding||t.parentNode;$(s).is(":visible")||(s="body"),l.find("input").removeAttr("name"),l.appendTo(s),this.s.heights.row=$("tr",e).eq(1).outerHeight(),l.remove()},_draw:function(){var s=this,t=this.s.heights,o=this.dom.scroller.scrollTop,e=$(this.s.dt.nTable).height(),l=this.s.dt._iDisplayStart,r=this.s.dt._iDisplayLength,i=this.s.dt.fnRecordsDisplay(),a=o+t.viewport,n=(this.s.skip=!0,!this.s.dt.bSorted&&!this.s.dt.bFiltered||0!==l||this.s.dt._drawHold||(this.s.topRowFloat=0),o="jump"===this.s.scrollType?this._domain("virtualToPhysical",this.s.topRowFloat*t.row):o,this.s.baseScrollTop=o,this.s.baseRowTop=this.s.topRowFloat,o-(this.s.topRowFloat-l)*t.row),l=(0===l?n=0:i<=l+r?n=t.scroll-e:n+et.scroll-t.viewport-t.row?t.scroll-t.viewport-t.row:o+l,this.s.skip=!1,s.s.ingnoreScroll&&(this.s.dt.oFeatures.bStateSave&&null!==this.s.dt.oLoadedState&&void 0!==this.s.dt.oLoadedState.scroller?((r=!(!this.s.dt.sAjaxSource&&!s.s.dt.ajax||this.s.dt.oFeatures.bServerSide))&&2<=this.s.dt.iDraw||!r&&1<=this.s.dt.iDraw)&&setTimeout(function(){$(s.dom.scroller).scrollTop(s.s.dt.oLoadedState.scroller.scrollTop),setTimeout(function(){s.s.ingnoreScroll=!1},0)},0):s.s.ingnoreScroll=!1),this.s.dt.oFeatures.bInfo&&setTimeout(function(){s._info.call(s)},0),$(this.s.dt.nTable).triggerHandler("position.dts.dt",n),this.dom.loader&&this.s.loaderVisible&&(this.dom.loader.css("display","none"),this.s.loaderVisible=!1)},_domain:function(s,t){var o,e=this.s.heights,l=1e4;return e.virtual===e.scroll||t=e.virtual-l?(o=e.virtual-t,e.scroll-o):"physicalToVirtual"===s&&t>=e.scroll-l?(o=e.scroll-t,e.virtual-o):(e=l-(o=(e.virtual-l-l)/(e.scroll-l-l))*l,"virtualToPhysical"===s?(t-e)/o:o*t+e)},_info:function(){if(this.s.dt.oFeatures.bInfo){var s=this.s.dt,t=s.oLanguage,o=this.dom.scroller.scrollTop,e=Math.floor(this.pixelsToRow(o,!1,this.s.ani)+1),l=s.fnRecordsTotal(),r=s.fnRecordsDisplay(),o=Math.ceil(this.pixelsToRow(o+this.s.heights.viewport,!1,this.s.ani)),o=ro.viewport?"jump":"cont",this.s.topRowFloat="cont"===this.s.scrollType?this.pixelsToRow(e,!1,!1):this._domain("physicalToVirtual",e)/o.row,this.s.topRowFloat<0&&(this.s.topRowFloat=0),this.s.forceReposition||ethis.s.redrawBottom?(s=Math.ceil((this.s.displayBuffer-1)/2*this.s.viewportRows),s=parseInt(this.s.topRowFloat,10)-s,this.s.forceReposition=!1,s<=0?s=0:s+this.s.dt._iDisplayLength>this.s.dt.fnRecordsDisplay()?(s=this.s.dt.fnRecordsDisplay()-this.s.dt._iDisplayLength)<0&&(s=0):s%2!=0&&s++,(this.s.targetTop=s)!=this.s.dt._iDisplayStart&&(this.s.tableTop=$(this.s.dt.nTable).offset().top,this.s.tableBottom=$(this.s.dt.nTable).height()+this.s.tableTop,s=function(){t.s.dt._iDisplayStart=t.s.targetTop,t.s.dt.oApi._fnDraw(t.s.dt)},this.s.dt.oFeatures.bServerSide?(this.s.forceReposition=!0,clearTimeout(this.s.drawTO),this.s.drawTO=setTimeout(s,this.s.serverWait)):s(),this.dom.loader)&&!this.s.loaderVisible&&(this.dom.loader.css("display","block"),this.s.loaderVisible=!0)):this.s.topRowFloat=this.pixelsToRow(e,!1,!0),this.s.lastScrollTop=e,this.s.stateSaveThrottle(),"jump"===this.s.scrollType&&this.s.mousedown&&(this.s.labelVisible=!0),this.s.labelVisible&&(s=(o.viewport-o.labelHeight-o.xbar)/o.scroll,this.dom.label.html(this.s.dt.fnFormatNumber(parseInt(this.s.topRowFloat,10)+1)).css("top",e+e*s).css("right",10-this.dom.scroller.scrollLeft).css("display","block"))))},_scrollForce:function(){var s=this.s.heights;s.virtual=s.row*this.s.dt.fnRecordsDisplay(),s.scroll=s.virtual,1e6this.s.heights.row?s.scroll+"px":this.s.heights.row+"px"}}),Scroller.defaults={boundaryScale:.5,displayBuffer:9,loadingIndicator:!1,rowHeight:"auto",serverWait:200},Scroller.oDefaults=Scroller.defaults,Scroller.version="2.1.1",$(document).on("preInit.dt.dtscroller",function(s,t){var o,e;"dt"===s.namespace&&(s=t.oInit.scroller,o=DataTable.defaults.scroller,s||o)&&(e=$.extend({},s,o),!1!==s)&&new Scroller(t,e)}),$.fn.dataTable.Scroller=Scroller,$.fn.DataTable.Scroller=Scroller,$.fn.dataTable.Api);Api.register("scroller()",function(){return this}),Api.register("scroller().rowToPixels()",function(s,t,o){var e=this.context;if(e.length&&e[0].oScroller)return e[0].oScroller.rowToPixels(s,t,o)}),Api.register("scroller().pixelsToRow()",function(s,t,o){var e=this.context;if(e.length&&e[0].oScroller)return e[0].oScroller.pixelsToRow(s,t,o)}),Api.register(["scroller().scrollToRow()","scroller.toPosition()"],function(t,o){return this.iterator("table",function(s){s.oScroller&&s.oScroller.scrollToRow(t,o)}),this}),Api.register("row().scrollTo()",function(o){var e=this;return this.iterator("row",function(s,t){s.oScroller&&(t=e.rows({order:"applied",search:"applied"}).indexes().indexOf(t),s.oScroller.scrollToRow(t,o))}),this}),Api.register("scroller.measure()",function(t){return this.iterator("table",function(s){s.oScroller&&s.oScroller.measure(t)}),this}),Api.register("scroller.page()",function(){var s=this.context;if(s.length&&s[0].oScroller)return s[0].oScroller.pageInfo()});export default DataTable;