tablesorter/dist/js/extras/jquery.quicksearch.min.js

1 line
2.1 KiB
JavaScript

!function(a,b){a.fn.quicksearch=function(c,d){var e,f,g,h,i="",j=this,k=a.extend({delay:100,selector:null,stripeRows:null,loader:null,noResults:"",childRow:"tablesorter-childRow",matchedResultsCount:0,bind:"keyup",onBefore:function(){},onAfter:function(){},show:function(){this.style.display=""},hide:function(){this.style.display="none"},prepareQuery:function(a){return a.toLowerCase().split(" ")},testQuery:function(a,b){for(var c=0;c<a.length;c+=1)if(-1===b.indexOf(a[c]))return!1;return!0}},d);return this.go=function(){var b,c=0,d=0,e=!0,h=k.prepareQuery(i),j=0===i.replace(" ","").length;for(c=0,b=g.length;b>c;c++)j||k.testQuery(h,f[c],g[c])||a(g[c]).hasClass(k.childRow)&&a(g[c>1?c-1:0]).is(":visible")?(k.show.apply(g[c]),e=!1,d++):k.hide.apply(g[c]);return e?this.results(!1):(this.results(!0),this.stripe()),this.matchedResultsCount=d,this.loader(!1),k.onAfter(),this},this.search=function(a){i=a,j.trigger()},this.currentMatchedResults=function(){return this.matchedResultsCount},this.stripe=function(){if("object"==typeof k.stripeRows&&null!==k.stripeRows){var b=k.stripeRows.join(" "),c=k.stripeRows.length;h.not(":hidden").each(function(d){a(this).removeClass(b).addClass(k.stripeRows[d%c])})}return this},this.strip_html=function(b){var c=b.replace(new RegExp("<[^<]+>","g"),"");return c=a.trim(c.toLowerCase())},this.results=function(b){return"string"==typeof k.noResults&&""!==k.noResults&&(b?a(k.noResults).hide():a(k.noResults).show()),this},this.loader=function(b){return"string"==typeof k.loader&&""!==k.loader&&(b?a(k.loader).show():a(k.loader).hide()),this},this.cache=function(){h=a(c),"string"==typeof k.noResults&&""!==k.noResults&&(h=h.not(k.noResults));var b="string"==typeof k.selector?h.find(k.selector):a(c).not(k.noResults);return f=b.map(function(){return j.strip_html(this.innerHTML)}),g=h.map(function(){return this}),i=i||this.val()||"",this.go()},this.trigger=function(){return this.loader(!0),k.onBefore(),b.clearTimeout(e),e=b.setTimeout(function(){j.go()},k.delay),this},this.cache(),this.results(!0),this.stripe(),this.loader(!1),this.each(function(){a(this).on(k.bind,function(){i=a(this).val(),j.trigger()})})}}(jQuery,this,document);