diff options
author | BuildTools <Noah Loomans> | 2016-12-08 22:43:21 +0100 |
---|---|---|
committer | BuildTools <Noah Loomans> | 2016-12-08 22:43:21 +0100 |
commit | 5c7fed6eda250d91d4babd14da73166425fab85b (patch) | |
tree | 3a108428592dbd72a92294e19469d8c1b77a29e3 /public/javascripts/autocomplete.js | |
parent | c547e6910ea7ad077771343ae75a4204223a118a (diff) |
moved function from autocomplete to search
Diffstat (limited to 'public/javascripts/autocomplete.js')
-rw-r--r-- | public/javascripts/autocomplete.js | 29 |
1 files changed, 2 insertions, 27 deletions
diff --git a/public/javascripts/autocomplete.js b/public/javascripts/autocomplete.js index 681dba8..f7bd046 100644 --- a/public/javascripts/autocomplete.js +++ b/public/javascripts/autocomplete.js @@ -1,8 +1,4 @@ -/* global USERS */ - -const fuzzy = require('fuzzy') const EventEmitter = require('events') -const process = require('process') const self = {} self._items = [] @@ -42,7 +38,7 @@ self.hide = function () { self._nodes.autocomplete.style.display = 'none' } -self._removeAllItems = function () { +self.removeAllItems = function () { while (self._nodes.autocomplete.firstChild) { self._nodes.autocomplete.removeChild(self._nodes.autocomplete.firstChild) } @@ -50,7 +46,7 @@ self._removeAllItems = function () { self._selectedItemIndex = -1 } -self._addItem = function (item) { +self.addItem = function (item) { const listItem = document.createElement('li') listItem.textContent = item.value self._nodes.autocomplete.appendChild(listItem) @@ -75,17 +71,6 @@ self._moveSelected = function (shift) { } } -self._calculate = function (searchTerm) { - const allResults = fuzzy.filter(searchTerm, USERS, { - extract: item => item.value - }) - const firstResults = allResults.slice(0, 7) - - const originalResults = firstResults.map(result => result.original) - - return originalResults -} - self._handleItemClick = function (event) { if (!self._nodes.autocomplete.contains(event.target)) return const itemIndex = Array.prototype.indexOf @@ -94,15 +79,6 @@ self._handleItemClick = function (event) { self.events.emit('select', self.getSelectedItem()) } -self._handleTextUpdate = function () { - const results = self._calculate(self._nodes.input.value) - - self._removeAllItems() - for (let i = 0; i < results.length; i++) { - self._addItem(results[i]) - } -} - self._handleKeydown = function (event) { if (event.key === 'ArrowDown' || event.key === 'ArrowUp') { event.preventDefault() @@ -115,7 +91,6 @@ self._handleKeydown = function (event) { } self._nodes.autocomplete.addEventListener('click', self._handleItemClick) -self._nodes.input.addEventListener('input', self._handleTextUpdate) self._nodes.input.addEventListener('keydown', self._handleKeydown) module.exports = self |