]> git.joonet.de Git - adminer.git/commitdiff
Use the fact that we handle oninput in whisper()
authorJakub Vrana <jakub@vrana.cz>
Sat, 13 Jan 2018 08:07:18 +0000 (09:07 +0100)
committerJakub Vrana <jakub@vrana.cz>
Sat, 13 Jan 2018 08:07:35 +0000 (09:07 +0100)
editor/include/adminer.inc.php
editor/static/editing.js

index 2fbaf36a95df1c7ab6150d88754e9735a483e4ec..ac2501941ef7edf062b20aa3ed69e3f4d8a40718 100644 (file)
@@ -461,7 +461,11 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
                if ($options !== null) {
                        return (is_array($options)
                                ? "<select$attrs>" . optionlist($options, $value, true) . "</select>"
-                               :  "<input value='" . h($value) . "'$attrs class='hidden'><input value='" . h($options) . "' class='jsonly' oninput=\"whisper.call(this, '" . h(ME . "script=complete&source=" . urlencode($table) . "&field=" . urlencode($field["field"])) . "&value=');\"><div onclick='return whisperClick(event, this.previousSibling);'></div>"
+                               :  "<input value='" . h($value) . "'$attrs class='hidden'>"
+                                       . "<input value='" . h($options) . "' class='jsonly'>"
+                                       . "<div></div>"
+                                       . 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)) {
index 2de3212d834c5c72266d3b54675a63be1b77f937..ac8764755312df42db0c84b527c5f5b93d57fac6 100644 (file)
@@ -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
 */