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

10 lines
113 KiB
JavaScript
Raw Normal View History

2016-06-13 11:17:13 +02:00
/**
* tablefilter v0.2.37 by Max Guglielmi
* build date: 2016-06-13T09:12:36.277Z
* 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 i=e();for(var s in i)("object"==typeof exports?exports:t)[s]=i[s]}}(this,function(){return function(t){function e(i){if(s[i])return s[i].exports;var n=s[i]={exports:{},id:i,loaded:!1};return t[i].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var i=window.webpackJsonp;window.webpackJsonp=function(s,r){for(var o,a,l=0,h=[];l<s.length;l++)a=s[l],n[a]&&h.push.apply(h,n[a]),n[a]=0;for(o in r)t[o]=r[o];for(i&&i(s,r);h.length;)h.shift().call(null,e)};var s={},n={0:0};return e.e=function(t,i){if(0===n[t])return i.call(null,e);if(void 0!==n[t])n[t].push(i);else{n[t]=[i];var s=document.getElementsByTagName("head")[0],r=document.createElement("script");r.type="text/javascript",r.charset="utf-8",r.async=!0,r.src=e.p+"tf-"+({}[t]||t)+".js",s.appendChild(r)}},e.m=t,e.c=s,e.p="",e(0)}([function(t,e,i){"use strict";function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0}),e.TableFilter=void 0;var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=i(1),o=i(3),a=i(5),l=i(4),h=i(6),p=i(7),c=i(2),f=i(8),u=i(9),d=i(12),g=i(13),m=i(14),v=i(15),b=i(18),y=i(19),_=i(20),C=i(21),x=i(22),w=i(23),E=i(24),T=i(25),P=i(26),F=i(11),S=c.root.document;e.TableFilter=function(){function t(){var e=this;s(this,t),this.id=null,this.version="0.2.37",this.year=(new Date).getFullYear(),this.tbl=null,this.startRow=null,this.refRow=null,this.headersRow=null,this.cfg={},this.nbFilterableRows=0,this.nbCells=null;for(var i=arguments.length,r=Array(i),a=0;i>a;a++)r[a]=arguments[a];if(r.forEach(function(t){"object"===("undefined"==typeof t?"undefined":n(t))&&"TABLE"===t.nodeName?(e.tbl=t,e.id=t.id||"tf_"+(new Date).getTime()+"_"):(0,l.isString)(t)?(e.id=t,e.tbl=(0,o.elm)(t)):(0,l.isNumber)(t)?e.startRow=t:(0,l.isObj)(t)&&(e.cfg=t)}),!this.tbl||"TABLE"!==this.tbl.nodeName||0===this.getRowsNb())throw new Error("Could not instantiate TableFilter: HTML table\n DOM element not found.");var h=this.cfg;this.emitter=new f.Emitter,this.refRow=null===this.startRow?2:this.startRow+1;try{this.nbCells=this.getCellsNb(this.refRow)}catch(p){this.nbCells=this.getCellsNb(0)}this.basePath=h.base_path||"tablefilter/",this.fltGrid=h.grid!==!1,this.gridLayout=Boolean(h.grid_layout),this.filtersRowIndex=isNaN(h.filters_row_index)?0:h.filters_row_index,this.headersRow=isNaN(h.headers_row_index)?0===this.filtersRowIndex?1:0:h.headers_row_index,this.fltCellTag=(0,l.isString)(h.filters_cell_tag)?h.filters_cell_tag:F.CELL_TAG,this.fltIds=[],this.validRowsIndex=[],this.infDiv=null,this.lDiv=null,this.rDiv=null,this.mDiv=null,this.infDivCssClass=h.inf_div_css_class||"inf",this.lDivCssClass=h.left_div_css_class||"ldiv",this.rDivCssClass=h.right_div_css_class||"rdiv",this.mDivCssClass=h.middle_div_css_class||"mdiv",this.contDivCssClass=h.content_div_css_class||"cont",this.stylePath=h.style_path||this.basePath+"style/",this.stylesheet=h.stylesheet||this.stylePath+"tablefilter.css",this.stylesheetId=this.id+"_style",this.fltsRowCssClass=h.flts_row_css_class||"fltrow",this.enableIcons=h.enable_icons!==!1,this.alternateRows=Boolean(h.alternate_rows),this.hasColWidths=(0,l.isArray)(h.col_widths),this.colWidths=this.hasColWidths?h.col_widths:[],this.fltCssClass=h.flt_css_class||"flt",this.fltMultiCssClass=h.flt_multi_css_class||"flt_multi",this.fltSmallCssClass=h.flt_small_css_class||"flt_s",this.singleFltCssClass=h.single_flt_css_class||"single_flt",this.enterKey=h.enter_key!==!1,this.onBeforeFilter=(0,l.isFn)(h.on_before_filter)?h.on_before_filter:null,this.onAfterFilter=(0,l.isFn)(h.on_after_filter)?h.on_after_filter:null,this.caseSensitive=Boolean(h.case_sensitive),this.hasExactMatchByCol=(0,l.isArray)(h.columns_exact_match),this.exactMatchByCol=this.hasExactMatchByCol?h.columns_exact_match:[],this.exactMatch=Bool
},t.prototype.getFiltersId=function(){return this.fltIds||[]},t.prototype.getValidRows=function(t){if(!t)return this.validRowsIndex;var e=this.getRowsNb(!0);this.validRowsIndex=[];for(var i=this.refRow;e>i;i++){var s=this.tbl.rows[i];this.paging?"true"!==s.getAttribute("validRow")&&null!==s.getAttribute("validRow")||this.validRowsIndex.push(s.rowIndex):this.getRowDisplay(s)!==F.NONE&&this.validRowsIndex.push(s.rowIndex)}return this.validRowsIndex},t.prototype.getFiltersRowIndex=function(){return this.filtersRowIndex},t.prototype.getHeadersRowIndex=function(){return this.headersRow},t.prototype.getStartRowIndex=function(){return this.refRow},t.prototype.getLastRowIndex=function(){var t=this.getRowsNb(!0);return t-1},t.prototype.getHeaderElement=function(t){for(var e=this.gridLayout?this.Mod.gridLayout.headTbl:this.tbl,i=(0,o.tag)(e,"thead"),s=this.headersRow,n=void 0,r=0;r<this.nbCells;r++)if(r===t){0===i.length&&(n=e.rows[s].cells[r]),1===i.length&&(n=i[0].rows[s].cells[r]);break}return n},t.prototype.getHeadersText=function(){for(var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[0],e=[],i=0;i<this.nbCells;i++)if(!(t&&this.hasExtension("colsVisibility")&&this.extension("colsVisibility").isColHidden(i))){var s=this.getHeaderElement(i),n=(0,o.getFirstTextNode)(s);e.push(n)}return e},t.prototype.getFilterType=function(t){var e=this.cfg["col_"+t];return e?e.toLowerCase():F.INPUT},t.prototype.getFilterableRowsNb=function(){return this.getRowsNb(!1)},t.prototype.getValidRowsNb=function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];return this.getValidRows(t).length},t.prototype.config=function(){return this.cfg},t}()},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.keyCode=e.targetEvt=e.cancelEvt=e.stopEvt=e.removeEvt=e.addEvt=void 0;var s=i(2);e.addEvt=function(t,e,i,s){t.addEventListener?t.addEventListener(e,i,s):t.attachEvent?t.attachEvent("on"+e,i):t["on"+e]=i},e.removeEvt=function(t,e,i,s){t.detachEvent?t.detachEvent("on"+e,i):t.removeEventListener?t.removeEventListener(e,i,s):t["on"+e]=null},e.stopEvt=function(t){t||(t=s.root.event),t.stopPropagation?t.stopPropagation():t.cancelBubble=!0},e.cancelEvt=function(t){t||(t=s.root.event),t.preventDefault?t.preventDefault():t.returnValue=!1},e.targetEvt=function(t){return t||(t=s.root.event),t.target||t.srcElement},e.keyCode=function(t){return t.charCode?t.charCode:t.keyCode?t.keyCode:t.which?t.which:0}},function(t,e){(function(t){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t};e.root="object"===("undefined"==typeof self?"undefined":i(self))&&self.self===self&&self||"object"===("undefined"==typeof t?"undefined":i(t))&&t.global===t&&t||void 0}).call(e,function(){return this}())},function(t,e,i){"use strict";function s(){return a.documentElement.classList}Object.defineProperty(e,"__esModule",{value:!0}),e.tag=e.elm=e.createCheckItem=e.createOpt=e.removeClass=e.addClass=e.hasClass=e.createText=e.removeElm=e.createElm=e.getFirstTextNode=e.getText=void 0;var n=i(2),r=i(4),o=i(5),a=n.root.document,l=(e.getText=function(t){return(0,r.isUndef)(t.textContent)?(0,o.trim)(t.innerText):(0,o.trim)(t.textContent)},e.getFirstTextNode=function(t){for(var e=0;e<t.childNodes.length;e++){var i=t.childNodes[e];if(3===i.nodeType)return i.data}},e.createElm=function(){for(var t=arguments.length,e=Array(t),i=0;t>i;i++)e[i]=arguments[i];var s=e[0];if(!(0,r.isString)(s))return null;for(var n=a.createElement(s),o=0;o<e.length;o++){var l=e[o];(0,r.isArray)(l)&&2===l.length&&n.setAttribute(l[0],l[1])}return n}),h=(e.removeElm=function(t){return t.parentNode.removeChild(t)},e.createText=function(t){return a.createTextNode(t)}),p=e.hasClass=function(t,e){return(0,r.isUndef)(t)?!1:s()?t.classList.contains(e):t.className.match(new RegExp("(\\s|^)"+e+"(\\s|$)"))};e.addClass=function(t,e){return(0,r.isUndef)(t)?void 0:s()?void t.classList.add(e):void
return t.selectOptions(i,s)})},e}(o.Feature)},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.has=void 0;var s=i(5);e.has=function(t,e,i){for(var n=Boolean(i),r=0,o=t.length;o>r;r++)if((0,s.matchCase)(t[r].toString(),n)===e)return!0;return!1}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.ignoreCase=function(t,e){var i=t.toLowerCase(),s=e.toLowerCase();return s>i?-1:i>s?1:0},e.numSortAsc=function(t,e){return t-e},e.numSortDesc=function(t,e){return e-t}},function(t,e,i){"use strict";function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0}),e.CheckList=void 0;var o=i(10),a=i(3),l=i(16),h=i(5),p=i(17),c=i(1),f=i(4),u=i(11),d="Filter options for column {0} cannot be sorted in {1} manner.";e.CheckList=function(t){function e(i){s(this,e);var r=n(this,t.call(this,i,"checkList")),o=r.config;return r.containers=[],r.containerCssClass=o.div_checklist_css_class||"div_checklist",r.filterCssClass=o.checklist_css_class||"flt_checklist",r.itemCssClass=o.checklist_item_css_class||"flt_checklist_item",r.selectedItemCssClass=o.checklist_selected_item_css_class||"flt_checklist_slc_item",r.activateText=o.activate_checklist_text||"Click to load filter data",r.disabledItemCssClass=o.checklist_item_disabled_css_class||"flt_checklist_item_disabled",r.enableResetOption=o.enable_checklist_reset_filter!==!1,r.prfx="chkdiv_",r.isCustom=!1,r.opts=[],r.optsTxt=[],r.excludedOpts=[],r}return r(e,t),e.prototype.onChange=function(t){var e=(0,c.targetEvt)(t),i=this.tf;this.emitter.emit("filter-focus",i,e),i.filter()},e.prototype.optionClick=function(t){this.setCheckListValues(t.target),this.onChange(t)},e.prototype.onCheckListClick=function(t){var e=this,i=(0,c.targetEvt)(t);if(this.tf.loadFltOnDemand&&"0"===i.getAttribute("filled")){var s=i.getAttribute("ct"),n=this.containers[s];this.build(s),(0,c.removeEvt)(n,"click",function(t){return e.onCheckListClick(t)})}},e.prototype.init=function(t,e,i){var s=this,n=this.tf,r=e?n.externalFltTgtIds[t]:null,o=(0,a.createElm)("div",["id",this.prfx+t+"_"+n.id],["ct",t],["filled","0"]);o.className=this.containerCssClass,r?((0,a.elm)(r).appendChild(o),n.externalFltEls.push(o)):i.appendChild(o),this.containers[t]=o,n.fltIds.push(n.prfxFlt+t+"_"+n.id),n.loadFltOnDemand?((0,c.addEvt)(o,"click",function(t){return s.onCheckListClick(t)}),o.appendChild((0,a.createText)(this.activateText))):this.build(t),this.emitter.on(["build-checklist-filter"],function(t,e,i){return s.build(e,i)}),this.emitter.on(["select-checklist-options"],function(t,e,i){return s.selectOptions(e,i)}),this.initialized=!0},e.prototype.build=function(t){var e=this,i=this.tf;t=parseInt(t,10),this.emitter.emit("before-populating-filter",i,t),this.opts=[],this.optsTxt=[];var s=this.containers[t],n=(0,a.createElm)("ul",["id",i.fltIds[t]],["colIndex",t]);n.className=this.filterCssClass,(0,c.addEvt)(n,"change",function(t){return e.onChange(t)});var r=i.tbl.rows,o=i.getRowsNb(!0),f=i.caseSensitive;this.isCustom=i.isCustomOptions(t);var u=void 0,g=i.getActiveFilterId();i.linkedFilters&&g&&(u=i.getColumnIndexFromFilterId(g));var m=[];i.linkedFilters&&i.disableExcludedOptions&&(this.excludedOpts=[]),s.innerHTML="";for(var v=i.refRow;o>v;v++)if(!i.hasVisibleRows||-1===i.visibleRows.indexOf(v)){var b=r[v].cells,y=b.length;if(y===i.nbCells&&!this.isCustom)for(var _=0;y>_;_++)if(t===_&&(!i.linkedFilters||i.linkedFilters&&i.disableExcludedOptions)||t===_&&i.linkedFilters&&(""===r[v].style.display&&!i.paging||i.paging&&(!u||u===t||u!==t&&-1!==i.validRowsI
if(!this.initialized){var i=(0,a.createElm)("span",["id",this.prfxResetSpan+e.id]);this.btnResetTgtId||e.setToolbar();var s=this.btnResetTgtId?(0,a.elm)(this.btnResetTgtId):e.rDiv;if(s.appendChild(i),this.btnResetHtml){i.innerHTML=this.btnResetHtml;var n=i.firstChild;(0,l.addEvt)(n,"click",function(){return t.onClick()})}else{var r=(0,a.createElm)("a",["href","javascript:voelm(0);"]);r.className=e.btnResetCssClass,r.appendChild((0,a.createText)(this.btnResetText)),i.appendChild(r),(0,l.addEvt)(r,"click",function(){return t.onClick()})}this.btnResetEl=i.firstChild,this.initialized=!0}},e.prototype.destroy=function(){var t=this.tf;if(this.initialized){var e=(0,a.elm)(this.prfxResetSpan+t.id);e&&(0,a.removeElm)(e),this.btnResetEl=null,this.initialized=!1}},e}(o.Feature)},function(t,e,i){"use strict";function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0}),e.Help=void 0;var o=i(10),a=i(3),l=i(1),h=i(11),p="https://github.com/koalyptus/TableFilter/wiki/4.-Filter-operators",c="http://koalyptus.github.io/TableFilter/";e.Help=function(t){function e(i){s(this,e);var r=n(this,t.call(this,i,"help")),o=r.config;return r.tgtId=o.help_instructions_target_id||null,r.contTgtId=o.help_instructions_container_target_id||null,r.instrText=o.help_instructions_text?o.help_instructions_text:'Use the filters above each column to filter and limit table data. Advanced searches can be performed by using the following operators: <br /><b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>=</b>, <b>*</b>, <b>!</b>, <b>{</b>, <b>}</b>, <b>||</b>,<b>&amp;&amp;</b>, <b>[empty]</b>, <b>[nonempty]</b>, <b>rgx:</b><br/><a href="'+p+'" target="_blank">Learn more</a><hr/>',r.instrHtml=o.help_instructions_html||null,r.btnText=o.help_instructions_btn_text||"?",r.btnHtml=o.help_instructions_btn_html||null,r.btnCssClass=o.help_instructions_btn_css_class||"helpBtn",r.contCssClass=o.help_instructions_container_css_class||"helpCont",r.btn=null,r.cont=null,r.defaultHtml='<div class="helpFooter"><h4>TableFilter v'+i.version+'</h4><a href="'+c+'" target="_blank">'+c+"</a><br/><span>&copy;2015-"+i.year+' Max Guglielmi</span><div align="center" style="margin-top:8px;"><a href="javascript:void(0);" class="close">Close</a></div></div>',r.prfxHelpSpan="helpSpan_",r.prfxHelpDiv="helpDiv_",r.emitter.on(["init-help"],function(){return r.init()}),r}return r(e,t),e.prototype.init=function(){var t=this;if(!this.initialized){var e=this.tf,i=(0,a.createElm)("span",["id",this.prfxHelpSpan+e.id]),s=(0,a.createElm)("div",["id",this.prfxHelpDiv+e.id]);this.tgtId||e.setToolbar();var n=this.tgtId?(0,a.elm)(this.tgtId):e.rDiv;n.appendChild(i);var r=this.contTgtId?(0,a.elm)(this.contTgtId):i;if(this.btnHtml){i.innerHTML=this.btnHtml;var o=i.firstChild;(0,l.addEvt)(o,"click",function(){return t.toggle()}),r.appendChild(s)}else{r.appendChild(s);var h=(0,a.createElm)("a",["href","javascript:void(0);"]);h.className=this.btnCssClass,h.appendChild((0,a.createText)(this.btnText)),i.appendChild(h),(0,l.addEvt)(h,"click",function(){return t.toggle()})}this.instrHtml?(this.contTgtId&&r.appendChild(s),s.innerHTML=this.instrHtml,this.contTgtId||(s.className=this.contCssClass,(0,l.addEvt)(s,"dblclick",function(){return t.toggle()}))):(s.innerHTML=this.instrText,s.className=this.contCssClass,(0,l.addEvt)(s,"dblclick",function(){return t.toggle()})),s.innerHTML+=this.defaultHtml,(0,l.addEvt)(s,"click",function(){return t.toggle()}),this.cont=s,this.btn=i,this.initialized=!0}},e.prototype.toggle=function(){if(this.enabled!==!1){var t=this.cont.sty