Welcome to mirror list, hosted at ThFree Co, Russian Federation.

search.js « js « src - github.com/g1eny0ung/hugo-theme-dream.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ce5d2b45477a40ca9cf479f401b0e291556f2749 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let searchVisible = false

function toggleSearch() {
  if (searchVisible) {
    $('#dream-search').css('display', '')
  } else {
    $('#dream-search').css('display', 'block')
    setTimeout(() => $('#dream-search input').focus())
  }

  searchVisible = !searchVisible
}

$(document).ready(() => {
  $(document).on('keydown', (e) => {
    if (e.metaKey && e.key === '/' && !searchVisible) {
      toggleSearch()
    }

    if (e.key === 'Escape' && searchVisible) {
      toggleSearch()
    }
  })
})