forked from straps/jquery-livefilter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.livefilter.min.js
1 lines (1 loc) · 1.35 KB
/
jquery.livefilter.min.js
1
(function(a){a.fn.livefilter=function(c,d){typeof c=="undefined"&&(c="init"),typeof c=="object"&&(d=c,c="init"),c==="init"?(d=a.extend({},a.fn.livefilter.defaults,d),a(this).data("lf-data",d),a(this).unbind(".livefilter").bind("keyup.livefilter",a.fn.livefilter.onKey(d))):c==="destroy"?(d=a(this).data("lf-data"),a(d.selector).filter("."+d.hiddenClass)[d.showFn](),a(this).unbind(".livefilter")):b("action unknown",c);return a(this)},a.fn.livefilter.onKey=function(c){var d=function(){var d=a(this).val();b("filtering",d),d?a(c.selector).filter(":icontains("+d+")")[c.showFn]().removeClass(c.hiddenClass).end().filter(":not(:icontains("+d+"))")[c.hideFn]().addClass(c.hiddenClass):a(c.selector).removeClass(c.hiddenClass)[c.showFn]()};c.debounce&&(b("debounce active",c.debounce),d=a.fn.livefilter.debounce(d,c.debounce));return d},a.fn.livefilter.debounce=function(a,b){var c;return function(){function f(){a.apply(d,e),c=null}var d=this,e=arguments;c&&clearTimeout(c),c=setTimeout(f,b||100)}},a.expr[":"].icontains=function(a,b,c,d){return(a.textContent||a.innerText||jQuery(a).text()||"").toLowerCase().indexOf(c[3].toLowerCase())>=0};var b=function(){typeof console!="undefined"&&console.log&&console.log(Array.prototype.slice.call(arguments).join(", "))};a.fn.livefilter.defaults={selector:"tbody tr",debounce:500,hiddenClass:"lf-hidden",showFn:"show",hideFn:"hide"}})(jQuery)