| 1 |
<form> |
| 2 |
<input id="lunr-search" name="q" placeholder="🔎 Search ..." aria-label="Search" |
| 3 |
disabled minlength="2"> |
| 4 |
</form> |
| 5 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/tingle/0.15.3/tingle.min.css" integrity="sha512-j1u8eUJ4f23xPPxwOrLUPQaCD2dwzNqqmDDcWS4deWsMv2ohLqmXXuP3hU7g8TyzbMSakP/mMqoNBYWj8AEIFg==" crossorigin> |
| 6 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/tingle/0.15.3/tingle.min.js" integrity="sha512-plGUER9JkeEWPPqQBE4sdLqBoQug5Ap+BCGMc7bJ8BXkm+VVj6QzkpBz5Yv2yPkkq+cqg9IpkBaGCas6uDbW8g==" crossorigin></script> |
| 7 |
<style> |
| 8 |
.modal-dialog iframe { |
| 9 |
width: 100vw; |
| 10 |
height: calc(100vh - 80px); |
| 11 |
} |
| 12 |
@media screen and (min-width: 700px) { |
| 13 |
.modal-dialog iframe { |
| 14 |
width: 70vw; |
| 15 |
height: 80vh; |
| 16 |
} |
| 17 |
} |
| 18 |
.modal-dialog .tingle-modal-box {width: auto;} |
| 19 |
.modal-dialog .tingle-modal-box__content {padding: 0;} |
| 20 |
</style> |
| 21 |
<script> |
| 22 |
const input = document.getElementById('lunr-search'); |
| 23 |
input.disabled = false; |
| 24 |
|
| 25 |
input.form.addEventListener('submit', (ev) => { |
| 26 |
ev.preventDefault(); |
| 27 |
const url = new URL(window.location); |
| 28 |
url.searchParams.set('q', input.value); |
| 29 |
history.replaceState({}, null, url.toString()); |
| 30 |
search(input.value); |
| 31 |
}); |
| 32 |
|
| 33 |
## On page load |
| 34 |
const query = new URL(window.location).searchParams.get('q'); |
| 35 |
if (query) |
| 36 |
search(query); |
| 37 |
|
| 38 |
function search(query) { |
| 39 |
const url = '${'../' * module.url().count('/')}doc-search.html#' + encodeURIComponent(query); |
| 40 |
new tingle.modal({ |
| 41 |
cssClass: ['modal-dialog'], |
| 42 |
onClose: () => { |
| 43 |
const url = new URL(window.location); |
| 44 |
url.searchParams.delete('q'); |
| 45 |
history.replaceState({}, null, url.toString()); |
| 46 |
setTimeout(() => input.focus(), 100); |
| 47 |
} |
| 48 |
}).setContent('<iframe src="' + url + '"></iframe>').open(); |
| 49 |
} |
| 50 |
</script> |