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

10 lines
105 KiB
JavaScript
Raw Normal View History

/*------------------------------------------------------------------------
- TableFilter v3.0.0 by Max Guglielmi
- build date: Mon Jan 26 2015 20:27:41
- http://tablefilter.free.fr
- Copyright (c) 2014, Licensed under the MIT License
------------------------------------------------------------------------*/
!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b:a.TableFilter=b()}(this,function(){var requirejs,require,define;return function(a){function b(a,b){return r.call(a,b)}function c(a,b){var c,d,e,f,g,h,i,j,k,l,m,n=b&&b.split("/"),o=p.map,q=o&&o["*"]||{};if(a&&"."===a.charAt(0))if(b){for(n=n.slice(0,n.length-1),a=a.split("/"),g=a.length-1,p.nodeIdCompat&&t.test(a[g])&&(a[g]=a[g].replace(t,"")),a=n.concat(a),k=0;k<a.length;k+=1)if(m=a[k],"."===m)a.splice(k,1),k-=1;else if(".."===m){if(1===k&&(".."===a[2]||".."===a[0]))break;k>0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}else 0===a.indexOf("./")&&(a=a.substring(2));if((n||q)&&o){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),n)for(l=n.length;l>0;l-=1)if(e=o[n.slice(0,l).join("/")],e&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&q&&q[d]&&(i=q[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function d(b,c){return function(){var d=s.call(arguments,0);return"string"!=typeof d[0]&&1===d.length&&d.push(null),k.apply(a,d.concat([b,c]))}}function e(a){return function(b){return c(b,a)}}function f(a){return function(b){n[a]=b}}function g(c){if(b(o,c)){var d=o[c];delete o[c],q[c]=!0,j.apply(a,d)}if(!b(n,c)&&!b(q,c))throw new Error("No "+c);return n[c]}function h(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function i(a){return function(){return p&&p.config&&p.config[a]||{}}}var j,k,l,m,n={},o={},p={},q={},r=Object.prototype.hasOwnProperty,s=[].slice,t=/\.js$/;l=function(a,b){var d,f=h(a),i=f[0];return a=f[1],i&&(i=c(i,b),d=g(i)),i?a=d&&d.normalize?d.normalize(a,e(b)):c(a,b):(a=c(a,b),f=h(a),i=f[0],a=f[1],i&&(d=g(i))),{f:i?i+"!"+a:a,n:a,pr:i,p:d}},m={require:function(a){return d(a)},exports:function(a){var b=n[a];return"undefined"!=typeof b?b:n[a]={}},module:function(a){return{id:a,uri:"",exports:n[a],config:i(a)}}},j=function(c,e,h,i){var j,k,p,r,s,t,u=[],v=typeof h;if(i=i||c,"undefined"===v||"function"===v){for(e=!e.length&&h.length?["require","exports","module"]:e,s=0;s<e.length;s+=1)if(r=l(e[s],i),k=r.f,"require"===k)u[s]=m.require(c);else if("exports"===k)u[s]=m.exports(c),t=!0;else if("module"===k)j=u[s]=m.module(c);else if(b(n,k)||b(o,k)||b(q,k))u[s]=g(k);else{if(!r.p)throw new Error(c+" missing "+k);r.p.load(r.n,d(i,!0),f(k),{}),u[s]=n[k]}p=h?h.apply(n[c],u):void 0,c&&(j&&j.exports!==a&&j.exports!==n[c]?n[c]=j.exports:p===a&&t||(n[c]=p))}else c&&(n[c]=h)},requirejs=require=k=function(b,c,d,e,f){if("string"==typeof b)return m[b]?m[b](c):g(l(b,c).f);if(!b.splice){if(p=b,p.deps&&k(p.deps,p.callback),!c)return;c.splice?(b=c,c=d,d=null):b=a}return c=c||function(){},"function"==typeof d&&(d=e,e=f),e?j(a,b,c,d):setTimeout(function(){j(a,b,c,d)},4),k},k.config=function(a){return k(a)},requirejs._defined=n,define=function(a,c,d){c.splice||(d=c,c=[]),!b(n,a)&&!b(o,a)&&(o[a]=[a,c,d])},define.amd={jQuery:!0}}(),define("../libs/almond/almond",function(){}),define("event",["exports"],function(a){var b={add:function(a,b,c,d){a.addEventListener?a.addEventListener(b,c,d):a.attachEvent?a.attachEvent("on"+b,c):a["on"+b]=c},remove:function(a,b,c,d){a.detachEvent?a.detachEvent("on"+b,c):a.removeEventListener?a.removeEventListener(b,c,d):a["on"+b]=null},stop:function(a){a||(a=window.event),a.stopPropagation?a.stopPropagation():a.cancelBubble=!0},cancel:function(a){a||(a=window.event),a.preventDefault?a.preventDefault():a.returnValue=!1}};a.Event=b}),define("dom",["exports"],function(a){function b(){return document.documentElement.classList}var c={};c.getText=function(a){var b=a.textContent||a.innerText||a.innerHTML.replace(/<[^<>]+>/g,"");return b=b.replace(/^\s+/,"").replace(/\s+$/,"")},c.create=function(a){if(a&&""!==a){var b=document.createElement(a),c=arguments;if(c.length>1)for(var d=0;d<c.length;d++){var e=typeof c[d];"object"===e.toLowerCase()&&2===c[d].length&&b.setAttribute(c[d][0],c[d][1])}return b}},c.text=function(a){return document.createTextNode(a)},c.position=function(a){var b=0,c=0;if(a&&a.offsetParent)do b+=a.offsetLeft,c+=a.offsetTop;while(a==a.
if(this.pagingLength=parseInt(b.options[b.selectedIndex].value,10),this.startPagingRow=this.pagingLength*c,!isNaN(this.pagingLength)){if(this.startPagingRow>=a.nbFilterableRows&&(this.startPagingRow=a.nbFilterableRows-this.pagingLength),this.setPagingInfo(),this.pageSelectorType===a.fltTypeSlc){var d=this.pagingSlc.options.length-1<=c?this.pagingSlc.options.length-1:c;this.pagingSlc.options[d].selected=!0}a.rememberPageLen&&a.Cpt.store.savePageLength(a.pgLenCookie)}}}},_resetPage:{writable:!0,value:function(a){var b=this.tf,c=b.Cpt.store.getPageNb(a);""!==c&&this.changePage(c-1)}},_resetPageLength:{writable:!0,value:function(a){var b=this.tf;if(b.paging){var c=b.Cpt.store.getPageLength(a);""!==c&&(this.resultsPerPageSlc.options[c].selected=!0,this.changeResultsPerPage())}}},destroy:{writable:!0,value:function(){var a=this.tf;if(a.hasGrid){var b,c,d,e,f,g,i;b=h.id(a.prfxBtnNextSpan+a.id),c=h.id(a.prfxBtnPrevSpan+a.id),d=h.id(a.prfxBtnLastSpan+a.id),e=h.id(a.prfxBtnFirstSpan+a.id),f=h.id(a.prfxPgBeforeSpan+a.id),g=h.id(a.prfxPgAfterSpan+a.id),i=h.id(a.prfxPgSpan+a.id);var j=this.evt;this.pagingSlc&&(this.pageSelectorType===a.fltTypeSlc?k.remove(this.pagingSlc,"change",j.slcPagesChange):this.pageSelectorType===a.fltTypeInp&&k.remove(this.pagingSlc,"keypress",j._detectKey),this.pagingSlc.parentNode.removeChild(this.pagingSlc)),b&&(k.remove(b,"click",j.next),b.parentNode.removeChild(b)),c&&(k.remove(c,"click",j.prev),c.parentNode.removeChild(c)),d&&(k.remove(d,"click",j.last),d.parentNode.removeChild(d)),e&&(k.remove(e,"click",j.first),e.parentNode.removeChild(e)),f&&f.parentNode.removeChild(f),g&&g.parentNode.removeChild(g),i&&i.parentNode.removeChild(i),this.hasResultsPerPage&&this.removeResultsPerPage(),this.pagingSlc=null,this.nbPages=0,this.isPagingRemoved=!0,a.paging=!1}}}}),a}();a.Paging=l}),define("modules/alternateRows",["exports","../dom"],function(a,b){var c=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},d=b.Dom,e=function(){var a=function(a){var b=a.fObj;this.evenCss=b.even_row_css_class||"even",this.oddCss=b.odd_row_css_class||"odd",this.tf=a};return c(a,null,{init:{writable:!0,value:function(){if(this.tf.hasGrid||this.tf.isFirstLoad)for(var a=(this.tf.tbl.rows,null===this.tf.validRowsIndex),b=a?this.tf.refRow:0,c=a?this.tf.nbFilterableRows+b:this.tf.validRowsIndex.length,d=0,e=b;c>e;e++){var f=a?e:this.tf.validRowsIndex[e];this.setRowBg(f,d),d++}}},setRowBg:{writable:!0,value:function(a,b){if(this.tf.alternateBgs&&!isNaN(a)){var c=this.tf.tbl.rows,e=b?b:a;this.removeRowBg(a),d.addClass(c[a],e%2?this.evenCss:this.oddCss)}}},removeRowBg:{writable:!0,value:function(a){if(!isNaN(a)){var b=this.tf.tbl.rows;d.removeClass(b[a],this.oddCss),d.removeClass(b[a],this.evenCss)}}},remove:{writable:!0,value:function(){if(this.tf.hasGrid){for(var a=(this.tf.tbl.rows,this.tf.refRow);a<this.tf.nbRows;a++)this.removeRowBg(a);this.tf.isStartBgAlternate=!0}}},enable:{writable:!0,value:function(){this.tf.alternateBgs=!0}},disable:{writable:!0,value:function(){this.tf.alternateBgs=!1}}}),a}();a.AlternateRows=e}),define("modules/colOps",["exports","../dom","../string"],function(exports,_dom,_string){var _classProps=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},Dom=_dom.Dom,Str=_string.Str,ColOps=function(){var ColOps=function(a){var b=a.fObj;this.colOperation=b.col_operation,this.tf=a};return _classProps(ColOps,null,{calc:{writable:!0,value:function(){if(this.tf.isFirstLoad||this.tf.hasGrid){this.tf.onBeforeOperation&&this.tf.onBeforeOperation.call(null,this.tf);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.length;ii++){for(var saved=0,jj=0;ucolMax>=jj;jj++)ucolIndex[jj]===colIndex[ii]&&(saved=1);0==
this.Ext.add(d,f,c,e),g(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")),p.isArray(this.themes.name)&&p.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,h=b.description&&b.description[c]?b.description[c]:null;this.Thm.add(e,h,d,f),g(d,"link")||this.IncludeFile(e,d,null,"link"),p.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.Cpt.paging.destroy(),this.statusBar&&this.RemoveStatusBar(),this.rowsCounter&&this.Cpt.rowsCounter.destroy(),this.btnReset&&this.RemoveResetBtn(),(this.helpInstructions||!this.helpInstructions)&&this.RemoveHelpInstructions(),this.isExternalFlt&&!this.popUpFilters&&this.RemoveExternalFlts(),this.infDiv&&this.RemoveTopDiv(),this.highlightKeywords&&this.Cpt.highlightKeyword.unhighlightAll(),this.sort&&this.RemoveSort(),this.loader&&this.Cpt.loader.remove(),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"===n.lower(e.nodeName)&&d.removeAttribute("validRow")}this.alternateBgs&&this.Cpt.alternateRows.removeRowBg(b)}this.fltGrid&&!this.gridLayout&&(this.fltGridEl=a[this.filtersRowIndex],this.tbl.deleteRow(this.filtersRowIndex)),this.gridLayout&&this.Cpt.gridLayout.destroy(),m.removeClass(this.tbl,this.prfxTf),this.activeFlt=null,this.isStartBgAlternate=!0,this.hasGrid=!1}},SetTopDiv:function(){if(null===this.infDiv){var a=m.create("div",["id",this.prfxInfDiv+this.id]);a.className=this.infDivCssClass,this.toolBarTgtId?m.id(this.toolBarTgtId).appendChild(a):this.gridLayout?(this.Cpt.gridLayout.tblMainCont.appendChild(a),a.className=this.gridInfDivCssClass):this.tbl.parentNode.insertBefore(a,this.tbl),this.infDiv=m.id(this.prfxInfDiv+this.id);var b=m.create("div",["id",this.prfxLDiv+this.id]);b.className=this.lDivCssClass,a.appendChild(b),this.lDiv=m.id(this.prfxLDiv+this.id);var c=m.create("div",["id",this.prfxRDiv+this.id]);c.className=this.rDivCssClass,a.appendChild(c),this.rDiv=m.id(this.prfxRDiv+this.id);var d=m.create("div",["id",this.prfxMDiv+this.id]);d.className=this.mDivCssClass,a.appendChild(d),this.mDiv=m.id(this.prfxMDiv+this.id),this.helpInstructions||this.SetHelpInstructions()}},RemoveTopDiv:function(){this.infDiv&&(this.infDiv.parentNode.removeChild(this.infDiv),this.infDiv=null)},RemoveExternalFlts:function(){if(this.isExternalFlt||this.externalFltTgtIds)for(var a=0;a<this.externalFltTgtIds.length;a++){var b=this.externalFltTgtIds[a],c=m.id(b);c&&(c.innerHTML="")}},SetSort:function(){var a=this.Evt._EnableSort,b=t
}}this.singleSearchFlt&&G&&(F=!0),F?(this.SetRowValidation(B,!0),this.validRowsIndex.push(B),this.alternateBgs&&this.Cpt.alternateRows.setRowBg(B,this.validRowsIndex.length),this.onRowValidated&&this.onRowValidated.call(null,this,B)):(this.SetRowValidation(B,!1),this.hasVisibleRows&&q.has(this.visibleRows,B)&&!this.paging?this.validRowsIndex.push(B):e++)}}this.nbVisibleRows=this.validRowsIndex.length,this.nbHiddenRows=e,this.isStartBgAlternate=!1,this.rememberGridValues&&this.Cpt.store.saveFilterValues(this.fltsValuesCookie),this.paging?(this.startPagingRow=0,this.currentPageNb=1,this.Cpt.paging.setPagingInfo(this.validRowsIndex)):this.ApplyGridProps(),this.onAfterFilter&&this.onAfterFilter.call(null,this)}},ApplyGridProps:function(){this.activeFlt&&n.lower(this.activeFlt.nodeName)===this.fltTypeSlc&&!this.popUpFilters&&(this.activeFlt.blur(),this.activeFlt.parentNode&&this.activeFlt.parentNode.focus()),this.visibleRows&&this.SetVisibleRows(),this.hasColOperation&&this.Cpt.colOps.calc(),this.refreshFilters&&this.RefreshFiltersGrid();var a=!this.paging&&this.hasVisibleRows?this.nbVisibleRows-this.visibleRows.length:this.nbVisibleRows;this.rowsCounter&&this.Cpt.rowsCounter.refresh(a),""!==this.inpWatermark&&this.SetWatermark(!0),this.popUpFilters&&this.CloseAllPopupFilters()},GetColValues:function(a,b,c){if(this.fltGrid){for(var d=this.tbl.rows,e=[],g=this.refRow;g<this.nbRows;g++){var h=!1;c&&p.isArray(c)&&(h=q.has(c,g));var i=d[g].cells,j=i.length;if(j==this.nbCells&&!h)for(var k=0;j>k;k++)if(k===a&&""===d[g].style.display){var l=n.lower(this.GetCellData(k,i[k])),m=this.colNbFormat?this.colNbFormat[a]:null,o=b?f(l,m):l;e.push(o)}}return e}},GetFilterValue:function(a){if(this.fltGrid){var b,c=this.GetFilterElement(a);if(!c)return"";var d=this.fltCol[a];if(d!==this.fltTypeMulti&&d!==this.fltTypeCheckList)b=c.value;else if(d===this.fltTypeMulti){b="";for(var e=0;e<c.options.length;e++)c.options[e].selected&&(b=b.concat(c.options[e].value+" "+this.orOperator+" "));b=b.substr(0,b.length-4)}else d===this.fltTypeCheckList&&(null!==c.getAttribute("value")?(b=c.getAttribute("value"),b=b.substr(0,b.length-3)):b="");return b}},GetFiltersValue:function(){if(this.fltGrid){for(var a=[],b=0;b<this.fltIds.length;b++)a.push(n.trim(n.matchCase(this.GetFilterValue(b),this.matchCase)));return a}},GetFilterId:function(){return this.fltGrid?this.fltIds[i]:void 0},GetFiltersByType:function(a,b){if(this.fltGrid){for(var c=[],d=0;d<this.fltIds.length;d++){var e=this["col"+d];if(e===n.lower(a)){var f=b?d:this.fltIds[d];c.push(f)}}return c}},GetFilterElement:function(a){return this.fltGrid?m.id(this.fltIds[a]):null},GetCellsNb:function(a){var b=a?this.tbl.rows[a]:this.tbl.rows[0];return b.cells.length},GetRowsNb:function(a){var b=this.refRow?this.refRow:0,c=this.tbl.rows.length;return a&&(b=0),parseInt(c-b,10)},GetCellData:function(a,b){return void 0!==a&&b?this.customCellData&&q.has(this.customCellDataCols,a)?this.customCellData.call(null,this,b,a):m.getText(b):""},GetTableData:function(){for(var a=this.tbl.rows,b=this.refRow;b<this.nbRows;b++){for(var c=[b,[]],d=a[b].cells,e=0;e<d.length;e++){var f=this.GetCellData(e,d[e]);c[1].push(f)}this.tblData.push(c)}return this.tblData},GetFilteredData:function(a){if(!this.validRowsIndex)return[];var b=this.tbl.rows,c=[];if(a){for(var d=this.gridLayout?this.headTbl:this.tbl,e=d.rows[this.headersRow],f=[e.rowIndex,[]],g=0;g<this.nbCells;g++){var h=this.GetCellData(g,e.cells[g]);f[1].push(h)}c.push(f)}for(var i=this.GetValidRowsIndex(!0),j=0;j<i.length;j++){for(var k=[this.validRowsIndex[j],[]],l=b[this.validRowsIndex[j]].cells,m=0;m<l.length;m++){var n=this.GetCellData(m,l[m]);k[1].push(n)}c.push(k)}return c},GetFilteredDataCol:function(a){if(void 0===a)return[];for(var b=this.GetFilteredData(),c=[],d=0;d<b.length;d++){var e=b[d],f=e[1],g=f[a];c.push(g)}return c},GetRowDisplay:function(a){return this.fltGrid||p.isObj(a)?a.style.display:void 0},SetRowValidation:function(a,b){var c=this.tbl.rows[a];if(c&&"boolean"===n.lower(typeof b)){this.hasVisibleRows&&q.has(this.visibleRows,a)&&!this.paging&&(b=!0);var