aboutsummaryrefslogtreecommitdiff
path: root/public/javascripts/search.js
blob: fb40f784257be93e679821ce15c75fc8e701de2d (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
25
26
27
28
29
30
31
32
const autocomplete = require('./autocomplete')
const iframe = require('./iframe')

const self = {}

self._nodes = {
  search: document.querySelector('#search'),
  input: document.querySelector('input[type="search"]')
}

self.submit = function () {
  self._nodes.input.blur()

  const selectedItem = autocomplete.getSelectedItem()
  console.log(selectedItem)
  iframe.viewItem(0, selectedItem)
}

self._handleSubmit = function (event) {
  event.preventDefault()
  self.submit()
}

autocomplete.events.on('select', self.submit)

self._nodes.search.addEventListener('submit', self._handleSubmit)
self._nodes.input.addEventListener('focus', autocomplete.show)

// TODO: hide on escape key press
// self._nodes.input.addEventListener('blur', autocomplete.hide)

module.exports = self