- customers.min.js, fleet.min.js, inventory.min.js, pos-utils.min.js, sidebar.min.js, virtual-scroll.min.js
1 line
2.4 KiB
JavaScript
1 line
2.4 KiB
JavaScript
!function(t){"use strict";function e(t){this.container=t.container,this.rowHeight=t.rowHeight||48,this.buffer=t.buffer||5,this.renderRow=t.renderRow||function(){return""},this.emptyHtml=t.emptyHtml||"",this.data=[],this._scrollHandler=this._onScroll.bind(this),this._resizeHandler=this._onResize.bind(this),this._isTbody="TBODY"===this.container.tagName,this._init()}e.prototype._init=function(){var e=this.container;if(this._isTbody){var i=e.closest("table");if(i){var r=i.parentElement;r&&r.classList.contains("vs-container")&&r.addEventListener("scroll",this._scrollHandler,{passive:!0})}}else e.style.overflowY="auto",e.style.position="relative",e.style.maxHeight||e.style.height||(e.style.maxHeight="60vh");t.addEventListener("resize",this._resizeHandler,{passive:!0})},e.prototype.setData=function(t){this.data=t||[],this._render()},e.prototype.refresh=function(){this._render()},e.prototype._onScroll=function(){this._render()},e.prototype._onResize=function(){this._render()},e.prototype._getScrollTop=function(){if(this._isTbody){var t=this.container.closest("table");if(t){var e=t.parentElement;if(e&&e.classList.contains("vs-container"))return e.scrollTop}return 0}return this.container.scrollTop},e.prototype._getContainerHeight=function(){if(this._isTbody){var t=this.container.closest("table");if(t){var e=t.parentElement;if(e&&e.classList.contains("vs-container"))return e.clientHeight}return 600}return this.container.clientHeight},e.prototype._render=function(){var t=this.data,e=this.rowHeight,i=this.buffer;if(!t.length)return this._isTbody,void(this.container.innerHTML=this.emptyHtml);var r=this._getScrollTop(),n=this._getContainerHeight(),s=Math.max(0,Math.floor(r/e)-i),o=Math.min(t.length,Math.ceil((r+n)/e)+i),a="";if(this._isTbody){var l=s*e;l>0&&(a+='<tr style="height:'+l+'px;"><td colspan="99" style="padding:0;border:0;"></td></tr>');for(var h=s;h<o;h++)a+=this.renderRow(t[h],h);var c=(t.length-o)*e;c>0&&(a+='<tr style="height:'+c+'px;"><td colspan="99" style="padding:0;border:0;"></td></tr>')}else for(var d=s;d<o;d++)a+=this.renderRow(t[d],d);this.container.innerHTML=a},e.prototype.destroy=function(){if(this._isTbody){var e=this.container.closest("table");if(e){var i=e.parentElement;i&&i.classList.contains("vs-container")&&i.removeEventListener("scroll",this._scrollHandler)}}else this.container.removeEventListener("scroll",this._scrollHandler);t.removeEventListener("resize",this._resizeHandler)},t.VirtualScroll=e}(window); |