mirror of
https://github.com/osmarks/website
synced 2025-06-23 16:54:11 +00:00
improve search overlay
This commit is contained in:
parent
b7fe83cb58
commit
7fa23b042a
24
src/page.js
24
src/page.js
@ -661,10 +661,10 @@ const closeOverlay = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this is actually now labelled properly as the search button
|
// this is actually now labelled properly as the search button
|
||||||
const loginButton = document.querySelector("nav a:last-of-type")
|
const searchButton = document.querySelector("nav a:last-of-type")
|
||||||
loginButton.href = "#"
|
searchButton.href = "#"
|
||||||
loginButton.innerText = "Search"
|
searchButton.innerText = "Search"
|
||||||
loginButton.onclick = async ev => {
|
searchButton.onclick = async ev => {
|
||||||
ev.preventDefault()
|
ev.preventDefault()
|
||||||
const query = (await import("/assets/js/fts_client.js")).default
|
const query = (await import("/assets/js/fts_client.js")).default
|
||||||
const overlay = document.createElement("div")
|
const overlay = document.createElement("div")
|
||||||
@ -675,13 +675,18 @@ loginButton.onclick = async ev => {
|
|||||||
input.type = "text"
|
input.type = "text"
|
||||||
input.placeholder = "Search"
|
input.placeholder = "Search"
|
||||||
let resultsEl
|
let resultsEl
|
||||||
|
let topResult
|
||||||
input.oninput = () => {
|
input.oninput = () => {
|
||||||
if (resultsEl) {
|
if (resultsEl) {
|
||||||
resultsEl.remove()
|
resultsEl.remove()
|
||||||
}
|
}
|
||||||
resultsEl = document.createElement("div")
|
resultsEl = document.createElement("div")
|
||||||
resultsEl.classList.add("search-results")
|
resultsEl.classList.add("search-results")
|
||||||
for (const result of query(input.value)) {
|
const results = query(input.value)
|
||||||
|
if (results.length > 0) {
|
||||||
|
topResult = results[0].url
|
||||||
|
}
|
||||||
|
for (const result of results) {
|
||||||
const item = e("search-result", resultsEl)
|
const item = e("search-result", resultsEl)
|
||||||
const titleLine = nameMappings[result.sourceType] + " / " + (result.title ?? result.timestamp)
|
const titleLine = nameMappings[result.sourceType] + " / " + (result.title ?? result.timestamp)
|
||||||
const link = e("search-result-link", item, titleLine, "a")
|
const link = e("search-result-link", item, titleLine, "a")
|
||||||
@ -702,6 +707,12 @@ loginButton.onclick = async ev => {
|
|||||||
if (input.value === "") {
|
if (input.value === "") {
|
||||||
// quit search mode
|
// quit search mode
|
||||||
closeOverlay()
|
closeOverlay()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ev.key === "Enter") {
|
||||||
|
if (topResult) {
|
||||||
|
window.location.href = topResult
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -713,6 +724,9 @@ window.addEventListener("keydown", ev => {
|
|||||||
if (ev.key === "Escape") {
|
if (ev.key === "Escape") {
|
||||||
closeOverlay()
|
closeOverlay()
|
||||||
}
|
}
|
||||||
|
if (ev.key === "/" && ev.ctrlKey) {
|
||||||
|
searchButton.click()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const citeButton = document.getElementById("citebutton")
|
const citeButton = document.getElementById("citebutton")
|
||||||
|
@ -10,6 +10,7 @@ $navbar-width: 20rem
|
|||||||
--autocol-lightness: 65%
|
--autocol-lightness: 65%
|
||||||
--autocol-saturation: 85%
|
--autocol-saturation: 85%
|
||||||
--autocol-border: 0%
|
--autocol-border: 0%
|
||||||
|
--block-lightness: 85%
|
||||||
|
|
||||||
@font-face
|
@font-face
|
||||||
font-family: 'osmarks-primary'
|
font-family: 'osmarks-primary'
|
||||||
@ -249,7 +250,7 @@ blockquote
|
|||||||
overflow-x: scroll
|
overflow-x: scroll
|
||||||
|
|
||||||
.footnote-item.hl1, .footnote-item.hl2, .footnote-item.hl3
|
.footnote-item.hl1, .footnote-item.hl2, .footnote-item.hl3
|
||||||
background: hsl(0, 0%, var(--autocol-lightness))
|
background: hsl(0, 0%, var(--block-lightness))
|
||||||
padding: 0.5em
|
padding: 0.5em
|
||||||
box-sizing: border-box
|
box-sizing: border-box
|
||||||
list-style-type: none
|
list-style-type: none
|
||||||
@ -318,6 +319,7 @@ $hl-border: 3px
|
|||||||
--autocol-lightness: 10%
|
--autocol-lightness: 10%
|
||||||
--autocol-saturation: 50%
|
--autocol-saturation: 50%
|
||||||
--autocol-border: 35%
|
--autocol-border: 35%
|
||||||
|
--block-lightness: 10%
|
||||||
|
|
||||||
nav .logocont
|
nav .logocont
|
||||||
color: white
|
color: white
|
||||||
@ -401,6 +403,7 @@ table
|
|||||||
bottom: 0
|
bottom: 0
|
||||||
right: 0
|
right: 0
|
||||||
background: rgba(0, 0, 0, 0.9)
|
background: rgba(0, 0, 0, 0.9)
|
||||||
|
backdrop-filter: blur(10px)
|
||||||
padding: 2em
|
padding: 2em
|
||||||
color: white
|
color: white
|
||||||
z-index: 1000
|
z-index: 1000
|
||||||
|
Loading…
x
Reference in New Issue
Block a user