vufindtutorialde/docsify/search.min.js

2 lines
6.3 KiB
JavaScript
Raw Normal View History

2019-12-03 01:17:26 +01:00
!function(){var f={},u={EXPIRE_KEY:"docsify.search.expires",INDEX_KEY:"docsify.search.index"};function h(e){var n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};return String(e).replace(/[&<>"'/]/g,function(e){return n[e]})}function o(o,r){var e,n,t="auto"===o.paths,s=(e=o.namespace)?u.EXPIRE_KEY+"/"+e:u.EXPIRE_KEY,c=(n=o.namespace)?u.INDEX_KEY+"/"+n:u.INDEX_KEY,a=localStorage.getItem(s)<Date.now();if(f=JSON.parse(localStorage.getItem(c)),a)f={};else if(!t)return;var i,d,l=t?(i=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"),a=i.parse(n).path;a&&-1===d.indexOf(a)&&!Docsify.util.isAbsolutePath(t)&&d.push(a)}),d):o.paths,h=l.length,p=0;l.forEach(function(i){if(f[i])return p++;Docsify.get(r.router.getFile(i),!1,r.config.requestHeaders).then(function(e){var n,t,a;f[i]=function(n,e,t,a){void 0===e&&(e="");var i,o=window.marked.lexer(e),r=window.Docsify.slugify,s={};return o.forEach(function(e){if("heading"===e.type&&e.depth<=a)i=t.toURL(n,{id:r(e.text)}),s[i]={slug:i,title:e.text,body:""};else{if(!i)return;s[i]?s[i].body?s[i].body+="\n"+(e.text||""):s[i].body=e.text:s[i]={slug:i,title:"",body:""}}}),r.clear(),s}(i,e,r.router,o.depth),h===++p&&(n=o.maxAge,t=s,a=c,localStorage.setItem(t,Date.now()+n),localStorage.setItem(a,JSON.stringify(f)))})})}var c,d="";function s(e){var n=Docsify.dom.find("div.search"),t=Docsify.dom.find(n,".results-panel"),a=Docsify.dom.find(n,".clear-button"),i=Docsify.dom.find(".sidebar-nav"),o=Docsify.dom.find(".app-name");if(!e)return t.classList.remove("show"),a.classList.remove("show"),t.innerHTML="",void(c.hideOtherSidebarContent&&(i.classList.remove("hide"),o.classList.remove("hide")));var r=function(e){var i=[],o=[];Object.keys(f).forEach(function(n){o=o.concat(Object.keys(f[n]).map(function(e){return f[n][e]}))});var r=(e=e.trim()).split(/[\s\-\\/]+/);1!==r.length&&(r=[].concat(e,r));for(var n=function(e){var n=o[e],s=0,c="",d=n.title&&n.title.trim(),l=n.body&&n.body.trim(),t=n.slug||"";if(d&&(r.forEach(function(e){var n,t=new RegExp(e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&"),"gi"),a=-1;if(n=d?d.search(t):-1,a=l?l.search(t):-1,0<=n||0<=a){s+=0<=n?3:0<=a?2:0,a<0&&(a=0);var i,o=0;(o=0==(i=a<11?0:a-10)?70:a+e.length+60)>l.length&&(o=l.length);var r="..."+h(l).substring(i,o).replace(t,'<em class="search-keyword">'+e+"</em>")+"...";c+=r}}),0<s)){var a={title:h(d),content:l?c:"",url:t,score:s};i.push(a)}},t=0;t<o.length;t++)n(t);return i.sort(function(e,n){return n.score-e.score})}(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"),a.classList.add("show"),t.innerHTML=s||'<p class="empty">'+d+"</p>",c.hideOtherSidebarContent&&(i.classList.add("hide"),o.classList.add("hide"))}function l(e){c=e}function r(e,n){var t,a,i,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 overf