-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.dataAttrSearch.min.js
1 lines (1 loc) · 3.23 KB
/
jquery.dataAttrSearch.min.js
1
(function(c){"function"!==typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});c.fn.dataAttrSearch=function(k,l,m,n){function f(b){if(""==b)return c("[data-"+g+"]").show(),c(".searchStatus").hide(),!1;var a=p;b=b.match(/\w+/g);var h={},e=[],d,a=a.split(",");for(d=0;d<a.length;d++)h[a[d].trim()]=!0;for(d=0;d<b.length;d++)a=b[d].trim().toLowerCase(),h[a]||e.push(a);var f=0;c("[data-"+g+"]").each(function(){var a=c(this).attr("data-"+g).replace("-"," ").replace(/[^a-zA-Z ]/g,"").split(" ");$self=c(this);console.log(a);for(var b=!1,d=0;d<e.length;d++)for(var h=RegExp("\\b"+e[d].replace(/\\/g,"\\\\"),"gi"),j=0;j<a.length;j++)h.test(a[j])&&(b=!0);!0==b?($self.show(),f++):$self.hide()});c(".resultCount").text(f);c(".searchStatus").show()}function q(b){var a=c('<button class="dataSearchButton">Search</button>');a.click(function(){f(b.val())});return a}function r(b){var a=c('<button class="dataClearButton">Clear Search</button>');a.click(function(){b.val("");c("[data-"+g+"]").show();c(".searchStatus").hide()});return a}var e,p="the, it is, we, all, a, an, by, to, you, me, he, do, she, they, we, how, it, i, are, to, for, of",g=k.replace("data-","");this.each(function(){var b=c(this);b.wrap("<div/>");var a=b.parent();!0==l&&a.append(q(b));!0==m&&a.append(r(b));!0==n&&a.append('<p style="display:none" class="searchStatus">Search Returned <span class="resultCount"></span> out of '+c("[data-"+g+"]").length+"</p>");b.on("keyup",function(){var a=c(this);window.clearTimeout(e);e=window.setTimeout(function(){f(a.val())},100)});b.on("blur",function(){var a=c(this);window.clearTimeout(e);e=window.setTimeout(function(){f(a.val())},100)})});return this}})(jQuery);(function(c){c.fn.dataAttrSearch=function(k,l,m,n){function f(b){if(""==b)return c("[data-"+g+"]").show(),c(".searchStatus").hide(),!1;var a=p;b=b.match(/\w+/g);var h={},e=[],d,a=a.split(",");for(d=0;d<a.length;d++)h[a[d].trim()]=!0;for(d=0;d<b.length;d++)a=b[d].trim().toLowerCase(),h[a]||e.push(a);var f=0;c("[data-"+g+"]").each(function(){for(var a=c(this).attr("data-"+g).replace("-"," ").replace(/[^a-zA-Z ]/g,"").split(" "),b=!1,d=0;d<e.length;d++)for(var h=RegExp("\\b"+e[d].replace(/\\/g,"\\\\"),"gi"),j=0;j<a.length;j++)h.test(a[j])&&(b=!0);!0==b?(c(this).show(),f++):c(this).hide()});c(".resultCount").text(f);c(".searchStatus").show()}function q(b){var a=c('<button class="dataSearchButton">Search</button>');a.click(function(){f(b.val())});return a}function r(b){var a=c('<button class="dataClearButton">Clear Search</button>');a.click(function(){b.val("");c("[data-"+g+"]").show();c(".searchStatus").hide()});return a}var e,p="the, it is, we, all, a, an, by, to, you, me, he, do, she, they, we, how, it, i, are, to, for, of",g=k?k.replace("data-",""):"tags";this.each(function(){var b=c(this);b.wrap("<div/>");var a=b.parent();!0==l&&a.append(q(b));!0==m&&a.append(r(b));!0==n&&a.append('<p style="display:none" class="searchStatus">Search Returned <span class="resultCount"></span> out of '+c("[data-"+g+"]").length+"</p>");b.on("keyup",function(){var a=c(this);window.clearTimeout(e);e=window.setTimeout(function(){f(a.val())},100)});b.on("blur",function(){var a=c(this);window.clearTimeout(e);e=window.setTimeout(function(){f(a.val())},100)})});return this}})(jQuery);