-
Notifications
You must be signed in to change notification settings - Fork 108
/
jets.min.js
14 lines (13 loc) · 4.55 KB
/
jets.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
Jets.js - v0.15.0 - 2022-12-11
http://NeXTs.github.com/Jets.js/
Copyright (c) 2015 Denis Lukov; Licensed MIT */
;(function(h,b){"undefined"!=typeof module?module.exports=b():"function"==typeof define&&"object"==typeof define.amd?define(b):h.Jets=b()})(this,function(){function h(b){if(!(this instanceof h))return new h(b);var a=this,c={searchSelector:"*AND",hideBy:"display:none",diacriticsMap:{}};a.options={};"columns addImportant searchSelector hideBy manualContentHandling callSearchManually searchInSpecificColumn diacriticsMap didSearch invert nonceId".split(" ").forEach(function(d){a.options[d]=b[d]||c[d]});
if(1<this.options.searchSelector.length){var f=a.options.searchSelector.trim();a.options.searchSelector=f.substr(0,1);a.options.searchSelectorMode=f.substr(1).toUpperCase()}a.content_tag=document.querySelectorAll(b.contentTag);if(!a.content_tag)throw Error("Error! Could not find contentTag element");a.content_param=b.contentTag;a.search_tag=document.querySelector(b.searchTag);if(!a.search_tag&&!a.options.callSearchManually)throw Error('Error! Provide one of search methods: searchTag or callSearchManually and call .search("phrase") manually');
var e=a.search_tag&&a.search_tag.value||"";a.search=function(d,g){e!=(e=a.options.callSearchManually&&"undefined"!=typeof d?d:a.search_tag?a.search_tag.value:"")&&(0,a._applyCSS(e,g),a.options.didSearch&&a.options.didSearch(e))};a._onSearch=function(d){if("keydown"==d.type)return setTimeout(a.search,0);a.search()};a.destroy=function(){a.options.callSearchManually||a._processEventListeners("remove");a._destroy()};a.options.callSearchManually||a._processEventListeners("add");a._addStyleTag();a._setJets();
a._applyCSS(e)}h.prototype={constructor:h,_processEventListeners:function(b){["input","keydown","change"].forEach(function(a){this.search_tag[b+"EventListener"](a,this._onSearch)}.bind(this))},_applyCSS:function(b,a){for(var c=this.options,f=this.replaceDiacritics(b.trim().toLowerCase().replace(/\s\s+/g," ")).replace(/\\/g,"\\\\"),e=c.searchSelectorMode?f.split(" ").filter(function(l,m,n){return n.indexOf(l)==m}):[f],d="AND"==c.searchSelectorMode,g=Array(e.length),k=0,p=e.length;k<p;k++)g[k]=(d?this.content_param+
">":"")+(c.invert?"":":not(")+"[data-jets"+("undefined"!=typeof a?"-col-"+a:"")+c.searchSelector+'="'+e[k]+'"]'+(c.invert?"":")");e=c.hideBy.split(";").filter(Boolean).map(function(l){return l+(c.addImportant?"!important":"")});d=(d?"":this.content_param+">")+g.join(d?",":"")+"{"+e.join(";")+"}";this.styleTag.innerHTML=f.length?d:""},_addStyleTag:function(){var b=this.options;this.styleTag=document.createElement("style");"undefined"!=typeof b.nonceId&&this.styleTag.setAttribute("nonce",b.nonceId);
document.head.appendChild(this.styleTag)},_getText:function(b){return b&&(b.textContent||b.innerText)||""},_sanitize:function(b){return this.replaceDiacritics(b).trim().replace(/\s+/g," ").toLowerCase()},_getContentTags:function(b){return Array.prototype.slice.call(this.content_tag).reduce(function(a,c){return a.concat(Array.prototype.slice.call(c.querySelectorAll(b||":scope > *")))},[])},_handleSpecificColumns:function(b,a){var c=this;c.options.searchInSpecificColumn&&Array.prototype.slice.call(b.children).map(function(f,
e){if(!c.options.columns||!c.options.columns.length||-1!=c.options.columns.indexOf(e))b[(a||"remove")+"Attribute"]("data-jets-col-"+e,a&&c._sanitize(c._getText(f)))})},_setJets:function(b,a){for(var c=this,f=c._getContentTags(a?"":b),e,d=0,g;g=f[d];d++)if(!g.hasAttribute("data-jets")||a)e=this.options.manualContentHandling?this.options.manualContentHandling(g):c.options.columns&&c.options.columns.length?c.options.columns.map(function(k){return c._getText(g.children[k])}).join(" "):c._getText(g),g.setAttribute("data-jets",
c._sanitize(e)),c._handleSpecificColumns(g,"set")},replaceDiacritics:function(b){var a=this.options.diacriticsMap,c;for(c in a)if(a.hasOwnProperty(c))for(var f=0,e=a[c].length;f<e;f++)b=b.replace(new RegExp(a[c][f],"g"),c);return b},update:function(b){this._setJets(":scope > :not([data-jets])",b)},_destroy:function(){this.styleTag.parentNode&&document.head.removeChild(this.styleTag);for(var b=this._getContentTags(),a=0,c;c=b[a];a++)c.removeAttribute("data-jets"),this._handleSpecificColumns(c)}};(function(b,
a){try{b.querySelector(":scope body")}catch(c){["querySelector","querySelectorAll"].forEach(function(f){var e=a[f];a[f]=function(d){if(/(^|,)\s*:scope/.test(d)){var g=this.getAttribute("id");this.id="ID_"+Date.now();d=d.replace(/((^|,)\s*):scope/g,"$1#"+this.getAttribute("id"));d=b[f](d);this.id=g;return d}return e.call(this,d)}})}})(window.document,Element.prototype);return h});