mirror of
https://codeberg.org/nobody/LocalCDN.git
synced 2024-12-25 09:40:38 +01:00
13 lines
4.4 KiB
JavaScript
13 lines
4.4 KiB
JavaScript
/*! Jets.js - v0.14.1 - 2018-06-22
|
|
* http://NeXTs.github.com/Jets.js/
|
|
* Copyright (c) 2015 Denis Lukov; Licensed MIT */
|
|
|
|
;(function(d,c){"undefined"!=typeof module?module.exports=c():"function"==typeof define&&"object"==typeof define.amd?define(c):d.Jets=c()})(this,function(){function d(c){if(!(this instanceof d))return new d(c);var a=this,b={searchSelector:"*AND",hideBy:"display:none",diacriticsMap:{}};a.options={};"columns addImportant searchSelector hideBy manualContentHandling callSearchManually searchInSpecificColumn diacriticsMap didSearch invert".split(" ").forEach(function(f){a.options[f]=c[f]||b[f]});if(1<this.options.searchSelector.length){var g=
|
|
a.options.searchSelector.trim();a.options.searchSelector=g.substr(0,1);a.options.searchSelectorMode=g.substr(1).toUpperCase()}a.content_tag=document.querySelectorAll(c.contentTag);if(!a.content_tag)throw Error("Error! Could not find contentTag element");a.content_param=c.contentTag;a.search_tag=document.querySelector(c.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(b,c){e!=(e=a.options.callSearchManually&&"undefined"!=typeof b?b:a.search_tag?a.search_tag.value:"")&&(0,a._applyCSS(e,c),a.options.didSearch&&a.options.didSearch(e))};a._onSearch=function(b){if("keydown"==b.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)}d.prototype={constructor:d,_processEventListeners:function(c){["input","keydown","change"].forEach(function(a){this.search_tag[c+"EventListener"](a,this._onSearch)}.bind(this))},_applyCSS:function(c,a){for(var b=this.options,g=this.replaceDiacritics(c.trim().toLowerCase().replace(/\s\s+/g," ")).replace(/\\/g,"\\\\"),e=b.searchSelectorMode?g.split(" ").filter(function(a,b,c){return c.indexOf(a)==b}):[g],f="AND"==b.searchSelectorMode,h=Array(e.length),d=0,k=e.length;d<k;d++)h[d]=(f?this.content_param+
|
|
">":"")+(b.invert?"":":not(")+"[data-jets"+("undefined"!=typeof a?"-col-"+a:"")+b.searchSelector+'="'+e[d]+'"]'+(b.invert?"":")");e=b.hideBy.split(";").filter(Boolean).map(function(a){return a+(b.addImportant?"!important":"")});f=(f?"":this.content_param+">")+h.join(f?",":"")+"{"+e.join(";")+"}";this.styleTag.innerHTML=g.length?f:""},_addStyleTag:function(){this.styleTag=document.createElement("style");document.head.appendChild(this.styleTag)},_getText:function(c){return c&&(c.textContent||c.innerText)||
|
|
""},_sanitize:function(c){return this.replaceDiacritics(c).trim().replace(/\s+/g," ").toLowerCase()},_getContentTags:function(c){return Array.prototype.slice.call(this.content_tag).reduce(function(a,b){return a.concat(Array.prototype.slice.call(b.querySelectorAll(c||":scope > *")))},[])},_handleSpecificColumns:function(c,a){var b=this;b.options.searchInSpecificColumn&&Array.prototype.slice.call(c.children).map(function(g,e){if(!b.options.columns||!b.options.columns.length||-1!=b.options.columns.indexOf(e))c[(a||
|
|
"remove")+"Attribute"]("data-jets-col-"+e,a&&b._sanitize(b._getText(g)))})},_setJets:function(c,a){for(var b=this,g=b._getContentTags(a?"":c),e,f=0,d;d=g[f];f++)if(!d.hasAttribute("data-jets")||a)e=this.options.manualContentHandling?this.options.manualContentHandling(d):b.options.columns&&b.options.columns.length?b.options.columns.map(function(a){return b._getText(d.children[a])}).join(" "):b._getText(d),d.setAttribute("data-jets",b._sanitize(e)),b._handleSpecificColumns(d,"set")},replaceDiacritics:function(c){var a=
|
|
this.options.diacriticsMap,b;for(b in a)if(a.hasOwnProperty(b))for(var d=0,e=a[b].length;d<e;d++)c=c.replace(new RegExp(a[b][d],"g"),b);return c},update:function(c){this._setJets(":scope > :not([data-jets])",c)},_destroy:function(){this.styleTag.parentNode&&document.head.removeChild(this.styleTag);for(var c=this._getContentTags(),a=0,b;b=c[a];a++)b.removeAttribute("data-jets"),this._handleSpecificColumns(b)}};(function(c,a){try{c.querySelector(":scope body")}catch(b){["querySelector","querySelectorAll"].forEach(function(b){var d=
|
|
a[b];a[b]=function(a){if(/(^|,)\s*:scope/.test(a)){var e=this.getAttribute("id");this.id="ID_"+Date.now();a=a.replace(/((^|,)\s*):scope/g,"$1#"+this.getAttribute("id"));a=c[b](a);this.id=e;return a}return d.call(this,a)}})}})(window.document,Element.prototype);return d}); |