Allow more advanced element focusing
[squirrelmail.git] / templates / default / js / default.js
index 4c7b9e890a18d56524f1529c575d6796f1341c6a..f55517262958133507495129c55269f1dac338ec 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * This array is used to remember mark status of rows in browse mode
  *
- * @copyright © 2005-2006 The SquirrelMail Project Team
+ * @copyright 2005-2018 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  */
@@ -266,13 +266,20 @@ function checkForm(smaction) {
      */
         var f = document.forms.length;
         var i = 0;
+        var remembered_form = -1;
         var pos = -1;
+        var remembered_pos = -1;
         while( pos == -1 && i < f ) {
             var e = document.forms[i].elements.length;
             var j = 0;
             while( pos == -1 && j < e ) {
-                if ( document.forms[i].elements[j].type == 'text' || document.forms[i].elements[j].type == 'password' ) {
-                    pos = j;
+                if ( document.forms[i].elements[j].type == 'text' || document.forms[i].elements[j].type == 'password' || document.forms[i].elements[j].type == 'textarea' ) {
+                    if ( document.forms[i].elements[j].id.substring(0, 13) == '__lastfocus__' ) {
+                        remembered_pos = j;
+                        remembered_form = i;
+                    } else if ( document.forms[i].elements[j].id.substring(0, 11) != '__nofocus__' ) {
+                        pos = j;
+                    }
                 }
                 j++;
             }
@@ -280,6 +287,8 @@ function checkForm(smaction) {
         }
         if( pos >= 0 ) {
             document.forms[i-1].elements[pos].focus();
+        } else if ( remembered_pos >= 0 ) {
+            document.forms[remembered_form].elements[remembered_pos].focus();
         }
     }
 }
@@ -289,3 +298,17 @@ function printThis()
     parent.frames['right'].focus();
     parent.frames['right'].print();
 }
+
+/* JS implementation of more/less links in To/CC. Could later be extended
+ * show/hide other interface items */
+function showhide (item, txtmore, txtless) {
+    var oTemp=document.getElementById("recpt_tail_" + item);
+    var oClick=document.getElementById("toggle_" + item);
+    if (oTemp.style.display=="inline") {
+        oTemp.style.display="none";
+        oClick.innerHTML=txtmore;
+    } else {
+        oTemp.style.display="inline";
+        oClick.innerHTML=txtless;
+    }
+}