1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-17 22:06:41 +02:00
TableFilter/dist/tablefilter/tablefilter.js

10 lines
107 KiB
JavaScript
Raw Normal View History

2015-11-21 08:31:32 +01:00
/**
* tablefilter v0.0.12 by Max Guglielmi
* build date: 2015-11-21T11:09:08.746Z
2015-11-21 08:31:32 +01:00
* MIT License
*/
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var s=e();for(var i in s)("object"==typeof exports?exports:t)[i]=s[i]}}(this,function(){return function(t){function e(s){if(i[s])return i[s].exports;var a=i[s]={exports:{},id:s,loaded:!1};return t[s].call(a.exports,a,a.exports,e),a.loaded=!0,a.exports}var s=window.webpackJsonp;window.webpackJsonp=function(i,l){for(var n,r,o=0,h=[];o<i.length;o++)r=i[o],a[r]&&h.push.apply(h,a[r]),a[r]=0;for(n in l)t[n]=l[n];for(s&&s(i,l);h.length;)h.shift().call(null,e)};var i={},a={0:0};return e.e=function(t,s){if(0===a[t])return s.call(null,e);if(void 0!==a[t])a[t].push(s);else{a[t]=[s];var i=document.getElementsByTagName("head")[0],l=document.createElement("script");l.type="text/javascript",l.charset="utf-8",l.async=!0,l.src=e.p+"tf-"+({}[t]||t)+".js",i.appendChild(l)}},e.m=t,e.c=i,e.p="",e(0)}([function(t,e,s){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var l=function(){function t(t,e){for(var s=0;s<e.length;s++){var i=e[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,s,i){return s&&t(e.prototype,s),i&&t(e,i),e}}(),n=s(1),r=i(n),o=s(2),h=i(o),d=s(3),u=i(d),c=s(4),f=i(c),p=s(5),g=i(p),v=s(6),b=i(v),m=s(7),_=i(m),y=s(8),C=i(y),w=s(9),x=s(10),T=s(12),k=s(13),P=s(14),F=s(15),R=s(17),O=s(18),I=s(19),S=s(20),E=s(21),L=s(22),N=s(23),D=window,M=_["default"].isValid,B=_["default"].format,A=D.document,H=function(){function t(){var e=this;a(this,t);for(var s=arguments.length,i=Array(s),l=0;s>l;l++)i[l]=arguments[l];if(0!==i.length){if(this.id=null,this.version="0.0.12",this.year=(new Date).getFullYear(),this.tbl=null,this.startRow=null,this.refRow=null,this.headersRow=null,this.cfg={},this.nbFilterableRows=null,this.nbRows=null,this.nbCells=null,this._hasGrid=!1,i.forEach(function(t){var s=typeof t;"object"===s&&t&&"TABLE"===t.nodeName?(e.tbl=t,e.id=t.id||"tf_"+(new Date).getTime()+"_"):"string"===s?(e.id=t,e.tbl=h["default"].id(t)):"number"===s?e.startRow=t:"object"===s&&(e.cfg=t)}),!this.tbl||"TABLE"!=this.tbl.nodeName||0===this.getRowsNb())throw new Error("Could not instantiate TableFilter: HTML table not found.");var n=this.cfg;this.refRow=null===this.startRow?2:this.startRow+1;try{this.nbCells=this.getCellsNb(this.refRow)}catch(o){this.nbCells=this.getCellsNb(0)}this.basePath=n.base_path||"tablefilter/",this.fltTypeInp="input",this.fltTypeSlc="select",this.fltTypeMulti="multiple",this.fltTypeCheckList="checklist",this.fltTypeNone="none",this.fltGrid=n.grid===!1?!1:!0,this.gridLayout=Boolean(n.grid_layout),this.filtersRowIndex=isNaN(n.filters_row_index)?0:n.filters_row_index,this.headersRow=isNaN(n.headers_row_index)?0===this.filtersRowIndex?1:0:n.headers_row_index,this.gridLayout&&(this.headersRow>1?this.filtersRowIndex=this.headersRow+1:(this.filtersRowIndex=1,this.headersRow=0)),this.fltCellTag="th"!==n.filters_cell_tag||"td"!==n.filters_cell_tag?"td":n.filters_cell_tag,this.fltIds=[],this.fltElms=[],this.searchArgs=null,this.validRowsIndex=null,this.fltGridEl=null,this.isFirstLoad=!0,this.infDiv=null,this.lDiv=null,this.rDiv=null,this.mDiv=null,this.infDivCssClass=n.inf_div_css_class||"inf",this.lDivCssClass=n.left_div_css_class||"ldiv",this.rDivCssClass=n.right_div_css_class||"rdiv",this.mDivCssClass=n.middle_div_css_class||"mdiv",this.contDivCssClass=n.content_div_css_class||"cont",this.stylePath=n.style_path||this.basePath+"style/",this.stylesheet=n.stylesheet||this.stylePath+"tablefilter.css",this.stylesheetId=this.id+"_style",this.fltsRowCssClass=n.flts_row_css_class||"fltrow",this.enableIcons=n.enable_icons===!1?!1:!0,this.alternateRows=Boolean(n.alternate_rows),this.hasColWidths=g["default"].isArray(n.col_widths),this.colWidths=this.hasColWidths?n.col_widths:null,this.fltCssClass=n.flt_css_class||"flt",this.fltMultiCssClass=n.flt_multi_c
2015-11-21 08:31:32 +01:00
e=e.substr(0,e.length-3)):e="");return e}}},{key:"getFiltersValue",value:function(){if(this.fltGrid){for(var t=[],e=0,s=this.fltIds.length;s>e;e++)t.push(u["default"].trim(u["default"].matchCase(this.getFilterValue(e),this.caseSensitive)));return t}}},{key:"getFilterId",value:function(t){return this.fltGrid?this.fltIds[t]:void 0}},{key:"getFiltersByType",value:function(t,e){if(this.fltGrid){for(var s=[],i=0,a=this.fltIds.length;a>i;i++){var l=this.getFilterType(i);if(l===u["default"].lower(t)){var n=e?i:this.fltIds[i];s.push(n)}}return s}}},{key:"getFilterElement",value:function(t){var e=this.fltIds[t];return h["default"].id(e)}},{key:"getCellsNb",value:function(){var t=arguments.length<=0||void 0===arguments[0]?0:arguments[0],e=this.tbl.rows[t];return e.cells.length}},{key:"getRowsNb",value:function(t){var e=g["default"].isUndef(this.refRow)?0:this.refRow,s=this.tbl.rows.length;return t&&(e=0),parseInt(s-e,10)}},{key:"getCellData",value:function(t){var e=t.cellIndex;return this.customCellData&&-1!=this.customCellDataCols.indexOf(e)?this.customCellData.call(null,this,t,e):h["default"].getText(t)}},{key:"getTableData",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[0],e=this.tbl.rows,s=[];t&&s.push([this.getHeadersRowIndex(),this.getHeadersText()]);for(var i=this.refRow;i<this.nbRows;i++){for(var a=[i,[]],l=e[i].cells,n=0,r=l.length;r>n;n++){var o=this.getCellData(l[n]);a[1].push(o)}s.push(a)}return s}},{key:"getFilteredData",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];if(!this.validRowsIndex)return[];var e=this.tbl.rows,s=[];t&&s.push([this.getHeadersRowIndex(),this.getHeadersText()]);for(var i=this.getValidRows(!0),a=0;a<i.length;a++){for(var l=[this.validRowsIndex[a],[]],n=e[this.validRowsIndex[a]].cells,r=0;r<n.length;r++){var o=this.getCellData(n[r]);l[1].push(o)}s.push(l)}return s}},{key:"getFilteredDataCol",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];if(g["default"].isUndef(t))return[];var s=this.getFilteredData(),i=[];e&&i.push(this.getHeadersText()[t]);for(var a=0,l=s.length;l>a;a++){var n=s[a],r=n[1],o=r[t];i.push(o)}return i}},{key:"getRowDisplay",value:function(t){return g["default"].isObj(t)?t.style.display:null}},{key:"validateRow",value:function(t,e){var s=this.tbl.rows[t];if(s&&"boolean"==typeof e){this.hasVisibleRows&&-1!==this.visibleRows.indexOf(t)&&(e=!0);var i=e?"":"none",a=e?"true":"false";s.style.display=i,this.paging&&s.setAttribute("validRow",a)}}},{key:"validateAllRows",value:function(){if(this._hasGrid){this.validRowsIndex=[];for(var t=this.refRow;t<this.nbFilterableRows;t++)this.validateRow(t,!0),this.validRowsIndex.push(t)}}},{key:"setFilterValue",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?"":arguments[1];if((this.fltGrid||this.isFirstLoad)&&this.getFilterElement(t)){var s=this.getFilterElement(t),i=this.getFilterType(t);if(i!==this.fltTypeMulti&&i!=this.fltTypeCheckList)s.value=e;else if(i===this.fltTypeMulti)for(var a=e.split(" "+this.orOperator+" "),l=0,n=s.options.length;n>l;l++){var r=s.options[l];(""===a||""===a[0])&&(r.selected=!1),""===r.value&&(r.selected=!1),""!==r.value&&b["default"].has(a,r.value,!0)&&(r.selected=!0)}else if(i===this.fltTypeCheckList){e=u["default"].matchCase(e,this.caseSensitive);var o=e.split(" "+this.orOperator+" "),d=h["default"].tag(s,"li").length;s.setAttribute("value",""),s.setAttribute("indexes","");for(var c=0;d>c;c++){var f=h["default"].tag(s,"li")[c],p=h["default"].tag(f,"label")[0],g=h["default"].tag(f,"input")[0],v=u["default"].matchCase(h["default"].getText(p),this.caseSensitive);""!==v&&b["default"].has(o,v,!0)?(g.checked=!0,this.Mod.checkList.setCheckListValues(g)):(g.checked=!1,this.Mod.checkList.setCheckListValues(g))}}}}},{key:"setColWidths",value:function(t,e){function s(){for(var t=this.nbCells,s=this.colWidths,i=h["default"].tag(e,"col"),a=i.length>0,l=a?null:A.createDocumentFragment(),n=0;t>n;n++){var r=void 0;a?r=i[n]:(r=h["default"].create("col",["id",this.id+"_col_"+n]),l.appendChild(r)),r.style.width=s[n]}a|
this.onAfterPopUpClose=d["default"].isFn(e.on_after_popup_filter_close)?e.on_after_popup_filter_close:null,this.popUpFltSpans=[],this.popUpFltImgs=[],this.popUpFltElms=this.popUpFltElmCache||[],this.popUpFltAdjustToContainer=!0,this.prfxPopUpSpan="popUpSpan_",this.prfxPopUpDiv="popUpDiv_"}return l(s,e),n(s,[{key:"onClick",value:function(e){var s=e||t.event,i=s.target.parentNode,a=parseInt(i.getAttribute("ci"),10);if(this.closeAll(a),this.toggle(a),this.popUpFltAdjustToContainer){var l=this.popUpFltElms[a],n=this.tf.getHeaderElement(a),r=.95*n.clientWidth;l.style.width=parseInt(r,10)+"px"}p["default"].cancel(s),p["default"].stop(s)}},{key:"init",value:function(){var t=this;if(!this.initialized){for(var e=this.tf,s=0;s<e.nbCells;s++)if(e.getFilterType(s)!==e.fltTypeNone){var i=c["default"].create("span",["id",this.prfxPopUpSpan+e.id+"_"+s],["ci",s]);i.innerHTML=this.popUpImgFltHtml;var a=e.getHeaderElement(s);a.appendChild(i),p["default"].add(i,"click",function(e){t.onClick(e)}),this.popUpFltSpans[s]=i,this.popUpFltImgs[s]=i.firstChild}this.initialized=!0}}},{key:"reset",value:function(){this.enable(),this.init(),this.buildAll()}},{key:"buildAll",value:function(){for(var t=0;t<this.popUpFltElmCache.length;t++)this.build(t,this.popUpFltElmCache[t])}},{key:"build",value:function(t,e){var s=this.tf,i=e?e:c["default"].create("div",["id",this.prfxPopUpDiv+s.id+"_"+t]);i.className=this.popUpDivCssClass,s.externalFltTgtIds.push(i.id);var a=s.getHeaderElement(t);a.insertBefore(i,a.firstChild),p["default"].add(i,"click",function(t){p["default"].stop(t)}),this.popUpFltElms[t]=i}},{key:"toggle",value:function(t){var e=this.tf,s=this.popUpFltElms[t];if("none"===s.style.display||""===s.style.display){if(this.onBeforePopUpOpen&&this.onBeforePopUpOpen.call(null,this,this.popUpFltElms[t],t),s.style.display="block",e.getFilterType(t)===e.fltTypeInp){var i=e.getFilterElement(t);i&&i.focus()}this.onAfterPopUpOpen&&this.onAfterPopUpOpen.call(null,this,this.popUpFltElms[t],t)}else this.onBeforePopUpClose&&this.onBeforePopUpClose.call(null,this,this.popUpFltElms[t],t),s.style.display="none",this.onAfterPopUpClose&&this.onAfterPopUpClose.call(null,this,this.popUpFltElms[t],t)}},{key:"closeAll",value:function(t){for(var e=0;e<this.popUpFltElms.length;e++)if(e!==t){var s=this.popUpFltElms[e];s&&(s.style.display="none")}}},{key:"buildIcons",value:function(){for(var t=0;t<this.popUpFltImgs.length;t++)this.buildIcon(t,!1)}},{key:"buildIcon",value:function(t,e){this.popUpFltImgs[t]&&(this.popUpFltImgs[t].src=e?this.popUpImgFltActive:this.popUpImgFlt)}},{key:"destroy",value:function(){if(this.initialized){this.popUpFltElmCache=[];for(var t=0;t<this.popUpFltElms.length;t++){var e=this.popUpFltElms[t],s=this.popUpFltSpans[t],i=this.popUpFltImgs[t];e&&(e.parentNode.removeChild(e),this.popUpFltElmCache[t]=e),e=null,s&&s.parentNode.removeChild(s),s=null,i&&i.parentNode.removeChild(i),i=null}this.popUpFltElms=[],this.popUpFltSpans=[],this.popUpFltImgs=[],this.disable(),this.initialized=!1}}}]),s}(o.Feature);e.PopupFilter=g}).call(e,function(){return this}())},function(t,e,s){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var l=function(){function t(t,e){for(var s=0;s<e.length;s++){var i=e[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,s,i){return s&&t(e.prototype,s),i&&t(e,i),e}}(),n=s(2),r=i(n),o=s(6),h=i(o),d=s(3),u=i(d),c=s(16),f=i(c),p=function(){function t(e){a(this,t);var s=e.config();this.enableSlcResetFilter=s.enable_slc_reset_filter===!1?!1:!0,this.nonEmptyText=s.non_empty_text||"(Non empty)",this.slcFillingMethod=s.slc_filling_method||"createElement",this.activateSlcTooltip=s.activate_slc_tooltip||"Click to activate",this.multipleSlcTooltip=s.multiple_slc_tooltip||"Use Ctrl key for multiple selections",this.isCustom=null,this.opts=null,this.optsTxt=null,this.slcInnerHtml=null,this.tf=e}return l(t,[{key:"b
};var i=d["default"].create(e.fltTypeSlc,["id",this.prfxSlcResults+e.id]);i.className=this.resultsSlcCssClass;var a=this.resultsPerPage[0],l=this.resultsPerPage[1],n=d["default"].create("span",["id",this.prfxSlcResultsTxt+e.id]);n.className=this.resultsSpanCssClass,this.resultsPerPageTgtId||e.setToolbar();var r=this.resultsPerPageTgtId?d["default"].id(this.resultsPerPageTgtId):e.rDiv;n.appendChild(d["default"].text(a));var o=e.feature("help");o&&o.btn?(o.btn.parentNode.insertBefore(n,o.btn),o.btn.parentNode.insertBefore(i,o.btn)):(r.appendChild(n),r.appendChild(i));for(var h=0;h<l.length;h++){var u=new Option(l[h],l[h],!1,!1);i.options[h]=u}v["default"].add(i,"change",s.slcResultsChange),this.resultsPerPageSlc=i}}},{key:"removeResultsPerPage",value:function(){var t=this.tf;if(t.hasGrid()&&this.resultsPerPageSlc&&this.resultsPerPage){var e=this.resultsPerPageSlc,s=d["default"].id(this.prfxSlcResultsTxt+t.id);e&&e.parentNode.removeChild(e),s&&s.parentNode.removeChild(s),this.resultsPerPageSlc=null}}},{key:"changePage",value:function(t){var e=this.tf,s=e.Evt;e.EvtManager(s.name.changepage,{pgIndex:t})}},{key:"changeResultsPerPage",value:function(){var t=this.tf,e=t.Evt;t.EvtManager(e.name.changeresultsperpage)}},{key:"resetPage",value:function(){var t=this.tf,e=t.Evt;t.EvtManager(e.name.resetpage)}},{key:"resetPageLength",value:function(){var t=this.tf,e=t.Evt;t.EvtManager(e.name.resetpagelength)}},{key:"_changePage",value:function(t){var e=this.tf;this.isEnabled()&&(null===t&&(t=this.pageSelectorType===e.fltTypeSlc?this.pagingSlc.options.selectedIndex:this.pagingSlc.value-1),t>=0&&t<=this.nbPages-1&&(this.onBeforeChangePage&&this.onBeforeChangePage.call(null,this,t),this.currentPageNb=parseInt(t,10)+1,this.pageSelectorType===e.fltTypeSlc?this.pagingSlc.options[t].selected=!0:this.pagingSlc.value=this.currentPageNb,e.rememberPageNb&&e.feature("store").savePageNb(e.pgNbCookie),this.startPagingRow=this.pageSelectorType===e.fltTypeSlc?this.pagingSlc.value:t*this.pagingLength,this.groupByPage(),this.onAfterChangePage&&this.onAfterChangePage.call(null,this,t)))}},{key:"_changeResultsPerPage",value:function(){var t=this.tf;if(this.isEnabled()){var e=this.resultsPerPageSlc,s=this.pageSelectorType===t.fltTypeSlc?this.pagingSlc.selectedIndex:parseInt(this.pagingSlc.value-1,10);if(this.pagingLength=parseInt(e.options[e.selectedIndex].value,10),this.startPagingRow=this.pagingLength*s,!isNaN(this.pagingLength)){if(this.startPagingRow>=t.nbFilterableRows&&(this.startPagingRow=t.nbFilterableRows-this.pagingLength),this.setPagingInfo(),this.pageSelectorType===t.fltTypeSlc){var i=this.pagingSlc.options.length-1<=s?this.pagingSlc.options.length-1:s;this.pagingSlc.options[i].selected=!0}t.rememberPageLen&&t.feature("store").savePageLength(t.pgLenCookie)}}}},{key:"_resetPage",value:function(t){var e=this.tf,s=e.feature("store").getPageNb(t);""!==s&&this.changePage(s-1)}},{key:"_resetPageLength",value:function(t){var e=this.tf;if(this.isEnabled()){var s=e.feature("store").getPageLength(t);""!==s&&(this.resultsPerPageSlc.options[s].selected=!0,this.changeResultsPerPage())}}},{key:"destroy",value:function(){var t=this.tf;if(this.initialized){var e=d["default"].id(this.prfxBtnNextSpan+t.id),s=d["default"].id(this.prfxBtnPrevSpan+t.id),i=d["default"].id(this.prfxBtnLastSpan+t.id),a=d["default"].id(this.prfxBtnFirstSpan+t.id),l=d["default"].id(this.prfxPgBeforeSpan+t.id),n=d["default"].id(this.prfxPgAfterSpan+t.id),r=d["default"].id(this.prfxPgSpan+t.id),o=this.evt;this.pagingSlc&&(this.pageSelectorType===t.fltTypeSlc?v["default"].remove(this.pagingSlc,"change",o.slcPagesChange):this.pageSelectorType===t.fltTypeInp&&v["default"].remove(this.pagingSlc,"keypress",o._detectKey),this.pagingSlc.parentNode.removeChild(this.pagingSlc)),e&&(v["default"].remove(e,"click",o.next),e.parentNode.removeChild(e)),s&&(v["default"].remove(s,"click",o.prev),s.parentNode.removeChild(s)),i&&(v["default"].remove(i,"click",o.last),i.parentNode.removeChild(i)),a&&(v["default"].remove(a,"click",o.first),a.parentNode.removeChild(a)),l&&l.parentNode.removeChild(l),n&&n.par