1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-23 08:42:18 +02:00
TableFilter/dist/tablefilter_all.js

10 lines
106 KiB
JavaScript
Raw Normal View History

/*------------------------------------------------------------------------
- TableFilter v1.0 by Max Guglielmi
2014-10-06 13:08:29 +02:00
- build date: Mon Oct 06 2014 22:02:06
- http://tablefilter.free.fr
- Copyright (c) 2014, Licensed under the MIT License
------------------------------------------------------------------------*/
2014-10-06 13:08:29 +02:00
function TF(a){"use strict";if(0!==arguments.length){if(this.id=a,this.version="2.5",this.year=(new Date).getFullYear(),this.tbl=tf_Id(a),this.startRow=null,this.refRow=null,this.headersRow=null,this.fObj=null,this.nbFilterableRows=null,this.nbRows=null,this.nbCells=null,this.hasGrid=!1,this.enableModules=!1,!this.tbl||"table"!==this.tbl.nodeName.tf_LCase()||0===this.GetRowsNb())throw new Error("Could not instantiate TF object: table not found.");if(arguments.length>1)for(var b=0;b<arguments.length;b++){var c=arguments[b],d=typeof c;switch(d.tf_LCase()){case"number":this.startRow=c;break;case"object":this.fObj=c}}var e=this.fObj||{};this.refRow=null===this.startRow?2:this.startRow+1;try{this.nbCells=this.GetCellsNb(this.refRow)}catch(f){this.nbCells=this.GetCellsNb(0)}this.basePath=void 0!==e.base_path?e.base_path:"TableFilter/",this.fltTypeInp="input",this.fltTypeSlc="select",this.fltTypeMulti="multiple",this.fltTypeCheckList="checklist",this.fltTypeNone="none",this.fltCol=[];for(var g=0;g<this.nbCells;g++){var h=this["col"+g],i=e["col_"+g];void 0===h&&(h=void 0===i?this.fltTypeInp:i.tf_LCase()),this.fltCol.push(h)}this.publicMethods=void 0!==e.public_methods?e.public_methods:!1,this.fltGrid=e.grid===!1?!1:!0,this.gridLayout=e.grid_layout?!0:!1,this.hasGridWidthsRow=!1,this.gridColElms=[],this.sourceTblHtml=null,this.gridLayout&&(void 0===this.tbl.outerHTML&&tf_SetOuterHtml(),this.sourceTblHtml=this.tbl.outerHTML),this.filtersRowIndex=e.filters_row_index||0,this.headersRow=e.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"!==e.filters_cell_tag||"td"!==e.filters_cell_tag?"td":e.filters_cell_tag,this.fltIds=[],this.fltElms=[],this.searchArgs=null,this.tblData=[],this.validRowsIndex=null,this.fltGridEl=null,this.isFirstLoad=!0,this.infDiv=null,this.lDiv=null,this.rDiv=null,this.mDiv=null,this.contDiv=null,this.infDivCssClass=e.inf_div_css_class||"inf",this.lDivCssClass=e.left_div_css_class||"ldiv",this.rDivCssClass=e.right_div_css_class||"rdiv",this.mDivCssClass=e.middle_div_css_class||"mdiv",this.contDivCssClass=e.content_div_css_class||"cont",this.stylesheet=e.stylesheet||this.basePath+"filtergrid.css",this.stylesheetId=this.id+"_style",this.fltsRowCssClass=e.flts_row_css_class||"fltrow",this.enableIcons=e.enable_icons===!1?!1:!0,this.alternateBgs=e.alternate_rows===!0?!0:!1,this.hasColWidth=e.col_width===!0?!0:!1,this.colWidth=this.hasColWidth?e.col_width:null,this.fixedHeaders=e.fixed_headers===!0?!0:!1,this.tBodyH=isNaN(e.tbody_height)?200:e.tbody_height,this.fltCssClass=e.flt_css_class||"flt",this.fltMultiCssClass=e.flt_multi_css_class||"flt_multi",this.fltSmallCssClass=e.flt_small_css_class||"flt_s",this.singleFltCssClass=e.single_flt_css_class||"single_flt",this.isStartBgAlternate=!0,this.rowBgEvenCssClass=e.even_row_css_class||"even",this.rowBgOddCssClass=e.odd_row_css_class||"odd",this.enterKey=e.enter_key===!1?!1:!0,this.isModFilterFn=e.mod_filter_fn===!0?!0:!1,this.modFilterFn=this.isModFilterFn?e.mod_filter_fn:null,this.onBeforeFilter=tf_IsFn(e.on_before_filter)?e.on_before_filter:null,this.onAfterFilter=tf_IsFn(e.on_after_filter)?e.on_after_filter:null,this.matchCase=e.match_case===!0?!0:!1,this.exactMatch=e.exact_match===!0?!0:!1,this.refreshFilters=e.refresh_filters===!0?!0:!1,this.disableExcludedOptions=e.disable_excluded_options===!0?!0:!1,this.activeFlt=null,this.activeFilterId=null,this.hasColOperation=e.col_operation===!0?!0:!1,this.colOperation=null,this.hasVisibleRows=e.rows_always_visible===!0?!0:!1,this.visibleRows=this.hasVisibleRows?e.rows_always_visible:[],this.searchType=e.search_type||"include",this.isExternalFlt=e.external_flt_grid===!0?!0:!1,this.externalFltTgtIds=e.external_flt_grid_ids||null,this.externalFltEls=[],this.execDelay=isNaN(e.exec_delay)?100:parseInt(e.exec_delay,10),this.status=e.status===!0?!0:!1,this.onFiltersLoaded=tf_IsFn(e.on_filters_loaded)?e.on_filters_loaded:null,this.singleSearchFlt=e.single_search_filter===!0?!0:!1,this.onRowVal
break;case d.Evt.name.resetvalues:d._ResetValues(),d._Filter();break;case d.Evt.name.resetpage:d._ResetPage(d.pgNbCookie);break;case d.Evt.name.resetpagelength:d._ResetPageLength(d.pgLenCookie);break;case d.Evt.name.sort:break;case d.Evt.name.loadextensions:d._LoadExtensions();break;case d.Evt.name.loadthemes:d._LoadThemes();break;default:d["_"+a].call(null,d,b)}(d.status||d.statusBar)&&d.StatusMsg(""),d.loader&&d.ShowLoader("none")}}var d=this,e=b&&void 0!==b.slcIndex?b.slcIndex:null,f=b&&void 0!==b.slcExternal?b.slcExternal:!1,g=b&&void 0!==b.slcId?b.slcId:null,h=b&&void 0!==b.pgIndex?b.pgIndex:null;if(this.loader||this.status||this.statusBar){try{this.ShowLoader(""),this.StatusMsg(d["msg"+a])}catch(i){}window.setTimeout(c,this.execDelay)}else c()},ImportModule:function(a){a.path&&a.name&&this.IncludeFile(a.name,a.path,a.init)},LoadExtensions:function(){if(!this.Ext){var a=this;this.Ext={list:{},add:function(b,c,d,e){var f=d.split("/")[d.split("/").length-1],g=new RegExp(f),h=d.replace(g,"");a.Ext.list[b]={name:b,description:c,file:f,path:h,callback:e}}}}this.EvtManager(this.Evt.name.loadextensions)},_LoadExtensions:function(){if(this.hasExtensions&&tf_IsArray(this.extensions.name)&&tf_IsArray(this.extensions.src))for(var a=this.extensions,b=0;b<a.name.length;b++){var c=a.src[b],d=a.name[b],e=a.initialize&&a.initialize[b]?a.initialize[b]:null,f=a.description&&a.description[b]?a.description[b]:null;this.Ext.add(d,f,c,e),tf_IsImported(c)?e.call(null,this):this.IncludeFile(d,c,e)}},LoadThemes:function(){this.EvtManager(this.Evt.name.loadthemes)},_LoadThemes:function(){if(this.hasThemes){if(!this.Thm){var a=this;this.Thm={list:{},add:function(b,c,d,e){var f=d.split("/")[d.split("/").length-1],g=new RegExp(f),h=d.replace(g,"");a.Thm.list[b]={name:b,description:c,file:f,path:h,callback:e}}}}if(this.enableDefaultTheme&&(this.themes={name:["DefaultTheme"],src:[this.themesPath+"Default/TF_Default.css"],description:["Default Theme"]},this.Thm.add("DefaultTheme",this.themesPath+"Default/TF_Default.css","Default Theme")),tf_IsArray(this.themes.name)&&tf_IsArray(this.themes.src))for(var b=this.themes,c=0;c<b.name.length;c++){var d=b.src[c],e=b.name[c],f=b.initialize&&b.initialize[c]?b.initialize[c]:null,g=b.description&&b.description[c]?b.description[c]:null;this.Thm.add(e,g,d,f),tf_IsImported(d,"link")||this.IncludeFile(e,d,null,"link"),tf_IsFn(f)&&f.call(null,this)}this.btnResetText=null,this.btnResetHtml='<input type="button" value="" class="'+this.btnResetCssClass+'" title="Clear filters" />',this.btnPrevPageHtml='<input type="button" value="" class="'+this.btnPageCssClass+' previousPage" title="Previous page" />',this.btnNextPageHtml='<input type="button" value="" class="'+this.btnPageCssClass+' nextPage" title="Next page" />',this.btnFirstPageHtml='<input type="button" value="" class="'+this.btnPageCssClass+' firstPage" title="First page" />',this.btnLastPageHtml='<input type="button" value="" class="'+this.btnPageCssClass+' lastPage" title="Last page" />',this.loader=!0,this.loaderHtml='<div class="defaultLoader"></div>',this.loaderText=null}},RemoveGrid:function(){if(this.fltGrid&&this.hasGrid){var a=this.tbl.rows;this.paging&&this.RemovePaging(),this.statusBar&&this.RemoveStatusBar(),this.rowsCounter&&this.RemoveRowsCounter(),this.btnReset&&this.RemoveResetBtn(),(this.helpInstructions||!this.helpInstructions)&&this.RemoveHelpInstructions(),this.paging&&this.RemoveResultsPerPage(),this.isExternalFlt&&!this.popUpFilters&&this.RemoveExternalFlts(),this.fixedHeaders&&this.RemoveFixedHeaders(),this.infDiv&&this.RemoveTopDiv(),this.highlightKeywords&&this.UnhighlightAll(),this.sort&&this.RemoveSort(),this.loader&&this.RemoveLoader(),this.popUpFilters&&this.RemovePopupFilters(),this.markActiveColumns&&this.ClearActiveColumns(),(this.editable||this.selectable)&&this.RemoveEditable();for(var b=this.refRow;b<this.nbRows;b++){a[b].style.display="";try{a[b].hasAttribute("validRow")&&a[b].removeAttribute("validRow")}catch(c){for(var d=a[b],e=d.attributes,f=0;f<e.length;f++)"validrow"===e.nodeName.tf_LCase()&&d.removeAttribute("validRo
}}b=b?b:!1;var f=this.prfxCheckListDiv+a+"_"+this.id;if((tf_Id(f)||b)&&(tf_Id(c)||!b)){var g=b?tf_Id(c):this.checkListDiv[a],h=tf_CreateElm("ul",["id",this.fltIds[a]],["colIndex",a]);h.className=this.checkListCssClass,h.onchange=this.Evt._OnCheckListChange;var i,j=this,k=this.tbl.rows,l=[],m=this.hasCustomSlcOptions&&this.customSlcOptions.cols.tf_Has(a),n=[];this.refreshFilters&&this.activeFilterId&&(i=this.activeFilterId.split("_")[0],i=i.split(this.prfxFlt)[1]);var o,p;this.refreshFilters&&this.disableExcludedOptions&&(o=[],p=[]);for(var q=this.refRow;q<this.nbRows;q++)if(!this.hasVisibleRows||!this.visibleRows.tf_Has(q)||this.paging){var r=k[q].cells,s=r.length;if(s==this.nbCells&&!m)for(var t=0;s>t;t++)if(a===t&&(!this.refreshFilters||this.refreshFilters&&this.disableExcludedOptions)||a===t&&this.refreshFilters&&(""===k[q].style.display&&!this.paging||this.paging&&(!i||i===a||i!=a&&this.validRowsIndex.tf_Has(q)))){var u=this.GetCellData(t,r[t]),v=u.tf_MatchCase(this.matchCase);l.tf_Has(v,this.matchCase)||l.push(u);var w=p[t];this.refreshFilters&&this.disableExcludedOptions&&(w||(p[t]=this.GetFilteredDataCol(t)),w.tf_Has(v,this.matchCase)||o.tf_Has(v,this.matchCase)||this.isFirstLoad||o.push(u))}}if(m){var x=this.__getCustomValues(a);l=x[0],n=x[1]}if(this.sortSlc&&!m&&(this.matchCase?(l.sort(),o&&o.sort()):(l.sort(tf_IgnoreCaseSort),o&&o.sort(tf_IgnoreCaseSort))),this.sortNumAsc&&this.sortNumAsc.tf_Has(a))try{l.sort(tf_NumSortAsc),o&&o.sort(tf_NumSortAsc),m&&n.sort(tf_NumSortAsc)}catch(y){l.sort(),o&&o.sort(),m&&n.sort()}if(this.sortNumDesc&&this.sortNumDesc.tf_Has(a))try{l.sort(tf_NumSortDesc),o&&o.sort(tf_NumSortDesc),m&&n.sort(tf_NumSortDesc)}catch(y){l.sort(),o&&o.sort(),m&&n.sort()}if(e(this.separator),this.fillSlcOnDemand&&(g.innerHTML=""),g.appendChild(h),g.setAttribute("filled","1"),j.rememberGridValues&&tf_isIE){var z=h.getAttribute("indexes");if(z)for(var A=z.split(","),B=0;B<A.length;B++){var C=tf_Id(this.fltIds[a]+"_"+A[B]);C&&(C.checked=!0)}}}},__setCheckListValues:function(a){if(a){for(var b=a.value,c=parseInt(a.id.split("_")[2],10),d="ul",e="li",f=a;f.nodeName.tf_LCase()!==d;)f=f.parentNode;if(f.nodeName.tf_LCase()===d){var g=f.childNodes[c],h=f.getAttribute("colIndex"),i=f.getAttribute("value"),j=f.getAttribute("indexes");if(a.checked){if(""===b){if(j&&""!==j)for(var k=j.split(this.separator),l=0;l<k.length;l++){var m=tf_Id(this.fltIds[h]+"_"+k[l]);m&&(m.checked=!1,tf_RemoveClass(f.childNodes[k[l]],this.checkListSlcItemCssClass))}f.setAttribute("value",""),f.setAttribute("indexes","")}else i=i?i:"",b=(i+" "+b+" "+this.orOperator).tf_Trim(),c=j+c+this.separator,f.setAttribute("value",b),f.setAttribute("indexes",c),tf_Id(this.fltIds[h]+"_0")&&(tf_Id(this.fltIds[h]+"_0").checked=!1);g.nodeName.tf_LCase()===e&&(tf_RemoveClass(f.childNodes[0],this.checkListSlcItemCssClass),tf_AddClass(g,this.checkListSlcItemCssClass))}else{if(""!==b){var n=new RegExp(tf_RegexpEscape(b+" "+this.orOperator));i=i.replace(n,""),f.setAttribute("value",i.tf_Trim());var o=new RegExp(tf_RegexpEscape(c+this.separator));j=j.replace(o,""),f.setAttribute("indexes",j)}g.nodeName.tf_LCase()===e&&tf_RemoveClass(g,this.checkListSlcItemCssClass)}}}},SetResetBtn:function(){if(this.hasGrid||this.isFirstLoad||!this.btnResetEl){var a=this.fObj;this.btnResetTgtId=a.btn_reset_target_id||null,this.btnResetEl=null,this.btnResetText=a.btn_reset_text||"Reset",this.btnResetTooltip=a.btn_reset_tooltip||"Clear filters",this.btnResetHtml=a.btn_reset_html||(this.enableIcons?'<input type="button" value="" class="'+this.btnResetCssClass+'" title="'+this.btnResetTooltip+'" />':null);var b=tf_CreateElm("span",["id",this.prfxResetSpan+this.id]);this.btnResetTgtId||this.SetTopDiv();var c=this.btnResetTgtId?tf_Id(this.btnResetTgtId):this.rDiv;if(c.appendChild(b),this.btnResetHtml){b.innerHTML=this.btnResetHtml;var d=b.firstChild;d.onclick=this.Evt._Clear}else{var e=tf_CreateElm("a",["href","javascript:void(0);"]);e.className=this.btnResetCssClass,e.appendChild(tf_CreateText(this.btnResetText)),b.appendChild(e),e.onclick=this.Evt._Clear}this.btnResetEl=tf_Id(thi
var d=b?"":"none",e=b?"true":"false";c.style.display=d,this.paging&&c.setAttribute("validRow",e)}},ValidateAllRows:function(){if(this.hasGrid){this.validRowsIndex=[];for(var a=this.refRow;a<this.nbFilterableRows;a++)this.SetRowValidation(a,!0),this.validRowsIndex.push(a)}},SetFilterValue:function(a,b,c){if((this.fltGrid||this.isFirstLoad)&&this.GetFilterElement(a)){var d=this.GetFilterElement(a),e=void 0===c?!0:c,f=this["col"+a];if(b=void 0===b?"":b,f!==this.fltTypeMulti&&f!=this.fltTypeCheckList)d.value=b,f===this.fltTypeInp&&""!==this.inpWatermark&&tf_RemoveClass(d,this.inpWatermarkCssClass);else if(f===this.fltTypeMulti){for(var g=b.split(" "+this.orOperator+" "),h=0,i=0;i<d.options.length;i++)if(""===g&&(d.options[i].selected=!1),""===d.options[i].value&&(d.options[i].selected=!1),""!==d.options[i].value&&g.tf_Has(d.options[i].value,!0))if(tf_isIE){var j=h==g.length-1&&e?!0:!1;this.__deferMultipleSelection(d,i,j),h++}else d.options[i].selected=!0}else if(f===this.fltTypeCheckList){b=b.tf_MatchCase(this.matchCase);for(var k=b.split(" "+this.orOperator+" "),l=(d.setAttribute("value",""),d.setAttribute("indexes",""),0);l<tf_Tag(d,"li").length;l++){var m=tf_Tag(d,"li")[l],n=tf_Tag(m,"label")[0],o=tf_Tag(m,"input")[0],p=tf_GetNodeText(n).tf_MatchCase(this.matchCase);""!==p&&k.tf_Has(p,!0)?(o.checked=!0,this.__setCheckListValues(o)):(o.checked=!1,this.__setCheckListValues(o))}}}},SetColWidths:function(a){function b(a){if((d||d.nbCells==d.colWidth.length)&&d.nbCells==a.cells.length)for(var b=0;b<d.nbCells;b++)a.cells[b].style.width=d.colWidth[b]}if(this.fltGrid&&this.hasColWidth){var c,d=this;c=void 0===a?"none"!=this.tbl.rows[0].style.display?0:1:a,b(this.tbl.rows[c])}},SetVisibleRows:function(){if(this.hasGrid&&this.hasVisibleRows&&!this.paging)for(var a=0;a<this.visibleRows.length;a++)this.visibleRows[a]<=this.nbRows&&this.SetRowValidation(this.visibleRows[a],!0)},ClearFilters:function(){this.EvtManager(this.Evt.name.clear)},_ClearFilters:function(){if(this.fltGrid){this.onBeforeReset&&this.onBeforeReset.call(null,this,this.GetFiltersValue());for(var a=0;a<this.fltIds.length;a++)this.SetFilterValue(a,"");this.refreshFilters&&(this.activeFilterId="",this.RefreshFiltersGrid()),this.rememberPageLen&&tf_RemoveCookie(this.pgLenCookie),this.rememberPageNb&&tf_RemoveCookie(this.pgNbCookie),this.onAfterReset&&this.onAfterReset.call(null,this)}},ClearActiveColumns:function(){for(var a=0;a<this.fltIds.length;a++)tf_RemoveClass(this.GetHeaderElement(a),this.activeColumnsCssClass)},RefreshGrid:function(a){var b=a?a:this.fObj,c=this.sort;c&&(this.sort=!1),this.nbRows=this.GetRowsNb(),this.RemoveGrid(),window["tf_"+this.id]=new TF(this.id,this.startRow,b),this.isFirstLoad=!0,this.fltIds=[],this._AddGrid(),c&&(this.st.setTBody(this.tbl.tBodies[0]),this.sort=!0)},RefreshFiltersGrid:function(){var a=this.GetFiltersByType(this.fltTypeSlc,!0),b=this.GetFiltersByType(this.fltTypeMulti,!0),c=this.GetFiltersByType(this.fltTypeCheckList,!0),d=a.concat(b);if(d=d.concat(c),this.activeFilterId){var e=this.activeFilterId.split("_")[0];e=e.split(this.prfxFlt)[1];for(var f,g=0;g<d.length;g++){var h=tf_Id(this.fltIds[d[g]]);if(f=this.GetFilterValue(d[g]),e!==d[g]||this.paging&&a.tf_Has(d[g])&&e===d[g]||!this.paging&&(c.tf_Has(d[g])||b.tf_Has(d[g]))||f===this.displayAllText){if(c.tf_Has(d[g])?this.checkListDiv[d[g]].innerHTML="":h.innerHTML="",this.fillSlcOnDemand){var i=tf_CreateOpt(this.displayAllText,"");h&&h.appendChild(i)}c.tf_Has(d[g])?this._PopulateCheckList(d[g]):this._PopulateSelect(d[g],!0),this.SetFilterValue(d[g],f)}}}},SetColOperation:function(){if(this.isFirstLoad||this.hasGrid){this.onBeforeOperation&&this.onBeforeOperation.call(null,this);var colOperation=this.colOperation,labelId=colOperation.id,colIndex=colOperation.col,operation=colOperation.operation,outputType=colOperation.write_method,totRowIndex=colOperation.tot_row_index,excludeRow=colOperation.exclude_row,decimalPrecision=void 0!==colOperation.decimal_precision?colOperation.decimal_precision:2,ucolIndex=[],ucolMax=0;ucolIndex[ucolMax]=colIndex[0];for(var ii=1;ii<colIndex.leng