Permalink
Browse files

Send the form by Ctrl+Enter in all textareas

  • Loading branch information...
1 parent 420faa3 commit 644c355d947b559fdbd31dd6be5589cecf13f0c6 @vrana committed Oct 17, 2010
View
@@ -57,7 +57,7 @@
<p>
<?php
echo ($_POST["add_x"] || strpos($name, "\n")
- ? '<textarea name="name" rows="10" cols="40">' . h($name) . '</textarea><br>'
+ ? '<textarea name="name" rows="10" cols="40" onkeydown="return textareaKeydown(this, event);">' . h($name) . '</textarea><br>'
: '<input name="name" value="' . h($name) . '" maxlength="64">'
) . "\n" . ($collations ? html_select("collation", array("" => "(" . lang('collation') . ")") + $collations, $collate) : "");
?>
View
@@ -214,7 +214,7 @@
}
}
} else {
- echo "<tr><td><textarea name='databases' rows='10' cols='20'></textarea>";
+ echo "<tr><td><textarea name='databases' rows='10' cols='20' onkeydown='return textareaKeydown(this, event);'></textarea>";
}
}
?>
@@ -104,7 +104,7 @@ function referencable_primary($self) {
* @return null
*/
function textarea($name, $value, $rows = 10, $cols = 80) {
- echo "<textarea name='$name' rows='$rows' cols='$cols' style='width: 98%;' spellcheck='false' onkeydown='return textareaKeydown(this, event);'>" . h($value) . "</textarea>"; // spellcheck - not valid before HTML5
+ echo "<textarea name='$name' rows='$rows' cols='$cols' style='width: 98%;' spellcheck='false' onkeydown='return textareaKeydown(this, event, true);'>" . h($value) . "</textarea>"; // spellcheck - not valid before HTML5
}
/** Print table columns for type edit
@@ -599,7 +599,7 @@ function input($field, $value, $function) {
} elseif (ereg('blob|bytea|raw|file', $field["type"]) && ini_bool("file_uploads")) {
echo "<input type='file' name='fields-$name'$onchange>";
} elseif (ereg('text|lob', $field["type"])) {
- echo "<textarea " . ($jush != "sqlite" || ereg("\n", $value) ? "cols='50' rows='12'" : "cols='30' rows='1' style='height: 1.2em;'") . "$attrs>" . h($value) . '</textarea>'; // 1.2em - line-height
+ echo "<textarea " . ($jush != "sqlite" || ereg("\n", $value) ? "cols='50' rows='12'" : "cols='30' rows='1' style='height: 1.2em;'") . "$attrs onkeydown='return textareaKeydown(this, event);'>" . h($value) . '</textarea>'; // 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));
View
@@ -339,7 +339,7 @@
$editable = is_utf8($val) && !$long && $rows[$n][$key] == $row[$key] && !$functions[$key];
$text = ereg('text|lob', $field["type"]);
echo (($_GET["modify"] && $editable) || isset($value)
- ? "<td>" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>")
+ ? "<td>" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "' onkeydown='return textareaKeydown(this, event);'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>")
: "<td id='$id' ondblclick=\"" . ($editable ? "selectDblClick(this, event" . ($text ? ", 1" : "") . ")" : "alert('" . h($long ? lang('Increase text length to modify this value.') : lang('Use edit link to modify this value.')) . "')") . ";\">" . $adminer->selectVal($val, $link, $field)
);
}
View
@@ -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;
-}
@@ -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();
View
@@ -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):
@@ -265,7 +265,7 @@ function selectEmailPrint($emailFields, $columns) {
echo '<fieldset><legend><a href="#fieldset-email" onclick="return !toggle(\'fieldset-email\');">' . lang('E-mail') . "</a></legend><div id='fieldset-email'" . ($_POST["email_append"] ? "" : " class='hidden'") . ">\n";
echo "<p>" . lang('From') . ": <input name='email_from' value='" . h($_POST ? $_POST["email_from"] : $_COOKIE["adminer_email"]) . "'>\n";
echo lang('Subject') . ": <input name='email_subject' value='" . h($_POST["email_subject"]) . "'>\n";
- echo "<p><textarea name='email_message' rows='15' cols='75'>" . h($_POST["email_message"] . ($_POST["email_append"] ? '{$' . "$_POST[email_addition]}" : "")) . "</textarea><br>\n";
+ echo "<p><textarea name='email_message' rows='15' cols='75' onkeydown='return textareaKeydown(this, event, false, this.form.email);'>" . h($_POST["email_message"] . ($_POST["email_append"] ? '{$' . "$_POST[email_addition]}" : "")) . "</textarea><br>\n";
echo html_select("email_addition", $columns, $_POST["email_addition"]) . "<input type='submit' name='email_append' value='" . lang('Insert') . "'>\n"; //! JavaScript
echo "<p>" . lang('Attachments') . ": <input type='file' name='email_files[]' onchange=\"var el = this.cloneNode(true); el.value = ''; this.parentNode.appendChild(el); this.onchange = function () { };\">";
echo "<p>" . (count($emailFields) == 1 ? '<input type="hidden" name="email_field" value="' . h(key($emailFields)) . '">' : html_select("email_field", $emailFields));

0 comments on commit 644c355

Please sign in to comment.