1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-16 12:45:49 +02:00
TableFilter/dist/tablefilter/tablefilter.js

10 lines
117 KiB
JavaScript
Raw Normal View History

2016-05-08 07:33:19 +02:00
/**
* tablefilter v0.2.25 by Max Guglielmi
* build date: 2016-05-14T09:58:19.199Z
2016-05-08 07:33:19 +02: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 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 l,a,o=0,h=[];o<s.length;o++)a=s[o],n[a]&&h.push.apply(h,n[a]),n[a]=0;for(l in r)t[l]=r[l];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){return t&&t.__esModule?t:{"default":t}}function n(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 r="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},l=i(1),a=s(l),o=i(3),h=s(o),u=i(5),f=s(u),d=i(4),c=s(d),p=i(6),g=s(p),b=i(7),v=s(b),m=i(2),y=i(8),_=i(9),C=i(12),w=i(13),x=i(14),T=i(15),E=i(18),P=i(19),R=i(20),F=i(21),S=i(22),I=i(23),O=i(24),N=i(25),L=i(26),k=i(11),B=m.root.document;e.TableFilter=function(){function t(){var e=this;n(this,t),this.id=null,this.version="0.2.25",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;for(var i=arguments.length,s=Array(i),l=0;i>l;l++)s[l]=arguments[l];if(s.forEach(function(t){var i="undefined"==typeof t?"undefined":r(t);"object"===i&&t&&"TABLE"===t.nodeName?(e.tbl=t,e.id=t.id||"tf_"+(new Date).getTime()+"_"):"string"===i?(e.id=t,e.tbl=h["default"].id(t)):"number"===i?e.startRow=t:"object"===i&&(e.cfg=t)}),!this.tbl||"TABLE"!==this.tbl.nodeName||0===this.getRowsNb())throw new Error("Could not instantiate TableFilter: HTML table DOMElement not found.");var a=this.cfg;this.emitter=new y.Emitter,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=a.base_path||"tablefilter/",this.fltGrid=a.grid!==!1,this.gridLayout=Boolean(a.grid_layout),this.filtersRowIndex=isNaN(a.filters_row_index)?0:a.filters_row_index,this.headersRow=isNaN(a.headers_row_index)?0===this.filtersRowIndex?1:0:a.headers_row_index,this.fltCellTag=c["default"].isString(a.filters_cell_tag)?a.filters_cell_tag:k.CELL_TAG,this.fltIds=[],this.fltElms=[],this.validRowsIndex=[],this.fltGridEl=null,this.infDiv=null,this.lDiv=null,this.rDiv=null,this.mDiv=null,this.infDivCssClass=a.inf_div_css_class||"inf",this.lDivCssClass=a.left_div_css_class||"ldiv",this.rDivCssClass=a.right_div_css_class||"rdiv",this.mDivCssClass=a.middle_div_css_class||"mdiv",this.contDivCssClass=a.content_div_css_class||"cont",this.stylePath=a.style_path||this.basePath+"style/",this.stylesheet=a.stylesheet||this.stylePath+"tablefilter.css",this.stylesheetId=this.id+"_style",this.fltsRowCssClass=a.flts_row_css_class||"fltrow",this.enableIcons=a.enable_icons!==!1,this.alternateRows=Boolean(a.alternate_rows),this.hasColWidths=c["default"].isArray(a.col_widths),this.colWidths=this.hasColWidths?a.col_widths:null,this.fltCssClass=a.flt_css_class||"flt",this.fltMultiCssClass=a.flt_multi_css_class||"flt_multi",this.fltSmallCssClass=a.flt_small_css_class||"flt_s",this.singleFltCssClass=a.single_flt_css_class||"single_flt",this.enterKey=a.enter_key!==!1,this.onBeforeFilter=c["default"].isFn(a.on_before_filter)?a.on_before_filter:null,this.onAfterFilter=c["default"].isFn(a.on_after_filter)?a.on_after_filter:null,this.caseSens
2016-05-08 08:14:40 +02:00
this.setFilterValue(s[r],o)}}}},t.prototype.isExactMatch=function(t){var e=this.getFilterType(t);return this.exactMatchByCol[t]||this.exactMatch||e!==k.INPUT},t.prototype.isImported=function(t,e){for(var i=!1,s=e?e:"script",n="script"==s?"src":"href",r=h["default"].tag(B,s),l=0,a=r.length;a>l;l++)if(void 0!==r[l][n]&&r[l][n].match(t)){i=!0;break}return i},t.prototype["import"]=function(t,e,i,s){var n=s?s:"script",r=this.isImported(e,n);if(!r){var l=this,a=!1,o=void 0,u=h["default"].tag(B,"head")[0];o="link"===f["default"].lower(n)?h["default"].create("link",["id",t],["type","text/css"],["rel","stylesheet"],["href",e]):h["default"].create("script",["id",t],["type","text/javascript"],["src",e]),o.onload=o.onreadystatechange=function(){a||this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState||(a=!0,"function"==typeof i&&i.call(null,l))},o.onerror=function(){throw new Error("TableFilter could not load: "+e)},u.appendChild(o)}},t.prototype.hasGrid=function(){return this._hasGrid},t.prototype.getFiltersId=function(){return this.fltIds||[]},t.prototype.getValidRows=function(t){if(!t)return this.validRowsIndex;this.validRowsIndex=[];for(var e=this.refRow;e<this.getRowsNb(!0);e++){var i=this.tbl.rows[e];this.paging?"true"!==i.getAttribute("validRow")&&null!==i.getAttribute("validRow")||this.validRowsIndex.push(i.rowIndex):this.getRowDisplay(i)!==k.NONE&&this.validRowsIndex.push(i.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(){return this.nbRows-1},t.prototype.getHeaderElement=function(t){for(var e=this.gridLayout?this.Mod.gridLayout.headTbl:this.tbl,i=h["default"].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=h["default"].getFirstTextNode(s);e.push(n)}return e},t.prototype.getFilterType=function(t){var e=this.cfg["col_"+t];return e?f["default"].lower(e):k.INPUT},t.prototype.getFilterableRowsNb=function(){return this.getRowsNb(!1)},t.prototype.config=function(){return this.cfg},t}()},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var s=i(2);e["default"]={add:function(t,e,i,s){t.addEventListener?t.addEventListener(e,i,s):t.attachEvent?t.attachEvent("on"+e,i):t["on"+e]=i},remove:function(t,e,i,s){t.detachEvent?t.detachEvent("on"+e,i):t.removeEventListener?t.removeEventListener(e,i,s):t["on"+e]=null},stop:function(t){t||(t=s.root.event),t.stopPropagation?t.stopPropagation():t.cancelBubble=!0},cancel:function(t){t||(t=s.root.event),t.preventDefault?t.preventDefault():t.returnValue=!1},target:function(t){return t&&t.target||s.root.event&&s.root.event.srcElement},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(t){return t&&t.__esModule?t:{"default":t}}function n(){return document.documentElement.classList}Object.defineProperty(e,"__esModule",{value:!0});var r="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}
}if(i.sortSlc&&!this.isCustom&&(l?(this.opts.sort(),u&&u.sort()):(this.opts.sort(g["default"].ignoreCase),u&&u.sort(g["default"].ignoreCase))),-1!=i.sortNumAsc.indexOf(t))try{this.opts.sort(g["default"].numSortAsc),u&&u.sort(g["default"].numSortAsc),this.isCustom&&this.optsTxt.sort(g["default"].numSortAsc)}catch(T){throw new Error(y.replace("{0}",t).replace("{1}","ascending"))}if(-1!=i.sortNumDesc.indexOf(t))try{this.opts.sort(g["default"].numSortDesc),u&&u.sort(g["default"].numSortDesc),this.isCustom&&this.optsTxt.sort(g["default"].numSortDesc)}catch(T){throw new Error(y.replace("{0}",t).replace("{1}","ascending"))}this.addOptions(t,n,e,u),this.emitter.emit("after-populating-filter",i,t,n)},e.prototype.addOptions=function(t,e,i,s){var n=this.tf,r=e.value;e.innerHTML="",e=this.addFirstOption(e);for(var l=0;l<this.opts.length;l++)if(""!==this.opts[l]){var a=this.opts[l],o=this.isCustom?this.optsTxt[l]:a,u=!1;i&&n.disableExcludedOptions&&f["default"].has(s,c["default"].matchCase(a,n.matchCase),n.matchCase)&&(u=!0);var d=void 0;d=n.loadFltOnDemand&&r===this.opts[l]&&n.getFilterType(t)===m.SELECT?h["default"].createOpt(o,a,!0):h["default"].createOpt(o,a,!1),u&&(d.disabled=!0),e.appendChild(d)}e.setAttribute("filled","1")},e.prototype.addFirstOption=function(t){var e=this.tf,i=h["default"].createOpt(this.enableSlcResetFilter?e.displayAllText:"","");if(this.enableSlcResetFilter||(i.style.display=m.NONE),t.appendChild(i),e.enableEmptyOption){var s=h["default"].createOpt(e.emptyText,e.emOperator);t.appendChild(s)}if(e.enableNonEmptyOption){var n=h["default"].createOpt(e.nonEmptyText,e.nmOperator);t.appendChild(n)}return t},e.prototype.selectOptions=function(t){var e=arguments.length<=1||void 0===arguments[1]?[]:arguments[1],i=this.tf;if(i.getFilterType(t)===m.MULTIPLE&&0!==e.length){var s=i.getFilterElement(t);[].forEach.call(s.options,function(t){""!==e[0]&&""!==t.value||(t.selected=!1),""!==t.value&&f["default"].has(e,t.value,!0)&&(t.selected=!0)})}},e.prototype.getValues=function(t){var e=this.tf,i=e.getFilterElement(t),s=[];return i.selectedOptions?[].forEach.call(i.selectedOptions,function(t){return s.push(t.value)}):[].forEach.call(i.options,function(t){t.selected&&s.push(t.value)}),s},e.prototype.destroy=function(){var t=this;this.emitter.off(["build-select-filter"],function(e,i,s){return t.build(e,i,s)}),this.emitter.off(["select-options"],function(e,i,s){return t.selectOptions(i,s)})},e}(a.Feature)},function(t,e,i){"use strict";function s(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var n=i(5),r=s(n);e["default"]={has:function(t,e,i){for(var s=void 0===i?!1:i,n=0;n<t.length;n++)if(r["default"].matchCase(t[n].toString(),s)==e)return!0;return!1}}},function(t,e,i){"use strict";function s(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var n=i(5),r=s(n);e["default"]={ignoreCase:function(t,e){var i=r["default"].lower(t),s=r["default"].lower(e);return s>i?-1:i>s?1:0},numSortAsc:function(t,e){return t-e},numSortDesc:function(t,e){return e-t}}},function(t,e,i){"use strict";function s(t){return t&&t.__esModule?t:{"default":t}}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(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 l(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 a=i(10),o=i(3),h=s(o),u=i(16),f=s(u),d=i(5),c=s(d),p=i(17),g=s(p),b=i(1),v=s(b),m=i(4),y=s(m),_=i(11),C="Filter options for column {0} cannot be sorted in {1} manner.";e.CheckList=function(t){function e(i){n(this,e);var s=r(this,t.call(this,i,"checkList")),l=i.config();return s.checkList
if(this.pagingLength=parseInt(e.options[i].value,10),this.startPagingRow=this.pagingLength*s,!isNaN(this.pagingLength)&&(this.startPagingRow>=t.nbFilterableRows&&(this.startPagingRow=t.nbFilterableRows-this.pagingLength),this.setPagingInfo(),this.pageSelectorType===v.SELECT)){var n=this.pagingSlc.options.length-1<=s?this.pagingSlc.options.length-1:s;this.pagingSlc.options[n].selected=!0}this.emitter.emit("after-page-length-change",t,this.pagingLength)}},e.prototype.resetPage=function(){var t=this.tf;if(this.isEnabled()){this.emitter.emit("before-reset-page",t);var e=t.feature("store").getPageNb();""!==e&&this.changePage(e-1),this.emitter.emit("after-reset-page",t,e)}},e.prototype.resetPageLength=function(){var t=this.tf;if(this.isEnabled()){this.emitter.emit("before-reset-page-length",t);var e=t.feature("store").getPageLength();""!==e&&(this.resultsPerPageSlc.options[e].selected=!0,this.changeResultsPerPage()),this.emitter.emit("after-reset-page-length",t,e)}},e.prototype.destroy=function(){var t=this,e=this.tf;if(this.initialized){var i=u["default"].id(this.prfxBtnNextSpan+e.id),s=u["default"].id(this.prfxBtnPrevSpan+e.id),n=u["default"].id(this.prfxBtnLastSpan+e.id),r=u["default"].id(this.prfxBtnFirstSpan+e.id),l=u["default"].id(this.prfxPgBeforeSpan+e.id),a=u["default"].id(this.prfxPgAfterSpan+e.id),o=u["default"].id(this.prfxPgSpan+e.id),h=this.evt;this.pagingSlc&&(this.pageSelectorType===v.SELECT?b["default"].remove(this.pagingSlc,"change",h.slcPagesChange):this.pageSelectorType===v.INPUT&&b["default"].remove(this.pagingSlc,"keypress",h._detectKey),u["default"].remove(this.pagingSlc)),i&&(b["default"].remove(i,"click",h.next),u["default"].remove(i)),s&&(b["default"].remove(s,"click",h.prev),u["default"].remove(s)),n&&(b["default"].remove(n,"click",h.last),u["default"].remove(n)),r&&(b["default"].remove(r,"click",h.first),u["default"].remove(r)),l&&u["default"].remove(l),a&&u["default"].remove(a),o&&u["default"].remove(o),this.hasResultsPerPage&&this.removeResultsPerPage(),this.emitter.off(["after-filtering"],function(){return t.resetPagingInfo()}),this.emitter.off(["change-page"],function(e,i){return t.setPage(i)}),this.emitter.off(["change-page-results"],function(e,i){return t.changeResultsPerPage(i)}),this.pagingSlc=null,this.nbPages=0,this.disable(),this.initialized=!1}},e}(o.Feature)},function(t,e,i){"use strict";function s(t){return t&&t.__esModule?t:{"default":t}}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(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 l(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.ClearButton=void 0;var a=i(10),o=i(3),h=s(o),u=i(1),f=s(u);e.ClearButton=function(t){function e(i){n(this,e);var s=r(this,t.call(this,i,"btnReset")),l=s.config;return s.btnResetTgtId=l.btn_reset_target_id||null,s.btnResetEl=null,s.btnResetText=l.btn_reset_text||"Reset",s.btnResetTooltip=l.btn_reset_tooltip||"Clear filters",s.btnResetHtml=l.btn_reset_html||(i.enableIcons?'<input type="button" value="" class="'+i.btnResetCssClass+'" title="'+s.btnResetTooltip+'" />':null),s.prfxResetSpan="resetspan_",s}return l(e,t),e.prototype.onClick=function(){this.isEnabled()&&this.tf.clearFilters()},e.prototype.init=function(){var t=this,e=this.tf;if(!this.initialized){var i=h["default"].create("span",["id",this.prfxResetSpan+e.id]);this.btnResetTgtId||e.setToolbar();var s=this.btnResetTgtId?h["default"].id(this.btnResetTgtId):e.rDiv;if(s.appendChild(i),this.btnResetHtml){i.innerHTML=this.btnResetHtml;var n=i.firstChild;f["default"].add(n,"click",function(){t.onClick()})}else{var r=h["default"].create("a",["href","javascript:void(0);"]);r.className=e.bt