Block serach bar untill index is loaded

This commit is contained in:
Alex Shpak 2019-07-17 14:43:30 +02:00
parent a3f7d8b948
commit f56f2bf04d
7 changed files with 14 additions and 13 deletions

View File

@ -139,18 +139,17 @@ ul.pagination {
.book-search { .book-search {
#book-search-input { #book-search-input {
opacity: .33;
border: 0; border: 0;
border-bottom: $padding-1 solid $body-font-color; border-bottom: $padding-1 solid $body-font-color;
outline: none; outline: none;
padding: $padding-4 $padding-8 $padding-4 $padding-16 + $padding-4; padding: $padding-4 $padding-4 $padding-4 $padding-16 + $padding-4;
width: 85%; width: 100%;
background: url("svg/search.svg") left center no-repeat; background: url("svg/search.svg") left center no-repeat;
background-size: $padding-16; background-size: $padding-16;
opacity: 0.33;
&:focus { &:focus {
opacity: 1; opacity: 1;
} }
@ -161,7 +160,6 @@ ul.pagination {
} }
} }
.book-toc { .book-toc {
flex: 0 0 $toc-width; flex: 0 0 $toc-width;
font-size: $font-size-12; font-size: $font-size-12;

View File

@ -10,7 +10,10 @@
function init() { function init() {
loadScript("{{ "lunr.min.js" | relURL }}") loadScript("{{ "lunr.min.js" | relURL }}")
loadScript("{{ $searchData.RelPermalink }}", search); loadScript("{{ $searchData.RelPermalink }}", function() {
input.readOnly = false;
search();
});
input.removeEventListener("focus", init); input.removeEventListener("focus", init);
} }

View File

@ -1,5 +1,5 @@
(function(){const input=document.querySelector("#book-search-input");const results=document.querySelector("#book-search-results");const dummy=document.querySelector("#book-search-dummy");input.addEventListener("focus",init);input.addEventListener("keyup",search);function init(){loadScript("/example/lunr.min.js") (function(){const input=document.querySelector("#book-search-input");const results=document.querySelector("#book-search-results");const dummy=document.querySelector("#book-search-dummy");input.addEventListener("focus",init);input.addEventListener("keyup",search);function init(){loadScript("/example/lunr.min.js")
loadScript("/example/search-data.min.34183091f91a205581bbdcc247f638b72d22f51e34ab573b24519f95c4a92895.js",search);input.removeEventListener("focus",init);} loadScript("/example/search-data.min.34183091f91a205581bbdcc247f638b72d22f51e34ab573b24519f95c4a92895.js",function(){input.readOnly=false;search();});input.removeEventListener("focus",init);}
function search(){while(results.firstChild){results.removeChild(results.firstChild);} function search(){while(results.firstChild){results.removeChild(results.firstChild);}
if(!input.value||!window.bookSearch){return} if(!input.value||!window.bookSearch){return}
const terms=lunr.tokenizer(input.value);const searchHits=window.bookSearch.idx.query(function(query){query.term(terms,{boost:100,});query.term(terms,{boost:10,wildcard:lunr.Query.wildcard.LEADING|lunr.Query.wildcard.TRAILING,});query.term(terms,{editDistance:2});});searchHits.slice(0,10).forEach(function(hit){const page=window.bookSearch.pages[hit.ref];const li=dummy.querySelector("li").cloneNode(true),a=li.querySelector("a");a.href=page.href;a.textContent=page.title;results.appendChild(li);});} const terms=lunr.tokenizer(input.value);const searchHits=window.bookSearch.idx.query(function(query){query.term(terms,{boost:100,});query.term(terms,{boost:10,wildcard:lunr.Query.wildcard.LEADING|lunr.Query.wildcard.TRAILING,});query.term(terms,{editDistance:2});});searchHits.slice(0,10).forEach(function(hit){const page=window.bookSearch.pages[hit.ref];const li=dummy.querySelector("li").cloneNode(true),a=li.querySelector("a");a.href=page.href;a.textContent=page.title;results.appendChild(li);});}

View File

@ -1 +1 @@
{"Target":"search.min.1f579a6bfcf647662ed7d1c6328560f89ac36825f447b8babab6da52f23738a7.js","MediaType":"application/javascript","Data":{"Integrity":"sha256-H1eaa/z2R2Yu19HGMoVg+JrDaCX0R7i6urbaUvI3OKc="}} {"Target":"search.min.be0d747115d15ef35d8cd20b07815450b1c3d2b84c58ba4a9f35dfff3f786384.js","MediaType":"application/javascript","Data":{"Integrity":"sha256-vg10cRXRXvNdjNILB4FUULHD0rhMWLpKnzXf/z94Y4Q="}}

View File

@ -1 +1 @@
{"Target":"book.min.d957ded8b0d85eeacfd42502592de956866a48868f317cb69b9776c15309f870.css","MediaType":"text/css","Data":{"Integrity":"sha256-2Vfe2LDYXurP1CUCWS3pVoZqSIaPMXy2m5d2wVMJ+HA="}} {"Target":"book.min.466789b48a1b0e04075f086ad9e175ac3c489b1c9f7848181949c5c634222648.css","MediaType":"text/css","Data":{"Integrity":"sha256-RmeJtIobDgQHXwhq2eF1rDxImxyfeEgYGUnFxjQiJkg="}}

View File

@ -1,9 +1,9 @@
{{ if default true .Site.Params.BookSearch }} {{ if default true .Site.Params.BookSearch }}
<div class="book-search"> <div class="book-search">
<ul id="book-search-dummy" class="hidden"> <ul id="book-search-dummy" class="hidden">
<li><a href></a></li> <li><a href></a></li><!-- used to clone search result -->
</ul> </ul>
<input type="text" placeholder="Search" id="book-search-input" /> <input type="text" placeholder="Search" id="book-search-input" maxlength="64" readonly />
<ul id="book-search-results"></ul> <ul id="book-search-results"></ul>
</div> </div>
{{ end }} {{ end }}