-
Notifications
You must be signed in to change notification settings - Fork 1
/
liveFilter.min.js
1 lines (1 loc) · 1.09 KB
/
liveFilter.min.js
1
$.fn.liveFilter=function(e,t,n){var r=this;r[0].placeholder="Filter...";var i=false;var s;r.focus(function(){function u(r){if(i)return;var s=r.getAttribute("data-previous-value");if(r.value==s||r.value=="!")return;var u="";if(r.value.length>s.length){if(r.value.indexOf(s)>-1){u=":visible"}}else{if(s.indexOf(r.value)>-1){u=":hidden"}}r.setAttribute("data-previous-value",r.value);var a=r.value.toString().toUpperCase();if(a.indexOf("!")>-1)u="";var f=a.match(/\S+/g)||[];var l=$();var c=$();var h=$(e+u);h.each(function(){var e=0;for(var n=0;n<f.length;n++){var r=true;$(this).find(t).each(function(){var t=this.innerText||this.textContent;t=t.toUpperCase();if(f[n][0]==="!"){var i=f[n].substr(1);if(i.length==0){return false}if(t.indexOf(i)!=-1){r=false;return false}}else{r=false;if(t.indexOf(f[n])!=-1){e++;return false}}});if(r)e++}if(e==f.length){c=c.add(this)}else{l=l.add(this)}});c.show();l.hide();if(o)n()}$(this).unbind("focus");this.setAttribute("data-previous-value","");var o=$.isFunction(n);r.bind("input",function(){clearTimeout(s);i=true;var e=this;s=setTimeout(function(){i=false;u(e)},350)})})};