1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-04 07:33:18 +02:00
TableFilter/dist/tablefilter/tablefilter.js

10 lines
112 KiB
JavaScript
Raw Normal View History

2016-09-02 05:32:59 +02:00
/**
2016-09-07 13:37:22 +02:00
* tablefilter v0.2.65 by Max Guglielmi
* build date: 2016-09-07T11:33:04.337Z
2016-09-02 05:32:59 +02:00
* MIT License
*/
2016-09-07 13:37:22 +02:00
!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,l,a=0,h=[];a<s.length;a++)l=s[a],n[l]&&h.push.apply(h,n[l]),n[l]=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),l=i(5),a=i(4),h=i(6),c=i(7),f=i(2),p=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),S=i(11),F=f.root.document;e.TableFilter=function(){function t(){var e=this;s(this,t),this.id=null,this.version="0.2.65",this.year=(new Date).getFullYear(),this.tbl=null,this.refRow=null,this.headersRow=null,this.cfg={},this.nbFilterableRows=0,this.nbCells=null;for(var i=void 0,r=arguments.length,l=Array(r),h=0;r>h;h++)l[h]=arguments[h];if(l.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,a.isString)(t)?(e.id=t,e.tbl=(0,o.elm)(t)):(0,a.isNumber)(t)?i=t:(0,a.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 c=this.cfg;this.emitter=new p.Emitter,this.refRow=(0,a.isUndef)(i)?2:i+1;try{this.nbCells=this.getCellsNb(this.refRow)}catch(f){this.nbCells=this.getCellsNb(0)}this.basePath=c.base_path||"tablefilter/",this.fltGrid=c.grid!==!1,this.gridLayout=Boolean(c.grid_layout),this.filtersRowIndex=isNaN(c.filters_row_index)?0:c.filters_row_index,this.headersRow=isNaN(c.headers_row_index)?0===this.filtersRowIndex?1:0:c.headers_row_index,this.fltCellTag=(0,a.isString)(c.filters_cell_tag)?c.filters_cell_tag:S.CELL_TAG,this.fltIds=[],this.validRowsIndex=[],this.infDiv=null,this.lDiv=null,this.rDiv=null,this.mDiv=null,this.infDivCssClass=c.inf_div_css_class||"inf",this.lDivCssClass=c.left_div_css_class||"ldiv",this.rDivCssClass=c.right_div_css_class||"rdiv",this.mDivCssClass=c.middle_div_css_class||"mdiv",this.stylePath=c.style_path||this.basePath+"style/",this.stylesheet=c.stylesheet||this.stylePath+"tablefilter.css",this.stylesheetId=this.id+"_style",this.fltsRowCssClass=c.flts_row_css_class||"fltrow",this.enableIcons=c.enable_icons!==!1,this.alternateRows=Boolean(c.alternate_rows),this.hasColWidths=(0,a.isArray)(c.col_widths),this.colWidths=this.hasColWidths?c.col_widths:[],this.fltCssClass=c.flt_css_class||"flt",this.fltMultiCssClass=c.flt_multi_css_class||"flt_multi",this.fltSmallCssClass=c.flt_small_css_class||"flt_s",this.singleFltCssClass=c.single_flt_css_class||"single_flt",this.enterKey=c.enter_key!==!1,this.onBeforeFilter=(0,a.isFn)(c.on_before_filter)?c.on_before_filter:null,this.onAfterFilter=(0,a.isFn)(c.on_after_filter)?c.on_after_filter:null,this.caseSensitive=Boolean(c.case_sensitive),this.hasExactMatchByCol=(0,a.isArray)(c.columns_exact_match),this.exactMatchByCol=this.hasExactMatchByCol?c.columns_exact_match:[],this.exactMatch=Boolean(c.exact_match),this.linkedFilters=Boolean(c.linked_filters),this.disableExcludedOpti
2016-09-06 03:45:27 +02:00
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():S.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 l.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),l=n.root.document,a=(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=l.createElement(s),o=0;o<e.length;o++){var a=e[o];(0,r.isArray)(a)&&2===a.length&&n.setAttribute(a[0],a[1])}return n}),h=(e.removeElm=function(t){return t.parentNode.removeChild(t)},e.createText=function(t){return l.createTextNode(t)}),c=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(""===t.className?t.className=e:c(t,e)||(t.className+=" "+e))},e.removeClass=function(t,e){if(!(0,r.isUndef)(t)){if(s())return void t.classList.remove(e);var i=new RegExp("(\\s|^)"+e+"(\\s|$)","g");t.className=t.className.replace(i,"")}},e.createOpt=function(t,e,i){var s=!!i,n=s?a("option",["value",e],["selected","true"]):a("option",["value",e]);return n.appendChild(h(t)),n},e.createCheckItem=function(t,e,i){var s=a("li"),n=a("label",["for",t]),r=a("input",["id",t],["name",t],["type","checkbox"],["value",e]);return n.appendChild(r),n.appendChild(h(i)),s.appendChild(n),s.label=n,s.check=r,s},e.elm=function(t){return l.getElementById(t)},e.tag=function(t,e){return t.getElementsByTagName(e)}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=void 0,s=(e.isObj=function(t){return"[object Object]"===Object.prototype.toString.call(t)},e.isFn=function(t){return"[object Functi
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),l=i(3),a=i(16),h=i(5),c=i(17),f=i(1),p=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.optionClick=function(t){var e=(0,f.targetEvt)(t),i=this.tf;this.emitter.emit("filter-focus",i,e),this.setCheckListValues(e),i.filter()},e.prototype.onCheckListClick=function(t){var e=this,i=(0,f.targetEvt)(t);if(this.tf.loadFltOnDemand&&"0"===i.getAttribute("filled")){var s=i.getAttribute("ct"),n=this.containers[s];this.build(s),(0,f.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,l.createElm)("div",["id",this.prfx+t+"_"+n.id],["ct",t],["filled","0"]);o.className=this.containerCssClass,r?(0,l.elm)(r).appendChild(o):i.appendChild(o),this.containers[t]=o,n.fltIds.push(n.prfxFlt+t+"_"+n.id),n.loadFltOnDemand?((0,f.addEvt)(o,"click",function(t){return s.onCheckListClick(t)}),o.appendChild((0,l.createText)(this.activateText))):this.build(t),this.emitter.on(["build-checklist-filter"],function(t,e){return s.build(e)}),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.tf;t=parseInt(t,10),this.emitter.emit("before-populating-filter",e,t),this.opts=[],this.optsTxt=[];var i=this.containers[t],s=(0,l.createElm)("ul",["id",e.fltIds[t]],["colIndex",t]);s.className=this.filterCssClass;var n=e.tbl.rows,r=e.getRowsNb(!0),o=e.caseSensitive;this.isCustom=e.isCustomOptions(t);var f=void 0,p=e.getActiveFilterId();e.linkedFilters&&p&&(f=e.getColumnIndexFromFilterId(p));var u=[];e.linkedFilters&&e.disableExcludedOptions&&(this.excludedOpts=[]),i.innerHTML="";for(var g=e.refRow;r>g;g++)if(!e.hasVisibleRows||-1===e.visibleRows.indexOf(g)){var m=n[g].cells,v=m.length;if(v===e.nbCells&&!this.isCustom)for(var b=0;v>b;b++)if(t===b&&(!e.linkedFilters||e.linkedFilters&&e.disableExcludedOptions)||t===b&&e.linkedFilters&&(""===n[g].style.display&&!e.paging||e.paging&&(!f||f===t||f!==t&&-1!==e.validRowsIndex.indexOf(g)))){var y=e.getCellData(m[b]),_=(0,h.matchCase)(y,o);(0,a.has)(this.opts,_,o)||this.opts.push(y);var C=u[b];e.linkedFilters&&e.disableExcludedOptions&&(C||(C=e.getFilteredDataCol(b)),(0,a.has)(C,_,o)||(0,a.has)(this.excludedOpts,_,o)||this.excludedOpts.push(y))}}if(this.isCustom){var x=e.getCustomOptions(t);this.opts=x[0],this.optsTxt=x[1]}if(e.sortSlc&&!this.isCustom&&(o?(this.opts.sort(),this.excludedOpts&&this.excludedOpts.sort()):(this.opts.sort(c.ignoreCase),this.excludedOpts&&this.excludedOpts.sort(c.ignoreCase))),-1!==e.sortNumAsc.indexOf(t))try{this.opts.sort(c.numSortAsc),this.excludedOpts&&this.excludedOpts.sort(c.numSortAsc),this.isCustom&&this.optsTxt.sort(c.numSortAsc)}catch(w){throw new Error(d.replace("{0}",t).replace("{1}","ascending"))}if(-1!==e.sortNumDesc.indexOf(t))try{this.opts.sort(c.numSortDesc),this.excludedOpts&&this.excludedOpts.sort(c.numSortDesc),this.isCustom&&this.optsTxt.sort(c.numSortDesc)}catch(w){throw new Error(d.replace("{0}",t).replace("{1}","descending"))}this.addChecks(t,s),e.loadFltOnDemand&&(i.innerHTML=""),i.appendChild(s),i.setAttribute("filled","1"),this.emitter.emit("after-populating-filter",e,t,i)},e.prototype.ad
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="'+c+'" 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="'+f+'" target="_blank">'+f+"</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,l.createElm)("span",["id",this.prfxHelpSpan+e.id]),s=(0,l.createElm)("div",["id",this.prfxHelpDiv+e.id]);this.tgtId||e.setToolbar();var n=this.tgtId?(0,l.elm)(this.tgtId):e.rDiv;n.appendChild(i);var r=this.contTgtId?(0,l.elm)(this.contTgtId):i;if(this.btnHtml){i.innerHTML=this.btnHtml;var o=i.firstChild;(0,a.addEvt)(o,"click",function(){return t.toggle()}),r.appendChild(s)}else{r.appendChild(s);var h=(0,l.createElm)("a",["href","javascript:void(0);"]);h.className=this.btnCssClass,h.appendChild((0,l.createText)(this.btnText)),i.appendChild(h),(0,a.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,a.addEvt)(s,"dblclick",function(){return t.toggle()}))):(s.innerHTML=this.instrText,s.className=this.contCssClass,(0,a.addEvt)(s,"dblclick",function(){return t.toggle()})),s.innerHTML+=this.defaultHtml,(0,a.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.style.display;""===t||t===h.NONE?this.cont.style.display="inline":this.cont.style.display=h.NONE}},e.prototype.destroy=function(){this.initialized&&((0,l.removeElm)(this.btn),this.btn=null,this.cont&&((0,l.removeElm)(this.cont),this.cont=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.AlternateRows=void 0;var o=i(10),l=i(3);e.AlternateRows=function(t){function e(i){s(this,e);var r=n(this,t.call(this,i,"alternateRows")),o=r.config;return r.evenCss=o.even_row_css_class||"even",r.oddCss=o.odd_row_css_class||"odd",r}return r(e,t),e.prototype.init=function(){var t=this;this.initialized||(this.processAll(),this.emitter.on(["row-processed","row-paged"],function(e,i,s,n){return t.processRow(i,s,n)}),this.emitter.on(["column-sorted"],function(){return t.processAll()}),this.initialized=!0)},e.prototype.processAll=function(){if(this.isEnabled())for(var t=this.tf,e=t.getValidRows(!0),i=e.length,s=0,n=0;i>n;n++){var r=e[n];this.setRowBg(r,s),s++}},e.prototype.proce