Skip to content

Commit

Permalink
feat: remember the search engine
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Sep 16, 2023
1 parent fdeb5d0 commit a3f3129
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions assets/hb/modules/theme-start/js/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
return
}

// focus the input on page loaded.
input?.focus()
const remember = (id: string): void => {
localStorage.setItem('engine', id)
}

const activeEngine = (engine: HTMLElement): void => {
engines.forEach((el) => {
Expand All @@ -19,6 +20,7 @@
engine.classList.add('active')
toggle.innerHTML = engine.querySelector('svg')?.outerHTML
const engineID = engine.getAttribute('data-id')
remember(engineID)
document.querySelectorAll('.hb-start-search-result-types').forEach((el) => {
if (el.getAttribute('data-engine') !== engineID) {
el.classList.add('d-none')
Expand Down Expand Up @@ -76,6 +78,18 @@
setResultTypeInput(item)
}

// focus the input on page loaded.
input?.focus()

// load the last engine.
const engineID = localStorage.getItem('engine')
if (engineID !== null) {
const engine = document.querySelector<HTMLElement>(`.hb-start-search-engine[data-id="${engineID}"]`)
if (engine !== null) {
activeEngine(engine)
}
}

engines.forEach((el) => {
el.addEventListener('click', () => {
activeEngine(el)
Expand Down

0 comments on commit a3f3129

Please sign in to comment.