-
Notifications
You must be signed in to change notification settings - Fork 3
/
search.min.js
1 lines (1 loc) · 6.34 KB
/
search.min.js
1
!function(){var m={},y=null,f={EXPIRE_KEY:"docsify.search.expires",INDEX_KEY:"docsify.search.index"};function g(e){var n={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};return String(e).replace(/[&<>"'/]/g,function(e){return n[e]})}function v(e,n){if(Object.hasOwnProperty.bind(e)(n))return e[n];for(var t in e)if(Object.hasOwnProperty.bind(e)(t)){var i=v(e[t],n);if(i)return i}return null}function o(o,r){var e,n,t="auto"===o.paths,s=(e=o.namespace)?f.EXPIRE_KEY+"/"+e:f.EXPIRE_KEY,c=(n=o.namespace)?f.INDEX_KEY+"/"+n:f.INDEX_KEY,i=localStorage.getItem(s)<Date.now();if(m=JSON.parse(localStorage.getItem(c)),i)m={};else if(!t)return;var a,d,l=t?(a=r.router,d=[],Docsify.dom.findAll(".sidebar-nav a:not(.section-link):not([data-nosearch])").forEach(function(e){var n=e.href,t=e.getAttribute("href"),i=a.parse(n).path;i&&-1===d.indexOf(i)&&!Docsify.util.isAbsolutePath(t)&&d.push(i)}),d):o.paths,h=l.length,p=0;l.forEach(function(a){if(m[a])return p++;Docsify.get(r.router.getFile(a),!1,r.config.requestHeaders).then(function(e){var n,t,i;m[a]=function(n,e,t,i){void 0===e&&(e="");var a,o=window.marked.lexer(e),r=window.Docsify.slugify,s={};return o.forEach(function(e){if("heading"===e.type&&e.depth<=i)a=t.toURL(n,{id:r(e.text)}),s[a]={slug:a,title:e.text,body:""};else{if(!a)return;s[a]?s[a].body?s[a].body+="\n"+(e.text||""):s[a].body=e.text:s[a]={slug:a,title:"",body:""}}}),r.clear(),s}(a,e,r.router,o.depth),h===++p&&(n=o.maxAge,t=s,i=c,localStorage.setItem(t,Date.now()+n),localStorage.setItem(i,JSON.stringify(m)))})})}var c,d="";function s(e){var n=Docsify.dom.find("div.search"),t=Docsify.dom.find(n,".results-panel"),i=Docsify.dom.find(n,".clear-button"),a=Docsify.dom.find(".sidebar-nav"),o=Docsify.dom.find(".app-name");if(!e)return t.classList.remove("show"),i.classList.remove("show"),t.innerHTML="",void(c.hideOtherSidebarContent&&(a.classList.remove("hide"),o.classList.remove("hide")));var r=function(e){null==y&&(y=lunr(function(){for(var e in this.field("title",{boost:3}),this.field("body"),this.ref("slug"),this.metadataWhitelist=["position"],m)for(var n in m[e])this.add(m[e][n])}));var n=[],t=y.search(e);for(var i in t){var a,o,r=t[i],s=r.ref,c=s.split("?")[0].replace("#",""),d=m[c][s],l=null==(o=v(r.matchData,"body"))?null:o.position[0][0],h=0;(h=0==(a=l<21?0:l-20)?150:l+e.length+150)>(o=void 0===d.body?"":d.body).length&&(h=o.length);var p="...";if(""!=o){var f=new RegExp("("+e+")","ig");p+=g(o.substring(a,h)).replace(f,'<em class="search-keyword">$1</em>')+"..."}var u={title:g(d.title),content:p,url:s};n.push(u)}return n}(e),s="";r.forEach(function(e){s+='<div class="matching-post">\n<a href="'+e.url+'">\n<h2>'+e.title+"</h2>\n<p>"+e.content+"</p>\n</a>\n</div>"}),t.classList.add("show"),i.classList.add("show"),t.innerHTML=s||'<p class="empty">'+d+"</p>",c.hideOtherSidebarContent&&(a.classList.add("hide"),o.classList.add("hide"))}function l(e){c=e}function r(e,n){var t,i,a,o,r=n.router.parse().query.s;l(e),Docsify.dom.style("\n.sidebar {\n padding-top: 0;\n}\n\n.search {\n margin-bottom: 20px;\n padding: 6px;\n border-bottom: 1px solid #eee;\n}\n\n.search .input-wrap {\n display: flex;\n align-items: center;\n}\n\n.search .results-panel {\n display: none;\n}\n\n.search .results-panel.show {\n display: block;\n}\n\n.search input {\n outline: none;\n border: none;\n width: 100%;\n padding: 0 7px;\n line-height: 36px;\n font-size: 14px;\n}\n\n.search input::-webkit-search-decoration,\n.search input::-webkit-search-cancel-button,\n.search input {\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n}\n.search .clear-button {\n width: 36px;\n text-align: right;\n display: none;\n}\n\n.search .clear-button.show {\n display: block;\n}\n\n.search .clear-button svg {\n transform: scale(.5);\n}\n\n.search h2 {\n font-size: 17px;\n margin: 10px 0;\n}\n\n.search a {\n text-decoration: none;\n color: inherit;\n}\n\n.search .matching-post {\n border-bottom: 1px solid #eee;\n}\n\n.search .matching-post:last-child {\n border-bottom: 0;\n}\n\n.search p {\n font-size: 14px;\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 5;\n -webkit-box-orient: vertical;\n}\n\n.search p.empty {\n text-align: center;\n}\n\n.app-name.hide, .sidebar-nav.hide {\n display: none;\n}"),function(e){void 0===e&&(e="");var n='<div class="input-wrap">\n <input type="search" value="'+e+'" />\n <div class="clear-button">\n <svg width="26" height="24">\n <circle cx="12" cy="12" r="11" fill="#ccc" />\n <path stroke="white" stroke-width="2" d="M8.25,8.25,15.75,15.75" />\n <path stroke="white" stroke-width="2"d="M8.25,15.75,15.75,8.25" />\n </svg>\n </div>\n </div>\n <div class="results-panel"></div>\n </div>',t=Docsify.dom.create("div",n),i=Docsify.dom.find("aside");Docsify.dom.toggleClass(t,"search"),Docsify.dom.before(i,t)}(r),i=Docsify.dom.find("div.search"),a=Docsify.dom.find(i,"input"),o=Docsify.dom.find(i,".input-wrap"),Docsify.dom.on(i,"click",function(e){return"A"!==e.target.tagName&&e.stopPropagation()}),Docsify.dom.on(a,"input",function(n){clearTimeout(t),t=setTimeout(function(e){return s(n.target.value.trim())},100)}),Docsify.dom.on(o,"click",function(e){"INPUT"!==e.target.tagName&&(a.value="",s())}),r&&setTimeout(function(e){return s(r)},500)}function h(e,n){l(e),function(e,n){var t=Docsify.dom.getNode('.search input[type="search"]');if(t)if("string"==typeof e)t.placeholder=e;else{var i=Object.keys(e).filter(function(e){return-1<n.indexOf(e)})[0];t.placeholder=e[i]}}(e.placeholder,n.route.path),function(e,n){if("string"==typeof e)d=e;else{var t=Object.keys(e).filter(function(e){return-1<n.indexOf(e)})[0];d=e[t]}}(e.noData,n.route.path)}var p={placeholder:"Type to search",noData:"No Results!",paths:"auto",depth:2,maxAge:864e5,hideOtherSidebarContent:!1,namespace:void 0};$docsify.plugins=[].concat(function(e,n){var t=Docsify.util,i=n.config.search||p;Array.isArray(i)?p.paths=i:"object"==typeof i&&(p.paths=Array.isArray(i.paths)?i.paths:"auto",p.maxAge=t.isPrimitive(i.maxAge)?i.maxAge:p.maxAge,p.placeholder=i.placeholder||p.placeholder,p.noData=i.noData||p.noData,p.depth=i.depth||p.depth,p.hideOtherSidebarContent=i.hideOtherSidebarContent||p.hideOtherSidebarContent,p.namespace=i.namespace||p.namespace);var a="auto"===p.paths;e.mounted(function(e){r(p,n),!a&&o(p,n)}),e.doneEach(function(e){h(p,n),a&&o(p,n)})},$docsify.plugins)}();