From 644c355d947b559fdbd31dd6be5589cecf13f0c6 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sun, 17 Oct 2010 07:16:32 +0200 Subject: [PATCH] Send the form by Ctrl+Enter in all textareas --- adminer/database.inc.php | 2 +- adminer/dump.inc.php | 2 +- adminer/include/editing.inc.php | 2 +- adminer/include/functions.inc.php | 2 +- adminer/select.inc.php | 2 +- adminer/static/editing.js | 24 ---------------------- adminer/static/functions.js | 33 ++++++++++++++++++++++++++++++- changes.txt | 1 + editor/include/adminer.inc.php | 2 +- 9 files changed, 39 insertions(+), 31 deletions(-) diff --git a/adminer/database.inc.php b/adminer/database.inc.php index f3399dee..eb9f6ac3 100644 --- a/adminer/database.inc.php +++ b/adminer/database.inc.php @@ -57,7 +57,7 @@ if ($_POST) {

' . h($name) . '
' + ? '
' : '' ) . "\n" . ($collations ? html_select("collation", array("" => "(" . lang('collation') . ")") + $collations, $collate) : ""); ?> diff --git a/adminer/dump.inc.php b/adminer/dump.inc.php index 8004b719..b813f87a 100644 --- a/adminer/dump.inc.php +++ b/adminer/dump.inc.php @@ -214,7 +214,7 @@ if (DB != "") { } } } else { - echo ""; + echo ""; } } ?> diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index 38bc423f..cf4ba18b 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -104,7 +104,7 @@ function referencable_primary($self) { * @return null */ function textarea($name, $value, $rows = 10, $cols = 80) { - echo ""; // spellcheck - not valid before HTML5 + echo ""; // spellcheck - not valid before HTML5 } /** Print table columns for type edit diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index ea81a1c9..88e51ad2 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -599,7 +599,7 @@ function input($field, $value, $function) { } elseif (ereg('blob|bytea|raw|file', $field["type"]) && ini_bool("file_uploads")) { echo ""; } elseif (ereg('text|lob', $field["type"])) { - echo "'; // 1.2em - line-height + echo "'; // 1.2em - line-height } else { // int(3) is only a display hint $maxlength = (!ereg('int', $field["type"]) && preg_match('~^([0-9]+)(,([0-9]+))?$~', $field["length"], $match) ? ((ereg("binary", $field["type"]) ? 2 : 1) * $match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0)); diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 363ef22a..0c174503 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -339,7 +339,7 @@ if (!$columns) { $editable = is_utf8($val) && !$long && $rows[$n][$key] == $row[$key] && !$functions[$key]; $text = ereg('text|lob', $field["type"]); echo (($_GET["modify"] && $editable) || isset($value) - ? "" . ($text ? "" : "") + ? "" . ($text ? "" : "") : "" . $adminer->selectVal($val, $link, $field) ); } diff --git a/adminer/static/editing.js b/adminer/static/editing.js index c1585b67..99c10569 100644 --- a/adminer/static/editing.js +++ b/adminer/static/editing.js @@ -408,27 +408,3 @@ function schemaMouseup(ev) { cookie('adminer_schema=' + encodeURIComponent(s.substr(1)), 30, '; path="' + location.pathname + location.search + '"'); } } - -/** Handle Tab and Ctrl+Enter in textarea -* @param HTMLTextAreaElement -* @param KeyboardEvent -* @return boolean -*/ -function textareaKeydown(target, event) { - if (event.keyCode == 9 && !event.shiftKey && !event.altKey && !event.ctrlKey && !event.metaKey) { - // inspired by http://pallieter.org/Projects/insertTab/ - if (target.setSelectionRange) { - var start = target.selectionStart; - target.value = target.value.substr(0, start) + '\t' + target.value.substr(target.selectionEnd); - target.setSelectionRange(start + 1, start + 1); - return false; //! still loses focus in Opera, can be solved by handling onblur - } else if (target.createTextRange) { - document.selection.createRange().text = '\t'; - return false; - } - } - if (event.ctrlKey && (event.keyCode == 13 || event.keyCode == 10) && !event.altKey && !event.metaKey) { // shiftKey allowed - target.form.submit(); - } - return true; -} diff --git a/adminer/static/functions.js b/adminer/static/functions.js index f610ab8d..ca4332a5 100644 --- a/adminer/static/functions.js +++ b/adminer/static/functions.js @@ -123,7 +123,35 @@ function selectAddRow(field) { - +/** Handle Ctrl+Enter and optionally Tab in textarea +* @param HTMLTextAreaElement +* @param KeyboardEvent +* @param boolean handle also Tab +* @param HTMLInputElement submit button +* @return boolean +*/ +function textareaKeydown(target, event, tab, button) { + if (tab && event.keyCode == 9 && !event.shiftKey && !event.altKey && !event.ctrlKey && !event.metaKey) { + // inspired by http://pallieter.org/Projects/insertTab/ + if (target.setSelectionRange) { + var start = target.selectionStart; + target.value = target.value.substr(0, start) + '\t' + target.value.substr(target.selectionEnd); + target.setSelectionRange(start + 1, start + 1); + return false; //! still loses focus in Opera, can be solved by handling onblur + } else if (target.createTextRange) { + document.selection.createRange().text = '\t'; + return false; + } + } + if (event.ctrlKey && (event.keyCode == 13 || event.keyCode == 10) && !event.altKey && !event.metaKey) { // shiftKey allowed + if (button) { + button.click(); + } else { + target.form.submit(); + } + } + return true; +} /** Display edit field * @param HTMLElement @@ -143,6 +171,9 @@ function selectDblClick(td, event, text) { rows++; }); input.rows = rows; + input.onkeydown = function (event) { + return textareaKeydown(input, event || window.event); + }; } if (document.selection) { var range = document.selection.createRange(); diff --git a/changes.txt b/changes.txt index 3e7f1369..716b9d2e 100644 --- a/changes.txt +++ b/changes.txt @@ -1,4 +1,5 @@ Adminer 3.0.1-dev: +Send the form by Ctrl+Enter in all textareas Catalan translation Adminer 3.0.0 (released 2010-10-15): diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index 8c8d990d..e7c74760 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -265,7 +265,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5 echo '

' . lang('E-mail') . "