diff options
author | Noah Loomans <noahloomans@gmail.com> | 2016-12-14 12:29:57 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2016-12-14 12:29:57 +0100 |
commit | 900366c6d623fde54223f93930d28a84264cbb46 (patch) | |
tree | aaef626b0a86fc0856c7e9be098c9db5c6584ff4 /public/javascripts/search.js | |
parent | e3f1a6a2c3534c3133f412f1b86f7398f3b4f40c (diff) |
handle search focus
Diffstat (limited to 'public/javascripts/search.js')
-rw-r--r-- | public/javascripts/search.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/public/javascripts/search.js b/public/javascripts/search.js index f0f905f..d1a49e2 100644 --- a/public/javascripts/search.js +++ b/public/javascripts/search.js @@ -53,9 +53,26 @@ self._handleTextUpdate = function () { } } +self._handleFocus = function () { + self._nodes.input.select() +} + +self._handleBlur = function () { + // this will removed the selection without drawing focus on it (safari) + // this will removed selection even when focusing an iframe (chrome) + const oldValue = self._nodes.value + self._nodes.value = '' + self._nodes.value = oldValue + + // this will hide the keyboard (iOS safari) + document.activeElement.blur() +} + autocomplete.on('select', self.submit) self._nodes.search.addEventListener('submit', self._handleSubmit) +self._nodes.input.addEventListener('focus', self._handleFocus) +self._nodes.input.addEventListener('blur', self._handleBlur) self._nodes.input.addEventListener('input', self._handleTextUpdate) module.exports = self |