42 lines
14 KiB
JavaScript
42 lines
14 KiB
JavaScript
|
/*!
|
||
|
Copyright 2011-2020 SpryMedia Ltd.
|
||
|
|
||
|
This source file is free software, available under the following license:
|
||
|
MIT license - http://datatables.net/license/mit
|
||
|
|
||
|
This source file is distributed in the hope that it will be useful, but
|
||
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
|
or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
|
||
|
|
||
|
For details please refer to: http://www.datatables.net
|
||
|
Scroller 2.0.2
|
||
|
©2011-2020 SpryMedia Ltd - datatables.net/license
|
||
|
*/
|
||
|
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(c,e,g){c instanceof String&&(c=String(c));for(var k=c.length,l=0;l<k;l++){var h=c[l];if(e.call(g,h,l,c))return{i:l,v:h}}return{i:-1,v:void 0}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;
|
||
|
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(c,e,g){c!=Array.prototype&&c!=Object.prototype&&(c[e]=g.value)};$jscomp.getGlobal=function(c){c=["object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global,c];for(var e=0;e<c.length;++e){var g=c[e];if(g&&g.Math==Math)return g}throw Error("Cannot find global object");};$jscomp.global=$jscomp.getGlobal(this);
|
||
|
$jscomp.polyfill=function(c,e,g,k){if(e){g=$jscomp.global;c=c.split(".");for(k=0;k<c.length-1;k++){var l=c[k];l in g||(g[l]={});g=g[l]}c=c[c.length-1];k=g[c];e=e(k);e!=k&&null!=e&&$jscomp.defineProperty(g,c,{configurable:!0,writable:!0,value:e})}};$jscomp.polyfill("Array.prototype.find",function(c){return c?c:function(c,g){return $jscomp.findInternal(this,c,g).v}},"es6","es3");
|
||
|
(function(c){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return c(e,window,document)}):"object"===typeof exports?module.exports=function(e,g){e||(e=window);g&&g.fn.dataTable||(g=require("datatables.net")(e,g).$);return c(g,e,e.document)}:c(jQuery,window,document)})(function(c,e,g,k){var l=c.fn.dataTable,h=function(a,b){this instanceof h?(b===k&&(b={}),a=c.fn.dataTable.Api(a),this.s={dt:a.settings()[0],dtApi:a,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,labelFactor:1},topRowFloat:0,scrollDrawDiff:null,loaderVisible:!1,forceReposition:!1,baseRowTop:0,baseScrollTop:0,mousedown:!1,lastScrollTop:0},this.s=c.extend(this.s,h.oDefaults,b),this.s.heights.row=this.s.rowHeight,this.dom={force:g.createElement("div"),label:c('<div class="dts_label">0</div>'),scroller:null,table:null,loader:null},this.s.dt.oScroller||
|
||
|
(this.s.dt.oScroller=this,this.construct())):alert("Scroller warning: Scroller must be initialised with the 'new' keyword.")};c.extend(h.prototype,{measure:function(a){this.s.autoHeight&&this._calcRowHeight();var b=this.s.heights;b.row&&(b.viewport=this._parseHeight(c(this.dom.scroller).css("max-height")),this.s.viewportRows=parseInt(b.viewport/b.row,10)+1,this.s.dt._iDisplayLength=this.s.viewportRows*this.s.displayBuffer);var d=this.dom.label.outerHeight();b.labelFactor=(b.viewport-d)/b.scroll;(a===
|
||
|
k||a)&&this.s.dt.oInstance.fnDraw(!1)},pageInfo:function(){var a=this.dom.scroller.scrollTop,b=this.s.dt.fnRecordsDisplay(),d=Math.ceil(this.pixelsToRow(a+this.s.heights.viewport,!1,this.s.ani));return{start:Math.floor(this.pixelsToRow(a,!1,this.s.ani)),end:b<d?b-1:d-1}},pixelsToRow:function(a,b,d){a-=this.s.baseScrollTop;d=d?(this._domain("physicalToVirtual",this.s.baseScrollTop)+a)/this.s.heights.row:a/this.s.heights.row+this.s.baseRowTop;return b||b===k?parseInt(d,10):d},rowToPixels:function(a,
|
||
|
b,d){a-=this.s.baseRowTop;d=d?this._domain("virtualToPhysical",this.s.baseScrollTop):this.s.baseScrollTop;d+=a*this.s.heights.row;return b||b===k?parseInt(d,10):d},scrollToRow:function(a,b){var d=this,f=!1,e=this.rowToPixels(a),g=a-(this.s.displayBuffer-1)/2*this.s.viewportRows;0>g&&(g=0);(e>this.s.redrawBottom||e<this.s.redrawTop)&&this.s.dt._iDisplayStart!==g&&(f=!0,e=this._domain("virtualToPhysical",a*this.s.heights.row),this.s.redrawTop<e&&e<this.s.redrawBottom&&(this.s.forceReposition=!0,b=!1));
|
||
|
b===k||b?(this.s.ani=f,c(this.dom.scroller).animate({scrollTop:e},function(){setTimeout(function(){d.s.ani=!1},250)})):c(this.dom.scroller).scrollTop(e)},construct:function(){var a=this,b=this.s.dtApi;if(this.s.dt.oFeatures.bPaginate){this.dom.force.style.position="relative";this.dom.force.style.top="0px";this.dom.force.style.left="0px";this.dom.force.style.width="1px";this.dom.scroller=c("div."+this.s.dt.oClasses.sScrollBody,this.s.dt.nTableWrapper)[0];this.dom.scroller.appendChild(this.dom.force);
|
||
|
this.dom.scroller.style.position="relative";this.dom.table=c(">table",this.dom.scroller)[0];this.dom.table.style.position="absolute";this.dom.table.style.top="0px";this.dom.table.style.left="0px";c(b.table().container()).addClass("dts DTS");this.s.loadingIndicator&&(this.dom.loader=c('<div class="dataTables_processing dts_loading">'+this.s.dt.oLanguage.sLoadingRecords+"</div>").css("display","none"),c(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;c(this.dom.scroller).on("scroll.dt-scroller",function(b){a._scroll.call(a)});c(this.dom.scroller).on("touchstart.dt-scroller",function(){a._scroll.call(a)});c(this.dom.scroller).on("mousedown.dt-scroller",function(){a.s.mousedown=!0}).on("mouseup.dt-scroller",function(){a.s.labelVisible=!1;a.s.mousedown=!1;a.dom.label.css("display","none")});c(e).on("resize.dt-scroller",function(){a.measure(!1);a._info()});
|
||
|
var d=!0,f=b.state.loaded();b.on("stateSaveParams.scroller",function(b,c,e){d?(e.scroller=f.scroller,d=!1):e.scroller={topRow:a.s.topRowFloat,baseScrollTop:a.s.baseScrollTop,baseRowTop:a.s.baseRowTop,scrollTop:a.s.lastScrollTop}});f&&f.scroller&&(this.s.topRowFloat=f.scroller.topRow,this.s.baseScrollTop=f.scroller.baseScrollTop,this.s.baseRowTop=f.scroller.baseRowTop);this.measure(!1);a.s.stateSaveThrottle=a.s.dt.oApi._fnThrottle(function(){a.s.dtApi.state.save()},500);b.on("init.scroller",function(){a.measure(!1);
|
||
|
a.s.scrollType="jump";a._draw();b.on("draw.scroller",function(){a._draw()})});b.on("preDraw.dt.scroller",function(){a._scrollForce()});b.on("destroy.scroller",function(){c(e).off("resize.dt-scroller");c(a.dom.scroller).off(".dt-scroller");c(a.s.dt.nTable).off(".scroller");c(a.s.dt.nTableWrapper).removeClass("DTS");c("div.DTS_Loading",a.dom.scroller.parentNode).remove();a.dom.table.style.position="";a.dom.table.style.top="";a.dom.table.style.left=""})}else this.s.dt.oApi._fnLog(this.s.dt,0,"Pagination must be enabled for Scroller")},
|
||
|
_calcRowHeight:function(){var a=this.s.dt,b=a.nTable,d=b.cloneNode(!1),f=c("<tbody/>").appendTo(d),e=c('<div class="'+a.oClasses.sWrapper+' DTS"><div class="'+a.oClasses.sScrollWrapper+'"><div class="'+a.oClasses.sScrollBody+'"></div></div></div>');c("tbody tr:lt(4)",b).clone().appendTo(f);var g=c("tr",f).length;if(1===g)f.prepend("<tr><td> </td></tr>"),f.append("<tr><td> </td></tr>");else for(;3>g;g++)f.append("<tr><td> </td></tr>");c("div."+a.oClasses.sScrollBody,e).append(d);a=this.s.dt.nHolding||
|
||
|
b.parentNode;c(a).is(":visible")||(a="body");e.find("input").removeAttr("name");e.appendTo(a);this.s.heights.row=c("tr",f).eq(1).outerHeight();e.remove()},_draw:function(){var a=this,b=this.s.heights,d=this.dom.scroller.scrollTop,f=c(this.s.dt.nTable).height(),e=this.s.dt._iDisplayStart,g=this.s.dt._iDisplayLength,k=this.s.dt.fnRecordsDisplay();this.s.skip=!0;!this.s.dt.bSorted&&!this.s.dt.bFiltered||0!==e||this.s.dt._drawHold||(this.s.topRowFloat=0);d="jump"===this.s.scrollType?this._domain("virtualToPhysical",
|
||
|
this.s.topRowFloat*b.row):d;this.s.baseScrollTop=d;this.s.baseRowTop=this.s.topRowFloat;var h=d-(this.s.topRowFloat-e)*b.row;0===e?h=0:e+g>=k&&(h=b.scroll-f);this.dom.table.style.top=h+"px";this.s.tableTop=h;this.s.tableBottom=f+this.s.tableTop;f=(d-this.s.tableTop)*this.s.boundaryScale;this.s.redrawTop=d-f;this.s.redrawBottom=d+f>b.scroll-b.viewport-b.row?b.scroll-b.viewport-b.row:d+f;this.s.skip=!1;this.s.dt.oFeatures.bStateSave&&null!==this.s.dt.oLoadedState&&"undefined"!=typeof this.s.dt.oLoadedState.scroller?
|
||
|
((b=!this.s.dt.sAjaxSource&&!a.s.dt.ajax||this.s.dt.oFeatures.bServerSide?!1:!0)&&2==this.s.dt.iDraw||!b&&1==this.s.dt.iDraw)&&setTimeout(function(){c(a.dom.scroller).scrollTop(a.s.dt.oLoadedState.scroller.scrollTop);setTimeout(function(){a.s.ingnoreScroll=!1},0)},0):a.s.ingnoreScroll=!1;this.s.dt.oFeatures.bInfo&&setTimeout(function(){a._info.call(a)},0);this.dom.loader&&this.s.loaderVisible&&(this.dom.loader.css("display","none"),this.s.loaderVisible=!1)},_domain:function(a,b){var d=this.s.heights;
|
||
|
if(d.virtual===d.scroll||1E4>b)return b;if("virtualToPhysical"===a&&b>=d.virtual-1E4)return a=d.virtual-b,d.scroll-a;if("physicalToVirtual"===a&&b>=d.scroll-1E4)return a=d.scroll-b,d.virtual-a;d=(d.virtual-1E4-1E4)/(d.scroll-1E4-1E4);var c=1E4-1E4*d;return"virtualToPhysical"===a?(b-c)/d:d*b+c},_info:function(){if(this.s.dt.oFeatures.bInfo){var a=this.s.dt,b=a.oLanguage,d=this.dom.scroller.scrollTop,f=Math.floor(this.pixelsToRow(d,!1,this.s.ani)+1),e=a.fnRecordsTotal(),g=a.fnRecordsDisplay();d=Math.ceil(this.pixelsToRow(d+
|
||
|
this.s.heights.viewport,!1,this.s.ani));d=g<d?g:d;var h=a.fnFormatNumber(f),k=a.fnFormatNumber(d),l=a.fnFormatNumber(e),m=a.fnFormatNumber(g);h=0===a.fnRecordsDisplay()&&a.fnRecordsDisplay()==a.fnRecordsTotal()?b.sInfoEmpty+b.sInfoPostFix:0===a.fnRecordsDisplay()?b.sInfoEmpty+" "+b.sInfoFiltered.replace("_MAX_",l)+b.sInfoPostFix:a.fnRecordsDisplay()==a.fnRecordsTotal()?b.sInfo.replace("_START_",h).replace("_END_",k).replace("_MAX_",l).replace("_TOTAL_",m)+b.sInfoPostFix:b.sInfo.replace("_START_",
|
||
|
h).replace("_END_",k).replace("_MAX_",l).replace("_TOTAL_",m)+" "+b.sInfoFiltered.replace("_MAX_",a.fnFormatNumber(a.fnRecordsTotal()))+b.sInfoPostFix;(b=b.fnInfoCallback)&&(h=b.call(a.oInstance,a,f,d,e,g,h));f=a.aanFeatures.i;if("undefined"!=typeof f)for(e=0,g=f.length;e<g;e++)c(f[e]).html(h);c(a.nTable).triggerHandler("info.dt")}},_parseHeight:function(a){var b,d=/^([+-]?(?:\d+(?:\.\d+)?|\.\d+))(px|em|rem|vh)$/.exec(a);if(null===d)return 0;a=parseFloat(d[1]);d=d[2];"px"===d?b=a:"vh"===d?b=a/100*
|
||
|
c(e).height():"rem"===d?b=a*parseFloat(c(":root").css("font-size")):"em"===d&&(b=a*parseFloat(c("body").css("font-size")));return b?b:0},_scroll:function(){var a=this,b=this.s.heights,d=this.dom.scroller.scrollTop;if(!this.s.skip&&!this.s.ingnoreScroll&&d!==this.s.lastScrollTop)if(this.s.dt.bFiltered||this.s.dt.bSorted)this.s.lastScrollTop=0;else{this._info();clearTimeout(this.s.stateTO);this.s.stateTO=setTimeout(function(){a.s.dtApi.state.save()},250);this.s.scrollType=Math.abs(d-this.s.lastScrollTop)>
|
||
|
b.viewport?"jump":"cont";this.s.topRowFloat="cont"===this.s.scrollType?this.pixelsToRow(d,!1,!1):this._domain("physicalToVirtual",d)/b.row;0>this.s.topRowFloat&&(this.s.topRowFloat=0);if(this.s.forceReposition||d<this.s.redrawTop||d>this.s.redrawBottom){var f=Math.ceil((this.s.displayBuffer-1)/2*this.s.viewportRows);f=parseInt(this.s.topRowFloat,10)-f;this.s.forceReposition=!1;0>=f?f=0:f+this.s.dt._iDisplayLength>this.s.dt.fnRecordsDisplay()?(f=this.s.dt.fnRecordsDisplay()-this.s.dt._iDisplayLength,
|
||
|
0>f&&(f=0)):0!==f%2&&f++;this.s.targetTop=f;f!=this.s.dt._iDisplayStart&&(this.s.tableTop=c(this.s.dt.nTable).offset().top,this.s.tableBottom=c(this.s.dt.nTable).height()+this.s.tableTop,f=function(){a.s.dt._iDisplayStart=a.s.targetTop;a.s.dt.oApi._fnDraw(a.s.dt)},this.s.dt.oFeatures.bServerSide?(this.s.forceReposition=!0,clearTimeout(this.s.drawTO),this.s.drawTO=setTimeout(f,this.s.serverWait)):f(),this.dom.loader&&!this.s.loaderVisible&&(this.dom.loader.css("display","block"),this.s.loaderVisible=
|
||
|
!0))}else this.s.topRowFloat=this.pixelsToRow(d,!1,!0);this.s.lastScrollTop=d;this.s.stateSaveThrottle();"jump"===this.s.scrollType&&this.s.mousedown&&(this.s.labelVisible=!0);this.s.labelVisible&&this.dom.label.html(this.s.dt.fnFormatNumber(parseInt(this.s.topRowFloat,10)+1)).css("top",d+d*b.labelFactor).css("display","block")}},_scrollForce:function(){var a=this.s.heights;a.virtual=a.row*this.s.dt.fnRecordsDisplay();a.scroll=a.virtual;1E6<a.scroll&&(a.scroll=1E6);this.dom.force.style.height=a.scroll>
|
||
|
this.s.heights.row?a.scroll+"px":this.s.heights.row+"px"}});h.defaults={boundaryScale:.5,displayBuffer:9,loadingIndicator:!1,rowHeight:"auto",serverWait:200};h.oDefaults=h.defaults;h.version="2.0.2";c(g).on("preInit.dt.dtscroller",function(a,b){if("dt"===a.namespace){a=b.oInit.scroller;var d=l.defaults.scroller;if(a||d)d=c.extend({},a,d),!1!==a&&new h(b,d)}});c.fn.dataTable.Scroller=h;c.fn.DataTable.Scroller=h;var m=c.fn.dataTable.Api;m.register("scroller()",function(){return this});m.register("scroller().rowToPixels()",
|
||
|
function(a,b,d){var c=this.context;if(c.length&&c[0].oScroller)return c[0].oScroller.rowToPixels(a,b,d)});m.register("scroller().pixelsToRow()",function(a,b,d){var c=this.context;if(c.length&&c[0].oScroller)return c[0].oScroller.pixelsToRow(a,b,d)});m.register(["scroller().scrollToRow()","scroller.toPosition()"],function(a,b){this.iterator("table",function(d){d.oScroller&&d.oScroller.scrollToRow(a,b)});return this});m.register("row().scrollTo()",function(a){var b=this;this.iterator("row",function(d,
|
||
|
c){d.oScroller&&(c=b.rows({order:"applied",search:"applied"}).indexes().indexOf(c),d.oScroller.scrollToRow(c,a))});return this});m.register("scroller.measure()",function(a){this.iterator("table",function(b){b.oScroller&&b.oScroller.measure(a)});return this});m.register("scroller.page()",function(){var a=this.context;if(a.length&&a[0].oScroller)return a[0].oScroller.pageInfo()});return h});
|