-
Notifications
You must be signed in to change notification settings - Fork 12
/
instafilta.min.js
9 lines (9 loc) · 3.41 KB
/
instafilta.min.js
1
2
3
4
5
6
7
8
9
/*!
* instaFilta
* Version: 1.4.4
* Description: jQuery plugin for performing in-page filtering
* Homepage and documentation: https://github.com/chromawoods/instaFilta
* Author: Andreas Larsson <[email protected]> (http://chromawoods.com)
* Contributions: Jaap-Jan Frans
*/
!function(t){t.fn.instaFilta=function(e){var i=null,s=null,a=t.extend({scope:null,targets:".instafilta-target",sections:".instafilta-section",categoryDataAttr:"instafilta-category",matchCssClass:"instafilta-match",itemsHideEffect:"hide",itemsHideDuration:0,itemsShowEffect:"show",itemsShowDuration:0,sectionsHideEffect:"hide",sectionsHideDuration:0,sectionsShowEffect:"show",sectionsShowDuration:0,onFilterComplete:null,markMatches:!1,hideEmptySections:!0,beginsWith:!1,caseSensitive:!1,typeDelay:0,useSynonyms:!0,synonyms:[{src:"à,á,å,ä,â,ã",dst:"a"},{src:"À,Á,Å,Ä,Â,Ã",dst:"A"},{src:"è,é,ë,ê",dst:"e"},{src:"È,É,Ë,Ê",dst:"E"},{src:"ì,í,ï,î",dst:"i"},{src:"Ì,Í,Ï,Î",dst:"I"},{src:"ò,ó,ö,ô,õ",dst:"o"},{src:"Ò,Ó,Ö,Ô,Õ",dst:"O"},{src:"ù,ú,ü,û",dst:"u"},{src:"Ù,Ú,Ü,Û",dst:"U"},{src:"ç",dst:"c"},{src:"Ç",dst:"C"},{src:"æ",dst:"ae"}]},e);if(a.useSynonyms)for(var n=0,r=a.synonyms.length;r>n;n++)a.synonyms[n].src=a.synonyms[n].src.split(",");return this.each(function(){var e,n,r,o,c="";a.scope?(o=t(this).closest(a.scope),n=o.find(a.targets),r=o.find(a.sections)):(n=t(a.targets),r=t(a.sections)),n.each(function(){$target=t(this),original=$target.text(),$target.data("values",function(t){var e=[original],i=original;if(!a.useSynonyms)return e;for(var s=0,n=t.length;n>s;s++)for(var r=0;r<t[s].src.length;r++)i=i.replace(t[s].src[r],t[s].dst);return!(i!==original)||e.push(i),e}(a.synonyms))});var l=function(){r.each(function(){var e=t(this);e.find('[data-instafilta-hide="false"]').length?e[a.sectionsShowEffect](a.sectionsShowDuration):e[a.sectionsHideEffect](a.sectionsHideDuration)})},f=function(t){var e=function(){return t?n.attr("data-instafilta-hide","false"):n}().filter('[data-instafilta-hide="false"]')[a.itemsShowEffect](a.itemsShowDuration);return t||n.filter('[data-instafilta-hide="true"]')[a.itemsHideEffect](a.itemsHideDuration),a.hideEmptySections&&l(),"function"==typeof a.onFilterComplete&&a.onFilterComplete.apply(this,[e]),e},u=function(){return f(!0)};i=function(e){return e=a.caseSensitive?e:e.toLowerCase(),c===e?!1:(c=e,e||u(),n.each(function(){var i=t(this);i.data("originalText")||(i.data("originalHtml",i.html()),i.data("originalText",i.data("values")[0]));var s=function(t,e){for(var i=-1,s=0;s<t.length&&(i=(a.caseSensitive?t[s]:t[s].toLowerCase()).indexOf(e),!(i>=0));s++);return i}(i.data("values"),e),n=i.data("originalText"),r=(a.caseSensitive?n:n.toLowerCase(),null),o=null;s>=0&&a.markMatches&&(r=n.substring(s,s+e.length),o=n.replace(r,'<span class="'+a.matchCssClass+'">'+r+"</span>"),i.html(i.data("originalHtml").replace(n,o))),i.attr("data-instafilta-hide",a.beginsWith&&0!==s||0>s?"true":"false")}),f())},s=function(e,i){return e&&e.length?("string"==typeof e&&(e=e.split(",")),n.each(function(){var s=!0,n=0,r=t(this),o=r.data(a.categoryDataAttr);if(o){o=o.split(",");for(var c=0;c<o.length;c++)for(var l=0;l<e.length;l++)if(o[c]===e[l]){if(!i){s=!1;break}n++}i&&n===e.length&&(s=!1),r.html(r.data("originalText")).attr("data-instafilta-hide",s)}}),f()):u()},t(this).on("keyup",function(){var s=t(this);clearTimeout(e),e=setTimeout(function(){i(s.val())},a.typeDelay)})}),{filterTerm:i,filterCategory:s}}}(jQuery);