From f457053d85756784242f6f0cfe6caf288018a010 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sat, 13 Jan 2018 09:07:18 +0100 Subject: [PATCH] Use the fact that we handle oninput in whisper() --- editor/include/adminer.inc.php | 6 ++++- editor/static/editing.js | 48 ++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index 2fbaf36a..ac250194 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -461,7 +461,11 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5 if ($options !== null) { return (is_array($options) ? "" . optionlist($options, $value, true) . "" - : "" + : "" + . "" + . "
" + . script("qsl('input').oninput = partial(whisper, '" . ME . "script=complete&source=" . urlencode($table) . "&field=" . urlencode($field["field"]) . "&value='); +qsl('div').onclick = whisperClick;", "") ); } if (like_bool($field)) { diff --git a/editor/static/editing.js b/editor/static/editing.js index 2de3212d..ac876475 100644 --- a/editor/static/editing.js +++ b/editor/static/editing.js @@ -11,7 +11,34 @@ function helpMouseover() { function helpMouseout() { } -function whisperClick(event, field) { +/** Display typeahead +* @param string +* @this HTMLInputElement +*/ +function whisper(url) { + var field = this; + field.orig = field.value; + field.previousSibling.value = field.value; // accept number, reject string + return ajax(url + encodeURIComponent(field.value), function (xmlhttp) { + if (xmlhttp.status && field.orig == field.value) { // ignore old responses + field.nextSibling.innerHTML = xmlhttp.responseText; + field.nextSibling.style.display = ''; + var a = field.nextSibling.firstChild; + if (a && a.firstChild.data == field.value) { + field.previousSibling.value = decodeURIComponent(a.href.replace(/.*=/, '')); + a.className = 'active'; + } + } + }); +} + +/** Select typeahead value +* @param MouseEvent +* @return boolean false for success +* @this HTMLDivElement +*/ +function whisperClick(event) { + var field = this.previousSibling; var el = getTarget(event); if (isTag(el, 'a') && !(event.button || event.shiftKey || event.altKey || isCtrl(event))) { field.value = el.firstChild.data; @@ -21,25 +48,6 @@ function whisperClick(event, field) { } } -function whisper(url) { - var field = this; - if (field.orig != field.value) { // ignore arrows, Shift, ... - field.orig = field.value; - field.previousSibling.value = field.value; // accept number, reject string - return ajax(url + encodeURIComponent(field.value), function (xmlhttp) { - if (xmlhttp.status && field.orig == field.value) { // ignore old responses - field.nextSibling.innerHTML = xmlhttp.responseText; - field.nextSibling.style.display = ''; - var a = field.nextSibling.firstChild; - if (a && a.firstChild.data == field.value) { - field.previousSibling.value = decodeURIComponent(a.href.replace(/.*=/, '')); - a.className = 'active'; - } - } - }); - } -} - /** Add new attachment field * @this HTMLInputElement */