1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-27 09:50:24 +02:00
TableFilter/dist/tablefilter.js

10 lines
112 KiB
JavaScript
Raw Normal View History

/*------------------------------------------------------------------------
- TableFilter v3.0.0 by Max Guglielmi
2015-02-28 10:27:28 +01:00
- build date: Sat Feb 28 2015 20:15:47
- http://tablefilter.free.fr
- Copyright (c) 2014, Licensed under the MIT License
------------------------------------------------------------------------*/
2015-02-28 10:27:28 +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",["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(e.sortSlc&&!this.isCustom&&(e.matchCase?(this.opts.sort(),p&&p.sort()):(this.opts.sort(l.ignoreCase),p&&p.sort(l.ignoreCase))),e.sortNumAsc&&j.has(e.sortNumAsc,a))try{this.opts.sort(numSortAsc),p&&p.sort(numSortAsc),this.isCustom&&this.optsTxt.sort(numSortAsc)}catch(z){this.opts.sort(),p&&p.sort(),this.isCustom&&this.optsTxt.sort()}if(e.sortNumDesc&&j.has(e.sortNumDesc,a))try{this.opts.sort(numSortDesc),p&&p.sort(numSortDesc),this.isCustom&&this.optsTxt.sort(numSortDesc)}catch(z){this.opts.sort(),p&&p.sort(),this.isCustom&&this.optsTxt.sort()}this.addChecks(a,h,e.separator),e.fillSlcOnDemand&&(g.innerHTML=""),g.appendChild(h),g.setAttribute("filled","1")}},writable:!0,configurable:!0},addChecks:{value:function(a,b){var c=this,d=this.tf,e=this.addTChecks(a,b),f=[],g=d.Cpt.store,h=g?g.getFilterValues(d.fltsValuesCookie)[a]:null;h&&k.trim(h).length>0&&(d.hasCustomSlcOptions&&j.has(d.customSlcOptions.cols,a)?f.push(h):f=h.split(" "+d.orOperator+" "));for(var l=0;l<this.opts.length;l++){var n=this.opts[l],o=this.isCustom?this.optsTxt[l]:n,p=i.createCheckItem(d.fltIds[a]+"_"+(l+e),n,o);p.className=this.checkListItemCssClass,d.refreshFilters&&d.disableExcludedOptions&&j.has(excludedOpts,k.matchCase(n,d.matchCase),d.matchCase)?(i.addClass(p,this.checkListItemDisabledCssClass),p.check.disabled=!0,p.disabled=!0):m.add(p.check,"click",function(a){c.optionClick(a)}),b.appendChild(p),""===n&&(p.style.display="none"),d.rememberGridValues&&(d.hasCustomSlcOptions&&j.has(d.customSlcOptions.cols,a)&&-1!=f.toString().indexOf(n)||j.has(f,k.matchCase(n,d.matchCase),d.matchCase))&&(p.check.checked=!0,this.setCheckListValues(p.check))}},writable:!0,configurable:!0},addTChecks:{value:function(a,b){var c=this,d=this.tf,e=1,f=i.createCheckItem(d.fltIds[a]+"_0","",d.displayAllText);if(f.className=this.checkListItemCssClass,b.appendChild(f),m.add(f.check,"click",function(a){c.optionClick(a)}),this.enableCheckListResetFilter||(f.style.display="none"),d.enableEmptyOption){var g=i.createCheckItem(d.fltIds[a]+"_1",d.emOperator,d.emptyText);g.className=this.checkListItemCssClass,b.appendChild(g),m.add(g.check,"click",function(a){c.optionClick(a)}),e++}if(d.enableNonEmptyOption){var h=i.createCheckItem(d.fltIds[a]+"_2",d.nmOperator,d.nonEmptyText);h.className=this.checkListItemCssClass,b.appendChild(h),m.add(h.check,"click",function(a){c.optionClick(a)}),e++}return e},writable:!0,configurable:!0},setCheckListValues:{value:function(a){if(a){for(var b=this.tf,c=a.value,d=parseInt(a.id.split("_")[2],10),e="ul",f="li",g=a;k.lower(g.nodeName)!==e;)g=g.parentNode;var h=g.childNodes[d],j=g.getAttribute("colIndex"),l=g.getAttribute("value"),m=g.getAttribute("indexes");if(a.checked){if(""===c){if(m&&""!==m)for(var n=m.split(b.separator),o=0;o<n.length;o++){var p=i.id(b.fltIds[j]+"_"+n[o]);p&&(p.checked=!1,i.removeClass(g.childNodes[n[o]],this.checkListSlcItemCssClass))}g.setAttribute("value",""),g.setAttribute("indexes","")}else l=l?l:"",c=k.trim(l+" "+c+" "+b.orOperator),d=m+d+b.separator,g.setAttribute("value",c),g.setAttribute("indexes",d),i.id(b.fltIds[j]+"_0")&&(i.id(b.fltIds[j]+"_0").checked=!1);k.lower(h.nodeName)===f&&(i.removeClass(g.childNodes[0],this.checkListSlcItemCssClass),i.addClass(h,this.checkListSlcItemCssClass))}else{if(""!==c){var q=new RegExp(k.rgxEsc(c+" "+b.orOperator));l=l.replace(q,""),g.setAttribute("value",k.trim(l));var r=new RegExp(k.rgxEsc(d+b.separator));m=m.replace(r,""),g.setAttribute("indexes",m)}k.lower(h.nodeName)===f&&i.removeClass(h,this.checkListSlcItemCssClass)}}},writable:!0,configurable:!0}}),a}()}Object.defineProperty(a,"__esModule",{value:!0})}),define("modules/rowsCounter",["exports","../dom","../types","../helpers"],function(a,b,c,d){{var e=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},f=function(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")},g=b.Dom,h=c.Types,i=d.Helpers;a.RowsCounter=function(){function a(b){f(this,a);var c=b.config();this.rowsCounterTgtId=c.rows_counter_target_id||null,this.rowsCounterDiv=null,this.rowsCounterSpa
}catch(e){}}var totRow=totRowIndex&&totRowIndex[ucol]?row[totRowIndex[ucol]]:null;totRow&&(totRow.style.display="")}this.onAfterOperation&&this.onAfterOperation.call(null,this.tf)}},writable:!0,configurable:!0}}),ColOps}();Object.defineProperty(exports,"__esModule",{value:!0})}),define("core",["exports","module","event","dom","string","cookie","types","array","helpers","date","sort","modules/store","modules/gridLayout","modules/loader","modules/highlightKeywords","modules/popupFilter","modules/dropdown","modules/checkList","modules/rowsCounter","modules/statusBar","modules/paging","modules/clearButton","modules/help","modules/alternateRows","modules/colOps"],function(a,b,c,d,e,f,g,h,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A){function B(a,b){if(a){b||(b="us");var c=a;return c="us"===H.lower(b)?+c.replace(/[^\d\.-]/g,""):+c.replace(/[^\d\,-]/g,"").replace(",",".")}}function C(){if(bb.body.__defineGetter__&&HTMLElement){var a=HTMLElement.prototype;a.__defineGetter__&&a.__defineGetter__("outerHTML",function(){var a=this.parentNode,b=G.create(a.tagName);b.appendChild(this);var c=b.innerHTML;return a.appendChild(this),c}),a.__defineSetter__&&HTMLElement.prototype.__defineSetter__("outerHTML",function(a){var b=this.ownerDocument.createRange();b.setStartBefore(this);var c=b.createContextualFragment(a);return this.parentNode.replaceChild(c,this),a})}}var D=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},E=function(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")},F=c.Event,G=d.Dom,H=e.Str,I=f.Cookie,J=g.Types,K=h.Arr,L=(k.Helpers,l.DateHelper),M=(m.Sort,n.Store),N=o.GridLayout,O=p.Loader,P=q.HighlightKeyword,Q=r.PopupFilter,R=s.Dropdown,S=t.CheckList,T=u.RowsCounter,U=v.StatusBar,V=w.Paging,W=x.ClearButton,X=y.Help,Y=z.AlternateRows,Z=A.ColOps,$=window,_=L.isValid,ab=L.format,bb=$.document,cb=function(){function a(b){if(E(this,a),0!==arguments.length){if(this.id=b,this.version="3.0",this.year=(new Date).getFullYear(),this.tbl=G.id(b),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.lower(this.tbl.nodeName)||0===this.getRowsNb())throw new Error("Could not instantiate TF object: HTML table not found.");if(arguments.length>1)for(var c=0;c<arguments.length;c++){var d=arguments[c],e=typeof d;switch(H.lower(e)){case"number":this.startRow=d;break;case"object":this.cfg=d}}var f=this.cfg;this.refRow=null===this.startRow?2:this.startRow+1;try{this.nbCells=this.getCellsNb(this.refRow)}catch(g){this.nbCells=this.getCellsNb(0)}this.basePath=void 0!==f.base_path?f.base_path:"",this.fltTypeInp="input",this.fltTypeSlc="select",this.fltTypeMulti="multiple",this.fltTypeCheckList="checklist",this.fltTypeNone="none",this.fltCol=[];for(var h=0;h<this.nbCells;h++){var i=f["col_"+h],j=i?H.lower(i):this.fltTypeInp;this.fltCol.push(j),this["col"+h]=j}this.publicMethods=void 0!==f.public_methods?f.public_methods:!1,this.fltGrid=f.grid===!1?!1:!0,this.gridLayout=f.grid_layout?!0:!1,this.sourceTblHtml=null,this.gridLayout&&(void 0===this.tbl.outerHTML&&C(),this.sourceTblHtml=this.tbl.outerHTML),this.filtersRowIndex=f.filters_row_index||0,this.headersRow=f.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"!==f.filters_cell_tag||"td"!==f.filters_cell_tag?"td":f.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=f.inf_div_css_class||"inf",this.lDivCssClass=f.left_div_css_class||"ldiv",this.rDivCssClass=f.right_div_css_class||"rdiv",this.mDivCssClass=f.middle_div_css_class||"mdiv",this.contDivCssClass=f.content_div_css_class||"cont",this.stylesheet=f.stylesheet||this.basePath+"filtergrid.css",this.stylesheetId=this.id+"
}}else{var i=c.on_before_selected_cell;c.on_before_selected_cell=function(){f(arguments[0],arguments[1],arguments[2]),i&&i.call(null,arguments[0],arguments[1],arguments[2])};var j=c.on_after_selected_cell;c.on_after_selected_cell=function(){e(arguments[0],arguments[1],arguments[2]),j&&j.call(null,arguments[0],arguments[1],arguments[2])}}}if(a.editable){var k=c.on_added_dom_row;if(c.on_added_dom_row=function(){a.nbFilterableRows++,a.paging?(a.nbRows++,a.nbVisibleRows++,a.nbFilterableRows++,a.paging=!1,a.Cpt.paging.destroy(),a.Cpt.paging.addPaging()):a.Cpt.rowsCounter.refresh(),a.alternateBgs&&a.Cpt.alternateRows.init(),k&&k.call(null,arguments[0],arguments[1],arguments[2])},c.actions&&c.actions["delete"]){var l=c.actions["delete"].on_after_submit;c.actions["delete"].on_after_submit=function(){a.nbFilterableRows--,a.paging?(a.nbRows--,a.nbVisibleRows--,a.nbFilterableRows--,a.paging=!1,a.Cpt.paging.destroy(),a.Cpt.paging.addPaging(!1)):a.Cpt.rowsCounter.refresh(),a.alternateBgs&&a.Cpt.alternateRows.init(),l&&l.call(null,arguments[0],arguments[1])}}}try{a.ezEditTable=new EditTable(a.id,c,b),a.ezEditTable.Init()}catch(m){console.log(c.err)}},writable:!0,configurable:!0},resetValues:{value:function(){this.EvtManager(this.Evt.name.resetvalues)},writable:!0,configurable:!0},_resetValues:{value:function(){this.rememberGridValues&&this.fillSlcOnDemand&&this.resetGridValues(this.fltsValuesCookie),this.rememberPageLen&&this.Cpt.paging.resetPageLength(this.pgLenCookie),this.rememberPageNb&&this.Cpt.paging.resetPage(this.pgNbCookie)},writable:!0,configurable:!0},resetGridValues:{value:function(a){if(this.fillSlcOnDemand){var b=this.Cpt.store.getFilterValues(a),c=this.getFiltersByType(this.fltTypeSlc,!0),d=this.getFiltersByType(this.fltTypeMulti,!0);if(Number(b[b.length-1])===this.fltIds.length){for(var e=0;e<b.length-1;e++)if(" "!==b[e]){var f,g;if(this["col"+e]===this.fltTypeSlc||this["col"+e]===this.fltTypeMulti){var h=G.id(this.fltIds[e]);if(h.options[0].selected=!1,K.has(c,e)&&(g=G.createOpt(b[e],b[e],!0),h.appendChild(g),this.hasStoredValues=!0),K.has(d,e))for(f=b[e].split(" "+this.orOperator+" "),j=0;j<f.length;j++)""!==f[j]&&(g=G.createOpt(f[j],f[j],!0),h.appendChild(g),this.hasStoredValues=!0)}else if(this["col"+e]==this.fltTypeCheckList){var i=this.Cpt.checkList,k=i.checkListDiv[e];k.title=k.innerHTML,k.innerHTML="";var l=G.create("ul",["id",this.fltIds[e]],["colIndex",e]);l.className=i.checkListCssClass;var m=G.createCheckItem(this.fltIds[e]+"_0","",this.displayAllText);for(m.className=i.checkListItemCssClass,l.appendChild(m),k.appendChild(l),f=b[e].split(" "+this.orOperator+" "),j=0;j<f.length;j++)if(""!==f[j]){var n=G.createCheckItem(this.fltIds[e]+"_"+(j+1),f[j],f[j]);n.className=i.checkListItemCssClass,l.appendChild(n),n.check.checked=!0,i.setCheckListValues(n.check),this.hasStoredValues=!0}}}!this.hasStoredValues&&this.paging&&this.Cpt.paging.setPagingInfo()}}},writable:!0,configurable:!0},filter:{value:function(){this.EvtManager(this.Evt.name.filter)},writable:!0,configurable:!0},_filter:{value:function(){function a(a,b,c){if(f.highlightKeywords&&b){a=a.replace(n,""),a=a.replace(o,""),a=a.replace(p,""),a=a.replace(q,"");var d=a;(i.test(a)||j.test(a)||k.test(a)||l.test(a)||m.test(a))&&(d=G.getText(c)),""!==d&&f.Cpt.highlightKeyword.highlight(c,d,f.Cpt.highlightKeyword.highlightCssClass)}}function b(a,b,c){var e,v,w,x=k.test(a),y=i.test(a),z=l.test(a),A=j.test(a),C=m.test(a),D=o.test(a),F=n.test(a),G=(r.test(a),p.test(a)),I=q.test(a),J=s===a,K=t===a,L=u.test(a),M=x&&_(a.replace(k,""),E),N=y&&_(a.replace(i,""),E),O=z&&_(a.replace(l,""),E),P=A&&_(a.replace(j,""),E),Q=C&&_(a.replace(m,""),E),R=D&&_(a.replace(o,""),E);if(_(b,E))v=ab(b,E),M?(w=ab(a.replace(k,""),E),e=w>v):N?(w=ab(a.replace(i,""),E),e=w>=v):P?(w=ab(a.replace(j,""),E),e=v>=w):O?(w=ab(a.replace(l,""),E),e=v>w):Q?(w=ab(a.replace(m,""),E),e=v.toString()!=w.toString()):R?(w=ab(a.replace(o,""),E),e=v.toString()==w.toString()):n.test(a)?e=f._containsStr(a.replace(n,""),b,null,!1):_(a,E)?(w=ab(a,E),e=v.toString()==w.toString()):J?e=H.isEmpty(b):K&&(e=!H.isEmpty(b));e