浏览代码

Don't auto-focus on compose form when user has already focused somewhere manually (very annoying over slow connections)

pdontthink 20 年之前
父节点
当前提交
ce270298f9
共有 3 个文件被更改,包括 23 次插入9 次删除
  1. 3 2
      functions/forms.php
  2. 16 7
      src/compose.php
  3. 4 0
      templates/default/js/default.js

+ 3 - 2
functions/forms.php

@@ -130,7 +130,8 @@ function addHidden($sName, $sValue, $aAttribs=array()) {
  * @param string $sValue initial field value
  * @param string $sValue initial field value
  * @param integer $iSize field size (number of characters)
  * @param integer $iSize field size (number of characters)
  * @param integer $iMaxlength maximum number of characters the user may enter
  * @param integer $iMaxlength maximum number of characters the user may enter
- * @param array $aAttribs (since 1.5.1) extra attributes
+ * @param array $aAttribs (since 1.5.1) extra attributes - should be given
+ *                        in the form array('attribute_name' => 'attribute_value', ...)
  * @return string html formated text input field
  * @return string html formated text input field
  */
  */
 function addInput($sName, $sValue = '', $iSize = 0, $iMaxlength = 0, $aAttribs=array()) {
 function addInput($sName, $sValue = '', $iSize = 0, $iMaxlength = 0, $aAttribs=array()) {
@@ -291,4 +292,4 @@ function addForm($sAction, $sMethod = 'post', $sName = '', $sEnctype = '', $sCha
         $sEnctype . $sName . $sCharset . $sAttribs . ">\n";
         $sEnctype . $sName . $sCharset . $sAttribs . ">\n";
 }
 }
 
 
-?>
+?>

+ 16 - 7
src/compose.php

@@ -1020,6 +1020,15 @@ function showInputForm ($session, $values=false) {
         $mailprio, $compose_new_win, $saved_draft, $mail_sent, $sig_first,
         $mailprio, $compose_new_win, $saved_draft, $mail_sent, $sig_first,
         $username, $compose_messages, $composesession, $default_charset;
         $username, $compose_messages, $composesession, $default_charset;
 
 
+    if (checkForJavascript()) {
+        $onfocus = ' onfocus="alreadyFocused=true;"';
+        $onfocus_array = array('onfocus' => 'alreadyFocused=true;');
+    }
+    else {
+        $onfocus = '';
+        $onfocus_array = array();
+    }
+
     $composeMessage = $compose_messages[$session];
     $composeMessage = $compose_messages[$session];
     if ($values) {
     if ($values) {
         $send_to = $values['send_to'];
         $send_to = $values['send_to'];
@@ -1108,28 +1117,28 @@ function showInputForm ($session, $values=false) {
         html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
         html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
         _("To") . ':</td>' . "\n" .
         _("To") . ':</td>' . "\n" .
         html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
         html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
-        addInput('send_to', $send_to, 60). '<br />' . "\n" .
+        addInput('send_to', $send_to, 60, 0, $onfocus_array). '<br />' . "\n" .
         '      </td>' . "\n" .
         '      </td>' . "\n" .
         '   </tr>' . "\n" .
         '   </tr>' . "\n" .
         '   <tr>' . "\n" .
         '   <tr>' . "\n" .
         html_tag( 'td', '', 'right', $color[4] ) .
         html_tag( 'td', '', 'right', $color[4] ) .
         _("Cc") . ':</td>' . "\n" .
         _("Cc") . ':</td>' . "\n" .
         html_tag( 'td', '', 'left', $color[4] ) .
         html_tag( 'td', '', 'left', $color[4] ) .
-        addInput('send_to_cc', $send_to_cc, 60). '<br />' . "\n" .
+        addInput('send_to_cc', $send_to_cc, 60, 0, $onfocus_array). '<br />' . "\n" .
         '      </td>' . "\n" .
         '      </td>' . "\n" .
         '   </tr>' . "\n" .
         '   </tr>' . "\n" .
         '   <tr>' . "\n" .
         '   <tr>' . "\n" .
         html_tag( 'td', '', 'right', $color[4] ) .
         html_tag( 'td', '', 'right', $color[4] ) .
         _("Bcc") . ':</td>' . "\n" .
         _("Bcc") . ':</td>' . "\n" .
         html_tag( 'td', '', 'left', $color[4] ) .
         html_tag( 'td', '', 'left', $color[4] ) .
-        addInput('send_to_bcc', $send_to_bcc, 60).'<br />' . "\n" .
+        addInput('send_to_bcc', $send_to_bcc, 60, 0, $onfocus_array).'<br />' . "\n" .
         '      </td>' . "\n" .
         '      </td>' . "\n" .
         '   </tr>' . "\n" .
         '   </tr>' . "\n" .
         '   <tr>' . "\n" .
         '   <tr>' . "\n" .
         html_tag( 'td', '', 'right', $color[4] ) .
         html_tag( 'td', '', 'right', $color[4] ) .
         _("Subject") . ':</td>' . "\n" .
         _("Subject") . ':</td>' . "\n" .
         html_tag( 'td', '', 'left', $color[4] ) . "\n";
         html_tag( 'td', '', 'left', $color[4] ) . "\n";
-    echo '         '.addInput('subject', $subject, 60).
+    echo '         '.addInput('subject', $subject, 60, 0, $onfocus_array).
         '      </td>' . "\n" .
         '      </td>' . "\n" .
         '   </tr>' . "\n\n";
         '   </tr>' . "\n\n";
 
 
@@ -1142,13 +1151,13 @@ function showInputForm ($session, $values=false) {
         echo '   <tr>' . "\n" .
         echo '   <tr>' . "\n" .
             '      <td bgcolor="' . $color[0] . '" colspan="2" align="center">' . "\n" .
             '      <td bgcolor="' . $color[0] . '" colspan="2" align="center">' . "\n" .
             '         <textarea name="body" id="body" rows="' . (int)$editor_height .
             '         <textarea name="body" id="body" rows="' . (int)$editor_height .
-            '" cols="' . (int)$editor_size . '" wrap="virtual">';
+            '" cols="' . (int)$editor_size . '" wrap="virtual"' . $onfocus . '>';
     }
     }
     else {
     else {
         echo '   <tr>' . "\n" .
         echo '   <tr>' . "\n" .
             '      <td bgcolor="' . $color[4] . '" colspan="2">' . "\n" .
             '      <td bgcolor="' . $color[4] . '" colspan="2">' . "\n" .
             '         &nbsp;&nbsp;<textarea name="body" id="body" rows="' . (int)$editor_height .
             '         &nbsp;&nbsp;<textarea name="body" id="body" rows="' . (int)$editor_height .
-            '" cols="' . (int)$editor_size . '" wrap="virtual">';
+            '" cols="' . (int)$editor_size . '" wrap="virtual"' . $onfocus . '>';
     }
     }
 
 
     if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
     if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
@@ -1660,4 +1669,4 @@ function deliverMessage($composeMessage, $draft=false) {
     return $succes;
     return $succes;
 }
 }
 
 
-?>
+?>

+ 4 - 0
templates/default/js/default.js

@@ -226,7 +226,11 @@ function sendMDN() {
     var newwin = window.open(mdnuri,'right');
     var newwin = window.open(mdnuri,'right');
 }
 }
 
 
+var alreadyFocused = false;
 function checkForm(smaction) {
 function checkForm(smaction) {
+
+    if (alreadyFocused) return;
+
     /*
     /*
      * this part is used for setting the focus in the compose screen
      * this part is used for setting the focus in the compose screen
      */
      */