Browse files

Send e-mail by Ctrl+Enter (Editor)

  • Loading branch information...
1 parent b6be64e commit daf85306a53c0088ed77d17260ca31aac4249179 @vrana committed May 4, 2011
Showing with 16 additions and 9 deletions.
  1. +10 −5 adminer/static/functions.js
  2. +4 −2 editor/include/adminer.inc.php
  3. +2 −2 editor/include/editing.inc.php
View
15 adminer/static/functions.js
@@ -190,16 +190,21 @@ function textareaKeydown(target, event) {
return true;
}
-/** Send form by Enter on <select>
+/** Send form by Ctrl+Enter on <select> and <textarea>
* @param KeyboardEvent
+* @param [string]
* @return boolean
*/
-function bodyKeydown(event) {
+function bodyKeydown(event, button) {
var target = event.target || event.srcElement;
- if (event.ctrlKey && (event.keyCode == 13 || event.keyCode == 10) && !event.altKey && !event.metaKey && /select|textarea/i.test(target.tagName)) { // 13|10 - Enter, shiftKey allowed
+ if (event.ctrlKey && (event.keyCode == 13 || event.keyCode == 10) && !event.altKey && !event.metaKey && /select|textarea|input/i.test(target.tagName)) { // 13|10 - Enter, shiftKey allowed
target.blur();
- if ((!target.form.onsubmit || target.form.onsubmit() !== false) && !ajaxForm(target.form)) {
- target.form.submit();
+ if ((!target.form.onsubmit || target.form.onsubmit() !== false) && !ajaxForm(target.form, (button ? button + '=1' : ''))) {
+ if (button) {
+ target.form[button].click();
+ } else {
+ target.form.submit();
+ }
}
return false;
}
View
6 editor/include/adminer.inc.php
@@ -278,13 +278,15 @@ function selectActionPrint() {
function selectEmailPrint($emailFields, $columns) {
if ($emailFields) {
print_fieldset("email", lang('E-mail'), $_POST["email_append"]);
+ echo "<div onkeydown=\"eventStop(event); return bodyKeydown(event, 'email');\">\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"; //! Ctrl+Enter for this.form.email
- echo html_select("email_addition", $columns, $_POST["email_addition"]) . "<input type='submit' name='email_append' value='" . lang('Insert') . "'>\n"; //! JavaScript
+ echo "<p><textarea name='email_message' rows='15' cols='75'>" . h($_POST["email_message"] . ($_POST["email_append"] ? '{$' . "$_POST[email_addition]}" : "")) . "</textarea>\n"; //! Ctrl+Enter for this.form.email
+ echo "<p onkeydown=\"eventStop(event); return bodyKeydown(event, 'email_append');\">" . 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=\"this.onchange = function () { }; var el = this.cloneNode(true); el.value = ''; this.parentNode.appendChild(el);\">";
echo "<p>" . (count($emailFields) == 1 ? '<input type="hidden" name="email_field" value="' . h(key($emailFields)) . '">' : html_select("email_field", $emailFields));
echo "<input type='submit' name='email' value='" . lang('Send') . "' onclick=\"return this.form['delete'].onclick();\">\n";
+ echo "</div>\n";
echo "</div></fieldset>\n";
}
}
View
4 editor/include/editing.inc.php
@@ -16,12 +16,12 @@ function email_header($header) {
* @param array
* @return bool
*/
-function send_mail($email, $subject, $message, $from = "", $files = array("error" => array())) {
+function send_mail($email, $subject, $message, $from = "", $files = array()) {
$eol = (strncasecmp(PHP_OS, "win", 3) ? "\n" : "\r\n"); // PHP_EOL available since PHP 4.3.10 and 5.0.2
$message = str_replace("\n", $eol, wordwrap(str_replace("\r", "", "$message\n")));
$boundary = uniqid("boundary");
$attachments = "";
- foreach ($files["error"] as $key => $val) {
+ foreach ((array) $files["error"] as $key => $val) {
if (!$val) {
$attachments .= "--$boundary$eol"
. "Content-Type: " . str_replace("\n", "", $files["type"][$key]) . $eol

0 comments on commit daf8530

Please sign in to comment.