From 8e4c9d666672e415957ae8b99e7ab400342f8b98 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Mon, 5 Sep 2016 16:23:12 +0200 Subject: add click on autocomplete suport --- public/javascripts/bundle.js | 11 ++++++++++- public/javascripts/main.js | 11 ++++++++++- public/stylesheets/style.css | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) (limited to 'public') diff --git a/public/javascripts/bundle.js b/public/javascripts/bundle.js index b15380a..0b22d45 100644 --- a/public/javascripts/bundle.js +++ b/public/javascripts/bundle.js @@ -96837,7 +96837,9 @@ getUsers().then(function (users) { } }) - searchNode.addEventListener('submit', function (e) { + searchNode.addEventListener('submit', submitForm) + + function submitForm (e) { e.preventDefault() const indexInResult = selectedResult === -1 ? 0 : selectedResult const selectedUser = users[results[indexInResult].index] @@ -96848,6 +96850,13 @@ getUsers().then(function (users) { inputNode.blur() scheduleIframe.src = getURLOfUser(0, selectedUser.type, selectedUser.index + 1) + } + + autocompleteNode.addEventListener('click', function (e) { + if (e.target.tagName === 'LI' && e.target.parentElement === autocompleteNode) { + selectedResult = Array.prototype.indexOf.call(e.target.parentElement.childNodes, e.target) + submitForm({preventDefault: function () {}}) // HACK: this is horrible. + } }) }) diff --git a/public/javascripts/main.js b/public/javascripts/main.js index c492ace..f311e17 100644 --- a/public/javascripts/main.js +++ b/public/javascripts/main.js @@ -50,7 +50,9 @@ getUsers().then(function (users) { } }) - searchNode.addEventListener('submit', function (e) { + searchNode.addEventListener('submit', submitForm) + + function submitForm (e) { e.preventDefault() const indexInResult = selectedResult === -1 ? 0 : selectedResult const selectedUser = users[results[indexInResult].index] @@ -61,6 +63,13 @@ getUsers().then(function (users) { inputNode.blur() scheduleIframe.src = getURLOfUser(0, selectedUser.type, selectedUser.index + 1) + } + + autocompleteNode.addEventListener('click', function (e) { + if (e.target.tagName === 'LI' && e.target.parentElement === autocompleteNode) { + selectedResult = Array.prototype.indexOf.call(e.target.parentElement.childNodes, e.target) + submitForm({preventDefault: function () {}}) // HACK: this is horrible. + } }) }) diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index fa76e4d..432b4e1 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -53,6 +53,11 @@ html, body { color: #FFCDD2; } +li:hover { + background-color: lightgray; + cursor: pointer; +} + .selected { background-color: lightgray; } -- cgit v1.1