fixtable
Version:
A grid library to present tabular data
1 lines • 6.53 kB
JavaScript
!function(a,b){"object"==typeof exports&&"object"==typeof module?module.exports=b():"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?exports.Fixtable=b():a.Fixtable=b()}(this,function(){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={i:d,l:!1,exports:{}};return a[d].call(e.exports,e,e.exports,b),e.l=!0,e.exports}var c={};return b.m=a,b.c=c,b.i=function(a){return a},b.d=function(a,c,d){b.o(a,c)||Object.defineProperty(a,c,{configurable:!1,enumerable:!0,get:d})},b.n=function(a){var c=a&&a.__esModule?function(){return a["default"]}:function(){return a};return b.d(c,"a",c),c},b.o=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},b.p="",b(b.s=2)}([function(a){(function(){var b;b=function(){function a(a){this.element=a}return a._movableStyles=function(){return Array.prototype.concat.apply([],["margin","padding","border"].map(function(a){return["Top","Right","Bottom","Left"].map(function(b){return a+b})}))}(),a.moveStyles=function(a,b){return null!=b&&b.setStyles(a.getStyles(this._movableStyles)),a.setStyles(this._movableStyles.map(function(a){return[a,"0"]}))},a.prototype.addClass=function(a){var b;return null!=(b=this.element)?b.classList.add(a):void 0},a.prototype.getChild=function(b){var c;return new a(null!=(c=this.element)?c.querySelector(b):void 0)},a.prototype.getChildren=function(b){var c,d;return c=Array.prototype.slice.call((null!=(d=this.element)?d.querySelectorAll(b):void 0)||[]),c.map(function(b){return new a(b)})},a.prototype.getHeight=function(){var a;return(null!=(a=this.element)?a.offsetHeight:void 0)||0},a.prototype.getScrollWidth=function(){var a;return(null!=(a=this.element)?a.scrollWidth:void 0)||0},a.prototype.getStyles=function(a){var b;return this.element&&(b=getComputedStyle(this.element)),a.map(function(a){return[a,null!=b?b[a]:void 0]})},a.prototype.getWidth=function(){var a;return(null!=(a=this.element)?a.offsetWidth:void 0)||0},a.prototype.scrollTop=function(){var a;return null!=(a=this.element)?a.scrollTop=0:void 0},a.prototype.setHeight=function(a){return this.setStyle("height",a)},a.prototype.setStyle=function(a,b){var c;return"number"==typeof b&&(b=parseInt(b)+"px"),null!=(c=this.element)?c.style[a]=b:void 0},a.prototype.setStyles=function(a){var b,c,d,e,f,g;for(f=[],b=0,c=a.length;c>b;b++)e=a[b],d=e[0],g=e[1],f.push(this.setStyle(d,g));return f},a.prototype.setWidth=function(a){return this.setStyle("width",a)},a}(),a.exports=b}).call(this)},function(a){(function(){var b;b=function(){function a(a,b){null==a&&(a=!1),null==b&&(b=[]),this.debugMode=a,this.prefix=b instanceof Array?b:[b]}return a.prototype.log=function(){return this.debugMode?console.log.apply(console,Array.prototype.concat.apply(this.prefix,arguments)):void 0},a}(),a.exports=b}).call(this)},function(a,b,c){(function(){var b,d,e;b=c(0),e=c(1),d=function(){function a(a,c){if(null==c&&(c=!1),!(a instanceof HTMLElement))throw new Error("Fixtable requires root HTML element of component");this.element=new b(a),this.logger=new e(c,["[fixtable]",this.element]),this.logger.log("initializing"),this._addResizeListener(),this._registerElements(),this._moveStyles()}return a._postRenderFunction=function(a,b){var c;return c=0,function(){var d;return this.logger.log(a,arguments,"attempt",++c),d=Array.prototype.slice.call(arguments),this._isRendered()?(b.apply(this,d),c=0):10>c?(this.logger.log("not yet rendered, deferring "+a),setTimeout(function(b){return function(){return b[a].apply(b,d)}}(this),1)):c=0}},a.prototype._addResizeListener=function(){var a;return a=null,addEventListener("resize",function(b){return function(){return clearTimeout(a),a=setTimeout(b.setDimensions.bind(b),100)}}(this))},a.prototype._isRendered=function(){return this.element.getChild("th > div").getHeight()},a.prototype._moveStyles=function(){return a._postRenderFunction("_moveStyles",function(){return this.stylesCirculated?void 0:(b.moveStyles(this.tableElement,this.element),this.columnHeaders.getChildren("th").forEach(function(a){return b.moveStyles(a,a.getChild("div"))}),this.columnFilters.getChildren("th").forEach(function(a){return b.moveStyles(a)}),this.element.addClass("fixtable-styles-circulated"),this.stylesCirculated=!0)})}(),a.prototype._registerElements=function(){return a._postRenderFunction("_registerElements",function(){return this.tableElement=this.element.getChild("table"),this.headerElement=this.element.getChild(".fixtable-header"),this.filtersElement=this.element.getChild(".fixtable-filters"),this.columnHeaders=this.element.getChild("tr.fixtable-column-headers"),this.columnFilters=this.element.getChild("tr.fixtable-column-filters"),this.footerElement=this.element.getChild(".fixtable-footer")})}(),a.prototype.scrollTop=function(){return this.element.getChild(".fixtable-inner").scrollTop()},a.prototype.setColumnWidth=function(){return a._postRenderFunction("setColumnWidth",function(a,b){return this.columnHeaders.getChild("th:nth-of-type("+a+")").setWidth(b),this.tableElement.setStyle("tableLayout","fixed")})}(),a.prototype.setDimensions=function(){return a._postRenderFunction("setDimensions",function(){var a,b,c,d,e,f;return this.stylesCirculated||(this._registerElements(),this._moveStyles()),b=this.columnHeaders.getChildren("th"),a=this.columnFilters.getChildren("th"),b.forEach(function(a){return a.getChild("div").setHeight("auto")}),b.forEach(function(a){return a.getChild("div").setWidth(a.getWidth())}),f=Math.max.apply(null,b.map(function(a){return a.getChild("div").getHeight()})),b.forEach(function(a){return a.getChild("div").setHeight(f)}),this.headerElement.setHeight(f),b.forEach(function(a){return function(b){var c;return c=b.getChild("div"),c.getScrollWidth()>c.getWidth()?(b.setWidth(c.getScrollWidth()+25),b.addClass("header-temp-width"),a.tableElement.setStyle("tableLayout","auto")):void 0}}(this)),a.forEach(function(a){return a.getChild("div").setWidth(a.getWidth())}),e=Math.max.apply(null,a.map(function(a){return a.getChild("div").getHeight()})),a.forEach(function(a){return a.getChild("div").setHeight(e),a.getChild("div").setStyle("top",f)}),this.filtersElement.setStyle("paddingTop",e),this.filtersElement.setStyle("top",f),d=this.headerElement.getHeight()+this.filtersElement.getHeight(),c=this.footerElement.getHeight(),this.element.setStyle("paddingTop",d),this.element.setStyle("paddingBottom",c),this.columnHeaders.setStyle("display","none"),this.columnHeaders.getHeight(),this.columnHeaders.setStyle("display","table-row")})}(),a}(),a.exports=d}).call(this)}])});