This commit is contained in:
Mahdi Dibaiee
2015-07-26 14:27:33 +04:30
parent 10fd1038fc
commit c459136de8
11 changed files with 28 additions and 6 deletions

View File

@ -20,22 +20,24 @@ for (let category in data) {
const input = document.querySelector('input');
const results = document.querySelector('#results');
input.addEventListener('keyup', e => {
input.addEventListener('keydown', e => {
// Tab Key
if (e.keyCode === 9) {
e.preventDefault();
const current = trie.find(input.value);
if (!current) return;
if (!current.children.length) return;
input.value = current.children[0].name;
}
});
input.addEventListener('keyup', () => {
results.innerHTML = '';
const nodes = trie.findWords(input.value);
if (!nodes) return;
if (!nodes.length) return;
for (let node of nodes) {
const category = node.category ? `- ${node.category}` : '';

3
src/libs/browser-polyfill.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -39,6 +39,7 @@ class Trie {
findWords(value, parent = this.root) {
let top = this.find(value, parent);
if (!top) return [];
let words = [];