1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-15 20:25:07 +02:00
TableFilter/dist/tablefilter/tablefilter.js

6 lines
109 KiB
JavaScript
Raw Normal View History

2015-05-15 16:26:21 +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 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 l=i[s]={exports:{},id:s,loaded:!1};return t[s].call(l.exports,l,l.exports,e),l.loaded=!0,l.exports}var s=window.webpackJsonp;window.webpackJsonp=function(i,a){for(var r,n,o=0,h=[];o<i.length;o++)n=i[o],l[n]&&h.push.apply(h,l[n]),l[n]=0;for(r in a)t[r]=a[r];for(s&&s(i,a);h.length;)h.shift().call(null,e)};var i={},l={0:0};return e.e=function(t,s){if(0===l[t])return s.call(null,e);if(void 0!==l[t])l[t].push(s);else{l[t]=[s];var i=document.getElementsByTagName("head")[0],a=document.createElement("script");a.type="text/javascript",a.charset="utf-8",a.async=!0,a.src=e.p+""+({}[t]||t)+".js",i.appendChild(a)}},e.m=t,e.c=i,e.p="/dist/tablefilter/",e(0)}([function(t,e,s){"use strict";function i(t,e){if(t){e||(e="us");var s=t;return s="us"===h.Str.lower(e)?+s.replace(/[^\d\.-]/g,""):+s.replace(/[^\d\,-]/g,"").replace(",",".")}}function l(){if(E.body.__defineGetter__&&HTMLElement){var t=HTMLElement.prototype;t.__defineGetter__&&t.__defineGetter__("outerHTML",function(){var t=this.parentNode,e=o.Dom.create(t.tagName);e.appendChild(this);var s=e.innerHTML;return t.appendChild(this),s}),t.__defineSetter__&&HTMLElement.prototype.__defineSetter__("outerHTML",function(t){var e=this.ownerDocument.createRange();e.setStartBefore(this);var s=e.createContextualFragment(t);return this.parentNode.replaceChild(s,this),t})}}var a=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},r=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}}();Object.defineProperty(e,"__esModule",{value:!0});var n=s(2),o=s(3),h=s(4),p=s(5),d=s(6),c=s(7),u=s(8),f=s(9),g=s(10),v=s(11),m=s(12),C=s(13),b=s(14),_=s(15),y=s(16),w=s(17),x=s(18),T=s(19),k=s(20),I=s(21),R=s(22),S=window,D=u.DateHelper.isValid,F=u.DateHelper.format,E=S.document,P=function(){function t(e){if(a(this,t),0!==arguments.length){if(this.id=e,this.version="0.0.1",this.year=(new Date).getFullYear(),this.tbl=o.Dom.id(e),this.startRow=null,this.refRow=null,this.headersRow=null,this.cfg={},this.nbFilterableRows=null,this.nbRows=null,this.nbCells=null,this._hasGrid=!1,this.enableModules=!1,!this.tbl||"table"!==h.Str.lower(this.tbl.nodeName)||0===this.getRowsNb())throw new Error("Could not instantiate TableFilter class: HTML table not found.");if(arguments.length>1)for(var s=0;s<arguments.length;s++){var i=arguments[s],r=typeof i;switch(h.Str.lower(r)){case"number":this.startRow=i;break;case"object":this.cfg=i}}var n=this.cfg;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=n.base_path||"tablefilter/",this.extensionsPath=n.extensions_path||this.basePath+"extensions/",this.fltTypeInp="input",this.fltTypeSlc="select",this.fltTypeMulti="multiple",this.fltTypeCheckList="checklist",this.fltTypeNone="none",this.fltCol=[];for(var c=0;c<this.nbCells;c++){var u=n["col_"+c],f=u?h.Str.lower(u):this.fltTypeInp;this.fltCol.push(f),this["col"+c]=f}this.publicMethods=void 0!==n.public_methods?n.public_methods:!1,this.fltGrid=n.grid===!1?!1:!0,this.gridLayout=n.grid_layout?!0:!1,this.sourceTblHtml=null,this.gridLayout&&(void 0===this.tbl.outerHTML&&l(),this.sourceTblHtml=this.tbl.outerHTML),this.filtersRowIndex=n.filters_row_index||0,this.headersRow=n.headers_row_index||(0===this.filtersRowIndex?1:0),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.tblData=[],this.validRowsIndex=null,this.
2015-05-14 12:08:19 +02:00
2015-05-15 16:26:21 +02:00
for(u.className=h.checkListItemCssClass,d.appendChild(u),p.appendChild(d),a=e[l].split(" "+this.orOperator+" "),j=0;j<a.length;j++)if(""!==a[j]){var f=o.Dom.createCheckItem(this.fltIds[l]+"_"+(j+1),a[j],a[j]);f.className=h.checkListItemCssClass,d.appendChild(f),f.check.checked=!0,h.setCheckListValues(f.check),this.hasStoredValues=!0}}}!this.hasStoredValues&&this.paging&&this.Cpt.paging.setPagingInfo()}}}},{key:"filter",value:function(){this.EvtManager(this.Evt.name.filter)}},{key:"_filter",value:function(){function t(t,e,s){if(r.highlightKeywords&&e){t=t.replace(m,""),t=t.replace(C,""),t=t.replace(b,""),t=t.replace(_,"");var i=t;(d.test(t)||u.test(t)||f.test(t)||g.test(t)||v.test(t))&&(i=o.Dom.getText(s)),""!==i&&r.Cpt.highlightKeyword.highlight(s,i,r.Cpt.highlightKeyword.highlightCssClass)}}function e(t,e,s){var a,o,c,T=f.test(t),k=d.test(t),I=g.test(t),R=u.test(t),S=v.test(t),E=C.test(t),P=m.test(t),L=b.test(t),A=_.test(t),B=y===t,O=w===t,M=x.test(t),V=T&&D(t.replace(f,""),N),H=k&&D(t.replace(d,""),N),U=I&&D(t.replace(g,""),N),j=R&&D(t.replace(u,""),N),G=S&&D(t.replace(v,""),N),z=E&&D(t.replace(C,""),N);if(D(e,N))o=F(e,N),V?(c=F(t.replace(f,""),N),a=c>o):H?(c=F(t.replace(d,""),N),a=c>=o):j?(c=F(t.replace(u,""),N),a=o>=c):U?(c=F(t.replace(g,""),N),a=o>c):G?(c=F(t.replace(v,""),N),a=o.toString()!=c.toString()):z?(c=F(t.replace(C,""),N),a=o.toString()==c.toString()):m.test(t)?a=r._containsStr(t.replace(m,""),e,null,!1):D(t,N)?(c=F(t,N),a=o.toString()==c.toString()):B?a=h.Str.isEmpty(e):O&&(a=!h.Str.isEmpty(e));else if(r.hasColNbFormat&&r.colNbFormat[s]?(n=i(e,r.colNbFormat[s]),p=r.colNbFormat[s]):","===r.thousandsSeparator&&"."===r.decimalSeparator?(n=i(e,"us"),p="us"):(n=i(e,"eu"),p="eu"),k)a=n<=i(t.replace(d,""),p);else if(R)a=n>=i(t.replace(u,""),p);else if(T)a=n<i(t.replace(f,""),p);else if(I)a=n>i(t.replace(g,""),p);else if(S)a=r._containsStr(t.replace(v,""),e)?!1:!0;else if(P)a=r._containsStr(t.replace(m,""),e,null,!1);else if(E)a=r._containsStr(t.replace(C,""),e,null,!0);else if(L)a=0===e.indexOf(t.replace(b,""))?!0:!1;else if(A){var K=t.replace(_,"");a=e.lastIndexOf(K,e.length-1)===e.length-1-(K.length-1)&&e.lastIndexOf(K,e.length-1)>-1?!0:!1}else if(B)a=h.Str.isEmpty(e);else if(O)a=!h.Str.isEmpty(e);else if(M)try{var W=t.replace(x,""),$=new RegExp(W);a=$.test(e)}catch(q){a=!1}else{var Y=l["col_"+s];a=r._containsStr(t,e,Y?Y:r.fltTypeInp)}return a}if(this.fltGrid&&(this._hasGrid||this.isFirstLoad)){this.onBeforeFilter&&this.onBeforeFilter.call(null,this);var s=this.tbl.rows,l=this.cfg,a=0;this.validRowsIndex=[];var r=this;this.highlightKeywords&&this.Cpt.highlightKeyword.unhighlightAll(),this.popUpFilters&&this.Cpt.popupFilter.buildIcons(),this.markActiveColumns&&this.clearActiveColumns(),this.searchArgs=this.getFiltersValue();for(var n,p,d=new RegExp(this.leOperator),u=new RegExp(this.geOperator),f=new RegExp(this.lwOperator),g=new RegExp(this.grOperator),v=new RegExp(this.dfOperator),m=new RegExp(h.Str.rgxEsc(this.lkOperator)),C=new RegExp(this.eqOperator),b=new RegExp(this.stOperator),_=new RegExp(this.enOperator),y=this.emOperator,w=this.nmOperator,x=new RegExp(h.Str.rgxEsc(this.rgxOperator)),T=this.refRow;T<this.nbRows;T++){"none"===s[T].style.display&&(s[T].style.display="");var k=s[T].cells,I=k.length;if(I===this.nbCells){for(var R=[],S="include"===this.searchType?!0:!1,E=!1,P=0;I>P;P++){var L=this.searchArgs[this.singleSearchFlt?0:P],N=this.hasColDateType?this.colDateType[P]:this.defaultDateType;if(""!==L){var A=h.Str.matchCase(this.getCellData(P,k[P]),this.matchCase),B=L.split(this.orOperator),O=B.length>1?!0:!1,M=L.split(this.anOperator),V=M.length>1?!0:!1;if(O||V){for(var H,U=!1,j=O?B:M,G=0;G<j.length&&(H=h.Str.trim(j[G]),U=e(H,A,P),t(H,U,k[P]),!O||!U)&&(!V||U);G++);R[P]=U}else R[P]=e(h.Str.trim(L),A,P),t(L,R[P],k[P]);R[P]||(S="include"===this.searchType?!1:!0),this.singleSearchFlt&&R[P]&&(E=!0),this.popUpFilters&&this.Cpt.popupFilter.buildIcon(P,!0),this.markActiveColumns&&T===this.refRow&&(this.onBeforeActiveColumn&&this.onBeforeActiveColumn.call(null,this,P),o.Dom.addClass(this.getHeaderElement(P),th
"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}}();Object.defineProperty(e,"__esModule",{value:!0});var a=s(3),r=s(4),n=function(){function t(e){i(this,t);var s=e.config();this.highlightCssClass=s.highlight_css_class||"keyword",this.highlightedNodes=[],this.tf=e}return l(t,[{key:"highlight",value:function(t,e,s){if(t.hasChildNodes)for(var i=t.childNodes,l=0;l<i.length;l++)this.highlight(i[l],e,s);if(3===t.nodeType){var n=r.Str.lower(t.nodeValue),o=r.Str.lower(e);if(-1!=n.indexOf(o)){var h=t.parentNode;if(h&&h.className!=s){var p=t.nodeValue,d=n.indexOf(o),c=a.Dom.text(p.substr(0,d)),u=p.substr(d,e.length),f=a.Dom.text(p.substr(d+e.length)),g=a.Dom.text(u),v=a.Dom.create("span");v.className=s,v.appendChild(g),h.insertBefore(c,t),h.insertBefore(v,t),h.insertBefore(f,t),h.removeChild(t),this.highlightedNodes.push(v.firstChild)}}}}},{key:"unhighlight",value:function(t,e){for(var s=[],i=this.highlightedNodes,l=0;l<i.length;l++){var a=i[l];if(a){var n=r.Str.lower(a.nodeValue),o=r.Str.lower(t);if(-1!==n.indexOf(o)){var h=a.parentNode;if(h&&h.className===e){var p=h.previousSibling,d=h.nextSibling;if(!p||!d)continue;d.nodeValue=p.nodeValue+a.nodeValue+d.nodeValue,p.nodeValue="",a.nodeValue="",s.push(l)}}}}for(var c=0;c<s.length;c++)i.splice(s[c],1)}},{key:"unhighlightAll",value:function(){if(this.tf.highlightKeywords&&this.tf.searchArgs){for(var t=0;t<this.tf.searchArgs.length;t++)this.unhighlight(this.tf.searchArgs[t],this.highlightCssClass);this.highlightedNodes=[]}}}]),t}();e.HighlightKeyword=n},function(t,e,s){(function(t){"use strict";var i=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},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}}();Object.defineProperty(e,"__esModule",{value:!0});var a=s(6),r=s(3),n=s(2),o=s(24),h=function(){function e(t){i(this,e);var s=t.config();t.isExternalFlt=!0,t.externalFltTgtIds=[],this.popUpImgFlt=s.popup_filters_image||t.themesPath+"icn_filter.gif",this.popUpImgFltActive=s.popup_filters_image_active||t.themesPath+"icn_filterActive.gif",this.popUpImgFltHtml=s.popup_filters_image_html||'<img src="'+this.popUpImgFlt+'" alt="Column filter" />',this.popUpDivCssClass=s.popup_div_css_class||"popUpFilter",this.onBeforePopUpOpen=a.Types.isFn(s.on_before_popup_filter_open)?s.on_before_popup_filter_open:null,this.onAfterPopUpOpen=a.Types.isFn(s.on_after_popup_filter_open)?s.on_after_popup_filter_open:null,this.onBeforePopUpClose=a.Types.isFn(s.on_before_popup_filter_close)?s.on_before_popup_filter_close:null,this.onAfterPopUpClose=a.Types.isFn(s.on_after_popup_filter_close)?s.on_after_popup_filter_close:null,this.popUpFltSpans=[],this.popUpFltImgs=[],this.popUpFltElms=this.popUpFltElmCache||[],this.popUpFltAdjustToContainer=!0,this.prfxPopUpSpan="popUpSpan_",this.prfxPopUpDiv="popUpDiv_",this.tf=t}return l(e,[{key:"onClick",value:function(e){var s=e||t.event,i=s.target.parentNode,l=parseInt(i.getAttribute("ci"),10);if(this.closeAll(l),this.toggle(l),this.popUpFltAdjustToContainer){var a=this.popUpFltElms[l],h=this.tf.getHeaderElement(l),p=.95*h.clientWidth;if(o.Helpers.isIE()){var d=r.Dom.position(h).left;a.style.left=d+"px"}a.style.width=parseInt(p,10)+"px"}n.Event.cancel(s),n.Event.stop(s)}},{key:"init",value:function(){for(var t=this,e=this.tf,s=0;s<e.nbCells;s++)if(e["col"+s]!==e.fltTypeNone){var i=r.Dom.create("span",["id",this.prfxPopUpSpan+e.id+"_"+s],["ci",s]);i.innerHTML=this.popUpImgFltHtml;var l=e.getHeaderElement(s);l.appendChild(i),n.Event.add(i,"click",function(e){t.onClick(e)}),this.popUpFltSpans[s]=i,this.popUpFltImgs[s]=i.firstChild}}},{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:r.Dom.create("div",["id",this.prfxPopUpDiv+s.id+"_"+t]);i.className=t
}},{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;e.paging&&(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.Cpt.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(t.paging){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.Cpt.store.savePageLength(t.pgLenCookie)}}}},{key:"_resetPage",value:function(t){var e=this.tf,s=e.Cpt.store.getPageNb(t);""!==s&&this.changePage(s-1)}},{key:"_resetPageLength",value:function(t){var e=this.tf;if(e.paging){var s=e.Cpt.store.getPageLength(t);""!==s&&(this.resultsPerPageSlc.options[s].selected=!0,this.changeResultsPerPage())}}},{key:"destroy",value:function(){var t=this.tf;if(t.hasGrid()){var e,s,i,l,r,n,h;e=a.Dom.id(this.prfxBtnNextSpan+t.id),s=a.Dom.id(this.prfxBtnPrevSpan+t.id),i=a.Dom.id(this.prfxBtnLastSpan+t.id),l=a.Dom.id(this.prfxBtnFirstSpan+t.id),r=a.Dom.id(this.prfxPgBeforeSpan+t.id),n=a.Dom.id(this.prfxPgAfterSpan+t.id),h=a.Dom.id(this.prfxPgSpan+t.id);var p=this.evt;this.pagingSlc&&(this.pageSelectorType===t.fltTypeSlc?o.Event.remove(this.pagingSlc,"change",p.slcPagesChange):this.pageSelectorType===t.fltTypeInp&&o.Event.remove(this.pagingSlc,"keypress",p._detectKey),this.pagingSlc.parentNode.removeChild(this.pagingSlc)),e&&(o.Event.remove(e,"click",p.next),e.parentNode.removeChild(e)),s&&(o.Event.remove(s,"click",p.prev),s.parentNode.removeChild(s)),i&&(o.Event.remove(i,"click",p.last),i.parentNode.removeChild(i)),l&&(o.Event.remove(l,"click",p.first),l.parentNode.removeChild(l)),r&&r.parentNode.removeChild(r),n&&n.parentNode.removeChild(n),h&&h.parentNode.removeChild(h),this.hasResultsPerPage&&this.removeResultsPerPage(),this.pagingSlc=null,this.nbPages=0,this.isPagingRemoved=!0,t.paging=!1}}}]),t}();e.Paging=h},function(t,e,s){"use strict";var i=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},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}}();Object.defineProperty(e,"__esModule",{value:!0});var a=s(3),r=s(2),n=function(){function t(e){i(this,t);var s=e.config();this.btnResetTgtId=s.btn_reset_target_id||null,this.btnResetEl=null,this.btnResetText=s.btn_reset_text||"Reset",this.btnResetTooltip=s.btn_reset_tooltip||"Clear filters",this.btnResetHtml=s.btn_reset_html||(e.enableIcons?'<input type="button" value="" class="'+e.btnResetCssClass+'" title="'+this.btnResetTooltip+'" />':null),this.prfxResetSpan="resetspan_",this.tf=e}return l(t,[{key:"onClick",value:function(){this.tf.clearFilters()}},{key:"init",value:function(){var t=this,e=this.tf;if(e.hasGrid()||e.isFirstLoad||!e.btnResetEl){var s=a.Dom.create("span",["id",this.prfxResetSpan+e.id]);this.btnResetTgtId||e.setToolbar();var i=this.btnResetTgtId?a.Dom.id(this.btnResetTgtId):e.rDiv;if(i.appendChild(s),this.btnResetHtml){s.innerHTML=th