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

10 lines
107 KiB
JavaScript
Raw Normal View History

/*------------------------------------------------------------------------
- TableFilter v3.0.0 by Max Guglielmi
2014-11-08 13:37:24 +01:00
- build date: Sat Nov 08 2014 23:36:19
- http://tablefilter.free.fr
- Copyright (c) 2014, Licensed under the MIT License
------------------------------------------------------------------------*/
2014-11-08 13:37:24 +01:00
!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",[],function(){var a={};return a.add=function(a,b,c,d){a.attachEvent?a.attachEvent("on"+b,c):a.addEventListener?a.addEventListener(b,c,void 0===d?!1:d):a["on"+b]=c},a.remove=function(a,b,c,d){a.detachEvent?a.detachEvent("on"+b,c):a.removeEventListener?a.removeEventListener(b,c,void 0===d?!1:d):a["on"+b]=null},a.stop=function(a){a||(a=window.event),a.stopPropagation?a.stopPropagation():a.cancelBubble=!0},a.cancel=function(a){a||(a=window.event),a.preventDefault?a.preventDefault():a.returnValue=!1},a}),define("dom",["require"],function(){function a(){return document.documentElement.classList}var b={};return b.getText=function(a){var b=a.textContent||a.innerText||a.innerHTML.replace(/<[^<>]+>/g,"");return b=b.replace(/^\s+/,"").replace(/\s+$/,"")},b.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}},b.text=function(a){return document.createTextNode(a)},b.position=function(a){var b=0,c=0;if(a&&a.offsetParent)do b+=a.offse
}else{var n=i===this.fltTypeInp?"text":"hidden",o=dom.create(this.fltTypeInp,["id",this.prfxFlt+g+"_"+this.id],["type",n],["ct",g]);if("hidden"!=n&&(o.value=this.isInpWatermarkArray?this.inpWatermark[g]:this.inpWatermark),o.className=a,""!==this.inpWatermark&&dom.addClass(o,this.inpWatermarkCssClass),o.onfocus=this.Evt._OnInpFocus,j?(dom.id(j).appendChild(o),this.externalFltEls.push(o)):h.appendChild(o),this.fltIds.push(this.prfxFlt+g+"_"+this.id),o.onkeypress=this.Evt._DetectKey,o.onkeydown=this.Evt._OnKeyDown,o.onkeyup=this.Evt._OnKeyUp,o.onblur=this.Evt._OnInpBlur,this.rememberGridValues){var p=cookie.read(this.fltsValuesCookie),q=new RegExp(this.separator,"g"),r=p.split(q);" "!=r[g]&&this.SetFilterValue(g,r[g],!1)}}if(g==c-1&&this.displayBtn){var s=dom.create(this.fltTypeInp,["id",this.prfxValButton+g+"_"+this.id],["type","button"],["value",this.btnText]);s.className=this.btnCssClass,j?dom.id(j).appendChild(s):h.appendChild(s),s.onclick=this.Evt._OnBtnClick}}}else this.__resetGrid();else this.refRow=this.refRow-1,this.gridLayout&&(this.refRow=0),this.nbFilterableRows=this.GetRowsNb(),this.nbVisibleRows=this.nbFilterableRows,this.nbRows=this.nbFilterableRows+this.refRow;this.rowsCounter&&this.SetRowsCounter(),this.statusBar&&this.SetStatusBar(),this.fixedHeaders&&!this.isFirstLoad&&this.SetFixedHeaders(),this.paging&&this.SetPaging(),this.hasResultsPerPage&&this.paging&&this.SetResultsPerPage(),this.btnReset&&this.SetResetBtn(),this.helpInstructions&&this.SetHelpInstructions(),this.hasColWidth&&!this.gridLayout&&this.SetColWidths(),this.alternateBgs&&this.isStartBgAlternate&&this.SetAlternateRows(),this.hasColOperation&&this.fltGrid&&(this.colOperation=b.col_operation,this.SetColOperation()),(this.sort||this.gridLayout)&&this.SetSort(),(this.selectable||this.editable)&&this.SetEditable(),this.isFirstLoad=!1,this.hasGrid=!0,(this.rememberGridValues||this.rememberPageLen||this.rememberPageNb)&&this.ResetValues(),this.gridLayout||dom.addClass(this.tbl,this.prfxTf),this.loader&&this.loaderCpt.show("none"),this.hasExtensions&&this.LoadExtensions(),this.onFiltersLoaded&&this.onFiltersLoaded.call(null,this)}},EvtManager:function(a,b){function c(){if(a){switch(a){case d.Evt.name.filter:d.isModFilterFn?d.modFilterFn.call(null,d):d._Filter();break;case d.Evt.name.populateselect:d.refreshFilters?d._PopulateSelect(e,!0):d._PopulateSelect(e,!1,f,g);break;case d.Evt.name.populatechecklist:d._PopulateCheckList(e,f,g);break;case d.Evt.name.changepage:d._ChangePage(h);break;case d.Evt.name.clear:d._ClearFilters(),d._Filter();break;case d.Evt.name.changeresultsperpage:d._ChangeResultsPerPage();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.loaderCpt.show("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.loaderCpt.show(""),this.StatusMsg(d["msg"+a])}catch(i){}global.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&&types.isArray(this.extensions.name)&&types.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),isImported
d.className=j.checkListItemCssClass,h.appendChild(d),d.check.onclick=function(a){j.__setCheckListValues(this),h.onchange.call(null,a)},hlp.isIE()&&(d.label.onclick=function(){d.check.click()}),b++}if(j.enableNonEmptyOption){var e=dom.createCheckItem(j.fltIds[a]+"_2",j.nmOperator,j.nonEmptyText);e.className=j.checkListItemCssClass,h.appendChild(e),e.check.onclick=function(a){j.__setCheckListValues(this),h.onchange.call(null,a)},hlp.isIE()&&(e.label.onclick=function(){e.check.click()}),b++}return b}function e(b){function c(a){j.__setCheckListValues(this),h.onchange.call(null,a)}function e(){this.firstChild.click()}var f=d(),g=[],i=cookie.getValueByIndex(j.fltsValuesCookie,a,b);i&&str.trim(i).length>0&&(j.hasCustomSlcOptions&&array.has(j.customSlcOptions.cols,a)?g.push(i):g=i.split(" "+j.orOperator+" "));for(var k=0;k<l.length;k++){var p=l[k],q=m?n[k]:p,r=dom.createCheckItem(j.fltIds[a]+"_"+(k+f),p,q);r.className=j.checkListItemCssClass,j.refreshFilters&&j.disableExcludedOptions&&array.has(o,str.matchCase(p,j.matchCase),j.matchCase)?(dom.addClass(r,j.checkListItemDisabledCssClass),r.check.disabled=!0,r.disabled=!0):r.check.onclick=c,h.appendChild(r),""===p&&(r.style.display="none"),j.rememberGridValues&&(j.hasCustomSlcOptions&&array.has(j.customSlcOptions.cols,a)&&-1!=g.toString().indexOf(p)||array.has(g,str.matchCase(p,j.matchCase),j.matchCase))&&(r.check.checked=!0,j.__setCheckListValues(r.check)),hlp.isIE()&&(r.label.onclick=e)}}b=b?b:!1;var f=this.prfxCheckListDiv+a+"_"+this.id;if((dom.id(f)||b)&&(dom.id(c)||!b)){var g=b?dom.id(c):this.checkListDiv[a],h=dom.create("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&&array.has(this.customSlcOptions.cols,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=[]);for(var q=this.refRow;q<this.nbRows;q++)if(!this.hasVisibleRows||!array.has(this.visibleRows,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&&array.has(this.validRowsIndex,q)))){var u=this.GetCellData(t,r[t]),v=str.matchCase(u,this.matchCase);array.has(l,v,this.matchCase)||l.push(u);var w=p[t];this.refreshFilters&&this.disableExcludedOptions&&(w||(p[t]=this.GetFilteredDataCol(t)),!array.has(w,v,this.matchCase)&&!array.has(o,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(ignoreCaseSort),o&&o.sort(ignoreCaseSort))),this.sortNumAsc&&array.has(this.sortNumAsc,a))try{l.sort(numSortAsc),o&&o.sort(numSortAsc),m&&n.sort(numSortAsc)}catch(y){l.sort(),o&&o.sort(),m&&n.sort()}if(this.sortNumDesc&&array.has(this.sortNumDesc,a))try{l.sort(numSortDesc),o&&o.sort(numSortDesc),m&&n.sort(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&&hlp.isIE()){var z=h.getAttribute("indexes");if(z)for(var A=z.split(","),B=0;B<A.length;B++){var C=dom.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;str.lower(f.nodeName)!==d;)f=f.parentNode;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=dom.id(this.fltIds[h]+"_"+k[l]);m&&(m.checked=!1,dom.removeClass(f.childNodes[k[l]],this.checkListSlcItemCssClass))}f.setAttribute("value",""),f.setAttribute("indexes","")}else i=i?i:"",b=str.trim(i+" "+b+" "+this.orOperator),c=j+c+this.separator,f.setAttribute("value",b),f.setAttribute(
return a&&(b=0),parseInt(c-b,10)},GetCellData:function(a,b){return void 0!==a&&b?this.customCellData&&array.has(this.customCellDataCols,a)?this.customCellData.call(null,this,b,a):dom.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||types.isObj(a)?a.style.display:void 0},SetRowValidation:function(a,b){var c=this.tbl.rows[a];if(c&&"boolean"===str.lower(typeof b)){this.hasVisibleRows&&array.has(this.visibleRows,a)&&!this.paging&&(b=!0);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&&dom.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&&array.has(g,d.options[i].value,!0))if(hlp.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=str.matchCase(b,this.matchCase);for(var k=b.split(" "+this.orOperator+" "),l=(d.setAttribute("value",""),d.setAttribute("indexes",""),0);l<dom.tag(d,"li").length;l++){var m=dom.tag(d,"li")[l],n=dom.tag(m,"label")[0],o=dom.tag(m,"input")[0],p=str.matchCase(dom.getText(n),this.matchCase);""!==p&&array.has(k,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&&cookie.remove(this.pgLenCookie),this.rememberPageNb&&cookie.remove(this.pgNbCookie),this.onAfterReset&&this.onAfterReset.call(null,this)}},ClearActiveColumns:function(){for(var a=0;a<this.fltIds.length;a++)dom.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